Advertisement
peter9477

Pull out useful MANIFEST.MF stuff for BBTart app on BB10

Jan 14th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1.  
  2. import os
  3. import re
  4. import datetime as dt
  5. import time
  6.  
  7.  
  8. MANIFEST_PATH = 'app/META-INF/MANIFEST.MF'
  9. DEVICEINFO_PATH = '/pps/services/deviceproperties'
  10. BUILDINFO_PATH = 'app/native/build.info'
  11.  
  12. class AppUtil:
  13.     # default values
  14.     date = '2012-01-01'
  15.     title = 'ThisApp'
  16.     author = 'Author'
  17.     app_version = '0.0'
  18.     os_version = '10.0'
  19.  
  20.     def __init__(self):
  21.         try:
  22.             with open(MANIFEST_PATH) as manifest:
  23.                 text = manifest.read(2000)
  24.                 for pat, name in [
  25.                     (r'Application-Version: (.+)', 'app_version'),
  26.                     (r'Application-Name: (.+)', 'title'),
  27.                     (r'Package-Author: (.+)', 'author'),
  28.                     ]:
  29.                     match = re.search(pat, text)
  30.                     if match:
  31.                         setattr(self, name, match.group(1))
  32.  
  33.                     # print(name, getattr(self, name))
  34.         except IOError:
  35.             pass
  36.  
  37.         try:
  38.             with open(DEVICEINFO_PATH) as devinfo:
  39.                 text = devinfo.read()
  40.  
  41.                 for pat, name in [
  42.                     (r'scmbundle::(.+)', 'os_version'),
  43.                     ]:
  44.                     match = re.search(pat, text)
  45.                     if match:
  46.                         setattr(self, name, match.group(1))
  47.  
  48.                     # print(name, getattr(self, name))
  49.         except IOError:
  50.             pass
  51.  
  52.         try:
  53.             with open(BUILDINFO_PATH) as buildinfo:
  54.                 text = buildinfo.read().strip()
  55.                 build_time = dt.datetime.strptime(text, '%Y-%m-%d %H:%M:%S.%f')
  56.                 self.date = str(build_time.date())
  57.                 self.build_time = str(build_time)
  58.         except IOError:
  59.             pass
  60.  
  61.  
  62. metadata = AppUtil()
  63.  
  64.  
  65. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement