示例#1
0
def main():
    root_dir = Path(__file__).resolve().parents[1]
    cfg = config()
    log = Logger(root_dir)
    info = AppInfo(cfg['api_url'])
    level = 'info'
    log.logging(level, '=== {} Started ==='.format(root_dir.name))

    # APIからアプリ情報取得
    log.logging(level, 'Start to fetch AppInfo from [{}]'.format(cfg['api_url']))
    app_info = info.fetch_app_info()
    if isinstance(app_info, dict):
        # アプリ情報取得できたら現在のバージョン取得
        ver_current = app_info['current_version']
        log.logging(level, 'Result to fetch current version: {}'.format(ver_current))

        # サイトからバージョン取得
        log.logging(level, 'Start to fetch latest version from [{}]'.format(app_info['url']))
        latest = info.fetch_latest_version(app_info)
        ver_latest = latest['version']
        level = 'info' if latest['download_link'] is not None else 'error'
        log.logging(level, 'Result to fetch latest version: {}'.format(ver_latest))

        is_updated = False
        try:
            is_updated = StrictVersion(ver_current) < StrictVersion(ver_latest)
        except ValueError:
            pass

        # メール送信
        level = 'info'
        log.logging(level, 'Start to send mail')
        mail_parts = {
            'app_name': app_info['name'],
            'ver_current': ver_current,
            'ver_latest': ver_latest,
            'download_link': latest['download_link'],
            'is_updated': is_updated
        }
        mail_content = create_mail_content(**mail_parts)
        mailer = Mail(cfg['mail_info'])
        msg = mailer.create_message(mail_content)
        mail_result = mailer.send_mail(msg)
        level = 'info' if mail_result['result'] else 'error'
        log.logging(level, 'Result to send mail: {}'.format(mail_result['msg']))
    else:
        level = 'error'
        log.logging(level, 'FAILED to fetch AppInfo from [{}]'.format(cfg['api_url']))
        log.logging(level, 'Error: {}'.format(app_info))

    level = 'info'
    log.logging(level, '=== {} Stop ==='.format(root_dir.name))
示例#2
0
    def copyRow(self, row):
        rowId = row['id']
        blob = row['lppa']

        appList = []
        try:
            lppa = msgpack.unpackb(blob)
            appList = [AppInfo.from_v1(k, v) for k, v in lppa.items()]
        except msgpack.exceptions.UnpackException:
            pass

        return

        if len(appList) <= 0:
            try:
                b = lzma.decompress(blob)
                lppa = simplejson.loads(b)
                appList = [AppInfo(**item) for item in lppa]
            except lzma.LZMAError:
                pass

        if len(appList) <= 0:
            logger.warning('not a valid lppa row {}'.format(rowId))
            return

        lppas = [x.value_v2() for x in appList]
        # pprint.pprint(lppas)

        logger.debug('copying {}'.format(rowId))
        blob = row['lppa']
        o = {
            'v': 3,
            'data': lppas,
        }
        s = simplejson.dumps(o, separators=[':', ','], ensure_ascii=True)
        b = s.encode('ascii')
        blob = zlib.compress(b, 1)
        sql = """INSERT INTO did_lppa_v3 (id, did, lppa)
        VALUES (:rowId, :did, :blob) ON DUPLICATE KEY UPDATE id = id"""
        p = {
            'blob': blob,
            'rowId': row['id'],
            'did': row['did'],
        }
        db.session.execute(sql, p)
        logger.debug('copied {}'.format(rowId))
示例#3
0
    def copyRow(self, row):
        rowId = row['id']
        blob = row['lppa']

        appList = []
        try:
            lppa = msgpack.unpackb(blob)
            appList = [AppInfo.from_v1(k, v) for k, v in lppa.items()]
        except msgpack.exceptions.UnpackException:
            pass

        if len(appList) <= 0:
            try:
                b = lzma.decompress(blob)
                lppa = simplejson.loads(b)
                appList = [AppInfo(**item) for item in lppa]
            except lzma.LZMAError:
                pass

        if len(appList) <= 0:
            logger.warning('not a valid lppa row {}'.format(rowId))
            return

        logger.debug(rowId)

        lppas = [x.value_v2() for x in appList]
        # pprint.pprint(lppas)

        logger.debug('copying {}'.format(rowId))
        blob = row['lppa']
        o = {
            'v': 3,
            'data': lppas,
        }
        s = simplejson.dumps(o, separators=[':', ','], ensure_ascii=True)
        b = s.encode('ascii')
        blob = zlib.compress(b, 1)
示例#4
0
def main():
  parser = optparse.OptionParser()
  info = ('The package name. Such as: '
          '--package=com.example.YourPackage')
  parser.add_option('--package', help=info)
  info = ('The apk name. Such as: --name="Your Application Name"')
  parser.add_option('--name', help=info)
  info = ('The version of the app. Such as: --app-version=TheVersionNumber')
  parser.add_option('--app-version', help=info)
  info = ('The versionCode of the app. Such as: --app-versionCode=24')
  parser.add_option('--app-versionCode', type='int', help=info)
  info = ('The application description. Such as:'
          '--description=YourApplicationdDescription')
  parser.add_option('--description', help=info)
  info = ('The permission list. Such as: --permissions="geolocation"'
          'For more permissions, such as:'
          '--permissions="geolocation:permission2"')
  parser.add_option('--permissions', help=info)
  info = ('The url of application. '
          'This flag allows to package website as apk. Such as: '
          '--app-url=http://www.intel.com')
  parser.add_option('--app-url', help=info)
  info = ('The root path of the web app. '
          'This flag allows to package local web app as apk. Such as: '
          '--app-root=/root/path/of/the/web/app')
  parser.add_option('--app-root', help=info)
  info = ('The reletive path of entry file based on |app_root|. '
          'This flag should work with "--app-root" together. '
          'Such as: --app-local-path=/reletive/path/of/entry/file')
  parser.add_option('--app-local-path', help=info)
  parser.add_option('--enable-remote-debugging', action='store_true',
                    dest='enable_remote_debugging', default=False,
                    help='Enable remote debugging.')
  parser.add_option('--use-animatable-view', action='store_true',
                    dest='use_animatable_view', default=False,
                    help='Enable using animatable view (TextureView).')
  parser.add_option('-f', '--fullscreen', action='store_true',
                    dest='fullscreen', default=False,
                    help='Make application fullscreen.')
  parser.add_option('--keep-screen-on', action='store_true', default=False,
                    help='Support keeping screen on')
  info = ('The path list for external extensions separated by os separator.'
          'On Linux and Mac, the separator is ":". On Windows, it is ";".'
          'Such as: --extensions="/path/to/extension1:/path/to/extension2"')
  parser.add_option('--extensions', help=info)
  info = ('The orientation of the web app\'s display on the device. '
          'Such as: --orientation=landscape. The default value is "unspecified"'
          'The value options are the same as those on the Android: '
          'http://developer.android.com/guide/topics/manifest/'
          'activity-element.html#screen')
  parser.add_option('--orientation', help=info)
  parser.add_option('--manifest', help='The manifest path')
  info = ('Use command lines.'
          'Crosswalk is powered by Chromium and supports Chromium command line.'
          'For example, '
          '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'')
  info = ('Create an Android project directory at this location. ')
  parser.add_option('--project-dir', help=info)
  parser.add_option('--xwalk-command-line', default='', help=info)
  info = ('Minify and obfuscate javascript and css.'
          '--compressor: compress javascript and css.'
          '--compressor=js: compress javascript.'
          '--compressor=css: compress css.')
  parser.add_option('--compressor', dest='compressor', action='callback',
                    callback=ParseParameterForCompressor,
                    type='string', nargs=0, help=info)
  options, _ = parser.parse_args()
  try:
    icon_dict = {144: 'icons/icon_144.png',
                 72: 'icons/icon_72.png',
                 96: 'icons/icon_96.png',
                 48: 'icons/icon_48.png'}
    app_info = AppInfo()
    if options.name is not None:
      app_info.android_name = options.name
    if options.app_root is None:
      app_info.app_root = os.path.join(xwalk_dir, 'test_data', 'manifest')
    else:
      app_info.app_root = options.app_root
    if options.package is not None:
      app_info.package = options.package
    if options.orientation is not None:
      app_info.orientation = options.orientation
    if options.app_version is not None:
      app_info.app_version = options.app_version
    if options.enable_remote_debugging is not None:
      app_info.remote_debugging = options.enable_remote_debugging
    if options.fullscreen is not None:
      app_info.fullscreen_flag = options.fullscreen
    app_info.icon = os.path.join('test_data', 'manifest', 'icons',
                                 'icon_96.png')
    CustomizeAll(app_info, options.description, icon_dict,
                 options.permissions, options.app_url, options.app_local_path,
                 options.keep_screen_on, options.extensions, None,
                 options.xwalk_command_line, options.compressor)

    # build project is now in /tmp/<name>. Copy to project_dir
    if options.project_dir:
      src_dir = GetBuildDir(app_info.android_name)
      dest_dir = os.path.join(options.project_dir, app_info.android_name)
      CreateAndCopyDir(src_dir, dest_dir, True)

  except SystemExit as ec:
    print('Exiting with error code: %d' % ec.code)
    return ec.code
  finally:
    CleanDir(GetBuildDir(app_info.android_name))
  return 0
示例#5
0
def main(argv):
  parser = optparse.OptionParser()
  parser.add_option('-v', '--version', action='store_true',
                    dest='version', default=False,
                    help='The version of this python tool.')
  parser.add_option('--verbose', action="store_true",
                    dest='verbose', default=False,
                    help='Print debug messages.')
  info = ('The packaging mode of the web application. The value \'shared\' '
          'means that the runtime is shared across multiple application '
          'instances and that the runtime needs to be distributed separately. '
          'The value \'embedded\' means that the runtime is embedded into the '
          'application itself and distributed along with it.'
          'Set the default mode as \'embedded\'. For example: --mode=embedded')
  parser.add_option('--mode', default='embedded', help=info)
  info = ('The target architecture of the embedded runtime. Supported values '
          'are \'x86\' and \'arm\'. Note, if undefined, APKs for all possible '
          'architestures will be generated.')
  parser.add_option('--arch', choices=AllArchitectures(), help=info)
  group = optparse.OptionGroup(parser, 'Application Source Options',
      'This packaging tool supports 3 kinds of web application source: '
      '1) XPK package; 2) manifest.json; 3) various command line options, '
      'for example, \'--app-url\' for website, \'--app-root\' and '
      '\'--app-local-path\' for local web application.')
  info = ('The path of the XPK package. For example, --xpk=/path/to/xpk/file')
  group.add_option('--xpk', help=info)
  info = ('The manifest file with the detail description of the application. '
          'For example, --manifest=/path/to/your/manifest/file')
  group.add_option('--manifest', help=info)
  info = ('The url of application. '
          'This flag allows to package website as apk. For example, '
          '--app-url=http://www.intel.com')
  group.add_option('--app-url', help=info)
  info = ('The root path of the web app. '
          'This flag allows to package local web app as apk. For example, '
          '--app-root=/root/path/of/the/web/app')
  group.add_option('--app-root', help=info)
  info = ('The relative path of entry file based on the value from '
          '\'app_root\'. This flag should work with \'--app-root\' together. '
          'For example, --app-local-path=/relative/path/of/entry/file')
  group.add_option('--app-local-path', help=info)
  parser.add_option_group(group)
  group = optparse.OptionGroup(parser, 'Mandatory arguments',
      'They are used for describing the APK information through '
      'command line options.')
  info = ('The apk name. For example, --name="Your Application Name"')
  group.add_option('--name', help=info)
  info = ('The package name. For example, '
          '--package=com.example.YourPackage')
  group.add_option('--package', help=info)
  parser.add_option_group(group)
  group = optparse.OptionGroup(parser, 'Optional arguments',
      'They are used for various settings for applications through '
      'command line options.')
  info = ('The version name of the application. '
          'For example, --app-version=1.0.0')
  group.add_option('--app-version', help=info)
  info = ('The version code of the application. '
          'For example, --app-versionCode=24')
  group.add_option('--app-versionCode', type='int', help=info)
  info = ('The version code base of the application. Version code will '
          'be made by adding a prefix based on architecture to the version '
          'code base. For example, --app-versionCodeBase=24')
  group.add_option('--app-versionCodeBase', type='int', help=info)
  info = ('Use command lines.'
          'Crosswalk is powered by Chromium and supports Chromium command line.'
          'For example, '
          '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'')
  group.add_option('--xwalk-command-line', default='', help=info)
  info = ('The description of the application. For example, '
          '--description=YourApplicationDescription')
  group.add_option('--description', help=info)
  group.add_option('--enable-remote-debugging', action='store_true',
                   dest='enable_remote_debugging', default=False,
                   help='Enable remote debugging.')
  info = ('The list of external extension paths splitted by OS separators. '
          'The separators are \':\' , \';\' and \':\' on Linux, Windows and '
          'Mac OS respectively. For example, '
          '--extensions=/path/to/extension1:/path/to/extension2.')
  group.add_option('--extensions', help=info)
  group.add_option('-f', '--fullscreen', action='store_true',
                   dest='fullscreen', default=False,
                   help='Make application fullscreen.')
  group.add_option('--keep-screen-on', action='store_true', default=False,
                   help='Support keeping screen on')
  info = ('The path of application icon. '
          'Such as: --icon=/path/to/your/customized/icon')
  group.add_option('--icon', help=info)
  info = ('The orientation of the web app\'s display on the device. '
          'For example, --orientation=landscape. The default value is '
          '\'unspecified\'. The permitted values are from Android: '
          'http://developer.android.com/guide/topics/manifest/'
          'activity-element.html#screen')
  group.add_option('--orientation', help=info)
  info = ('The list of permissions to be used by web application. For example, '
          '--permissions=geolocation:webgl')
  group.add_option('--permissions', help=info)
  info = ('Packaging tool will move the output APKS to the target directory')
  group.add_option('--target-dir', default=os.getcwd(), help=info)
  parser.add_option_group(group)
  group = optparse.OptionGroup(parser, 'Keystore Options',
      'The keystore is a signature from web developer, it\'s used when '
      'developer wants to distribute the applications.')
  info = ('The path to the developer keystore. For example, '
          '--keystore-path=/path/to/your/developer/keystore')
  group.add_option('--keystore-path', help=info)
  info = ('The alias name of keystore. For example, --keystore-alias=name')
  group.add_option('--keystore-alias', help=info)
  info = ('The passcode of keystore. For example, --keystore-passcode=code')
  group.add_option('--keystore-passcode', help=info)
  info = ('Minify and obfuscate javascript and css.'
          '--compressor: compress javascript and css.'
          '--compressor=js: compress javascript.'
          '--compressor=css: compress css.')
  group.add_option('--compressor', dest='compressor', action='callback',
                   callback=ParseParameterForCompressor, type='string',
                   nargs=0, help=info)
  parser.add_option_group(group)
  options, _ = parser.parse_args()
  if len(argv) == 1:
    parser.print_help()
    return 0

  if options.version:
    if os.path.isfile('VERSION'):
      print(GetVersion('VERSION'))
      return 0
    else:
      parser.error('Can\'t get version due to the VERSION file missing!')

  xpk_temp_dir = ''
  if options.xpk:
    xpk_name = os.path.splitext(os.path.basename(options.xpk))[0]
    xpk_temp_dir = xpk_name + '_xpk'
    ParseXPK(options, xpk_temp_dir)

  if options.app_root and not options.manifest:
    manifest_path = os.path.join(options.app_root, 'manifest.json')
    if os.path.exists(manifest_path):
      print('Using manifest.json distributed with the application.')
      options.manifest = manifest_path

  app_info = AppInfo()
  if not options.manifest:
    if options.package:
      VerifyAppName(options.package, 'packagename')
    else:
      parser.error('The package name is required! '
                   'Please use "--package" option.')
    if options.name:
      VerifyAppName(options.name)
      app_info.original_name = options.name
      options.name = ReplaceSpaceWithUnderscore(options.name)
    else:
      parser.error('The APK name is required! Please use "--name" option.')
    if not ((options.app_url and
             not options.app_root and
             not options.app_local_path) or
            (not options.app_url and
             options.app_root and
             options.app_local_path)):
      parser.error('The entry is required. If the entry is a remote url, '
                   'please use "--app-url" option; If the entry is local, '
                   'please use "--app-root" and '
                   '"--app-local-path" options together!')
    if options.permissions:
      permission_list = options.permissions.split(':')
    else:
      print('Warning: all supported permissions on Android port are added. '
            'Refer to https://github.com/crosswalk-project/'
            'crosswalk-website/wiki/Crosswalk-manifest')
      permission_list = permission_mapping_table.keys()
    options.permissions = HandlePermissionList(permission_list)
    options.icon_dict = {}
  else:
    try:
      ParseManifest(options, app_info)
    except SystemExit as ec:
      return ec.code

  if (options.app_root and options.app_local_path and
      not os.path.isfile(os.path.join(options.app_root,
                                      options.app_local_path))):
    print('Please make sure that the local path file of launching app '
          'does exist.')
    sys.exit(7)

  if options.target_dir:
    target_dir = os.path.abspath(os.path.expanduser(options.target_dir))
    options.target_dir = target_dir
    if not os.path.isdir(target_dir):
      os.makedirs(target_dir)

  try:
    MakeApk(options, app_info)
  except SystemExit as ec:
    CleanDir(options.name)
    CleanDir('out')
    CleanDir(xpk_temp_dir)
    return ec.code
  return 0
示例#6
0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option('-v',
                      '--version',
                      action='store_true',
                      dest='version',
                      default=False,
                      help='The version of this python tool.')
    parser.add_option('--verbose',
                      action="store_true",
                      dest='verbose',
                      default=False,
                      help='Print debug messages.')
    info = (
        'The packaging mode of the web application. The value \'shared\' '
        'means that the runtime is shared across multiple application '
        'instances and that the runtime needs to be distributed separately. '
        'The value \'embedded\' means that the runtime is embedded into the '
        'application itself and distributed along with it.'
        'Set the default mode as \'embedded\'. For example: --mode=embedded')
    parser.add_option('--mode',
                      choices=('embedded', 'shared'),
                      default='embedded',
                      help=info)
    info = (
        'The target architecture of the embedded runtime. Supported values: '
        '%s. If not specified, APKs for all available architectures will be '
        'generated.' % ', '.join(AllArchitectures()))
    parser.add_option('--arch', choices=AllArchitectures(), help=info)
    group = optparse.OptionGroup(
        parser, 'Application Source Options',
        'This packaging tool supports 3 kinds of web application source: '
        '1) XPK package; 2) manifest.json; 3) various command line options, '
        'for example, \'--app-url\' for website, \'--app-root\' and '
        '\'--app-local-path\' for local web application.')
    info = (
        'The path of the XPK package. For example, --xpk=/path/to/xpk/file')
    group.add_option('--xpk', help=info)
    info = (
        'The manifest file with the detail description of the application. '
        'For example, --manifest=/path/to/your/manifest/file')
    group.add_option('--manifest', help=info)
    info = ('The url of application. '
            'This flag allows to package website as apk. For example, '
            '--app-url=http://www.intel.com')
    group.add_option('--app-url', help=info)
    info = ('The root path of the web app. '
            'This flag allows to package local web app as apk. For example, '
            '--app-root=/root/path/of/the/web/app')
    group.add_option('--app-root', help=info)
    info = (
        'The relative path of entry file based on the value from '
        '\'app_root\'. This flag should work with \'--app-root\' together. '
        'For example, --app-local-path=/relative/path/of/entry/file')
    group.add_option('--app-local-path', help=info)
    parser.add_option_group(group)
    # Mandatory options group
    group = optparse.OptionGroup(
        parser, 'Mandatory arguments',
        'They are used for describing the APK information through '
        'command line options.')
    info = ('The apk name. For example, --name="Your Application Name"')
    group.add_option('--name', help=info)
    info = ('The package name. For example, '
            '--package=com.example.YourPackage')
    group.add_option('--package', help=info)
    parser.add_option_group(group)
    # Optional options group (alphabetical)
    group = optparse.OptionGroup(
        parser, 'Optional arguments',
        'They are used for various settings for applications through '
        'command line options.')
    info = ('The version name of the application. '
            'For example, --app-version=1.0.0')
    group.add_option('--app-version', help=info)
    info = ('The version code of the application. '
            'For example, --app-versionCode=24')
    group.add_option('--app-versionCode', type='int', help=info)
    info = ('The version code base of the application. Version code will '
            'be made by adding a prefix based on architecture to the version '
            'code base. For example, --app-versionCodeBase=24')
    group.add_option('--app-versionCodeBase', type='int', help=info)
    info = ('The description of the application. For example, '
            '--description=YourApplicationDescription')
    group.add_option('--description', help=info)
    group.add_option('--enable-remote-debugging',
                     action='store_true',
                     dest='enable_remote_debugging',
                     default=False,
                     help='Enable remote debugging.')
    group.add_option('--use-animatable-view',
                     action='store_true',
                     dest='use_animatable_view',
                     default=False,
                     help='Enable using animatable view (TextureView).')
    info = ('The list of external extension paths splitted by OS separators. '
            'The separators are \':\' , \';\' and \':\' on Linux, Windows and '
            'Mac OS respectively. For example, '
            '--extensions=/path/to/extension1:/path/to/extension2.')
    group.add_option('--extensions', help=info)
    group.add_option('-f',
                     '--fullscreen',
                     action='store_true',
                     dest='fullscreen',
                     default=False,
                     help='Make application fullscreen.')
    group.add_option('--keep-screen-on',
                     action='store_true',
                     default=False,
                     help='Support keeping screen on')
    info = ('The path of application icon. '
            'Such as: --icon=/path/to/your/customized/icon')
    group.add_option('--icon', help=info)
    info = ('The orientation of the web app\'s display on the device. '
            'For example, --orientation=landscape. The default value is '
            '\'unspecified\'. The permitted values are from Android: '
            'http://developer.android.com/guide/topics/manifest/'
            'activity-element.html#screen')
    group.add_option('--orientation', help=info)
    info = (
        'The list of permissions to be used by web application. For example, '
        '--permissions=geolocation:webgl')
    group.add_option('--permissions', help=info)
    info = (
        'Create an Android project directory with Crosswalk at this location.'
        ' (See project-only option below)')
    group.add_option('--project-dir', help=info)
    info = ('Must be used with project-dir option. Create an Android project '
            'directory with Crosswalk but do not build the APK package')
    group.add_option('--project-only',
                     action='store_true',
                     default=False,
                     dest='project_only',
                     help=info)
    info = ('Packaging tool will move the output APKs to the target directory')
    group.add_option('--target-dir', default=os.getcwd(), help=info)
    info = (
        'Use command lines.'
        'Crosswalk is powered by Chromium and supports Chromium command line.'
        'For example, '
        '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'')
    group.add_option('--xwalk-command-line', default='', help=info)
    parser.add_option_group(group)
    # Keystore options group
    group = optparse.OptionGroup(
        parser, 'Keystore Options',
        'The keystore is a signature from web developer, it\'s used when '
        'developer wants to distribute the applications.')
    info = ('The path to the developer keystore. For example, '
            '--keystore-path=/path/to/your/developer/keystore')
    group.add_option('--keystore-path', help=info)
    info = ('The alias name of keystore. For example, --keystore-alias=name')
    group.add_option('--keystore-alias', help=info)
    info = ('The passcode of keystore. For example, --keystore-passcode=code')
    group.add_option('--keystore-passcode', help=info)
    info = ('Passcode for alias\'s private key in the keystore, '
            'For example, --keystore-alias-passcode=alias-code')
    group.add_option('--keystore-alias-passcode', help=info)
    info = ('Minify and obfuscate javascript and css.'
            '--compressor: compress javascript and css.'
            '--compressor=js: compress javascript.'
            '--compressor=css: compress css.')
    group.add_option('--compressor',
                     dest='compressor',
                     action='callback',
                     callback=ParseParameterForCompressor,
                     type='string',
                     nargs=0,
                     help=info)
    parser.add_option_group(group)
    options, _ = parser.parse_args()
    if len(argv) == 1:
        parser.print_help()
        return 0

    if options.version:
        if os.path.isfile('VERSION'):
            print(GetVersion('VERSION'))
            return 0
        else:
            parser.error(
                'VERSION was not found, so Crosswalk\'s version could not '
                'be determined.')

    xpk_temp_dir = ''
    if options.xpk:
        xpk_name = os.path.splitext(os.path.basename(options.xpk))[0]
        xpk_temp_dir = tempfile.mkdtemp(prefix="%s-" % xpk_name + '_xpk')
        CleanDir(xpk_temp_dir)
        ParseXPK(options, xpk_temp_dir)

    if options.manifest:
        options.manifest = os.path.abspath(options.manifest)
        if not os.path.isfile(options.manifest):
            print('Error: The manifest file does not exist.')
            sys.exit(8)

    if options.app_root and not options.manifest:
        manifest_path = os.path.join(options.app_root, 'manifest.json')
        if os.path.exists(manifest_path):
            print('Using manifest.json distributed with the application.')
            options.manifest = manifest_path

    app_info = AppInfo()
    manifest = None
    if not options.manifest:
        # The checks here are really convoluted, but at the moment make_apk
        # misbehaves any of the following conditions is true.
        if options.app_url:
            # 1) --app-url must be passed without either --app-local-path or
            #    --app-root.
            if options.app_root or options.app_local_path:
                parser.error(
                    'You must pass either "--app-url" or "--app-local-path" '
                    'with "--app-root", but not all.')
        else:
            # 2) --app-url is not passed but only one of --app-local-path and
            #    --app-root is set.
            if bool(options.app_root) != bool(options.app_local_path):
                parser.error('You must specify both "--app-local-path" and '
                             '"--app-root".')
            # 3) None of --app-url, --app-local-path and --app-root are passed.
            elif not options.app_root and not options.app_local_path:
                parser.error(
                    'You must pass either "--app-url" or "--app-local-path" '
                    'with "--app-root".')

        if options.permissions:
            permission_list = options.permissions.split(':')
        else:
            print(
                'Warning: all supported permissions on Android port are added. '
                'Refer to https://github.com/crosswalk-project/'
                'crosswalk-website/wiki/Crosswalk-manifest')
            permission_list = permission_mapping_table.keys()
        options.permissions = HandlePermissionList(permission_list)
        options.icon_dict = {}
    else:
        try:
            manifest = ParseManifest(options)
        except SystemExit as ec:
            return ec.code

    if not options.name:
        parser.error(
            'An APK name is required. Please use the "--name" option.')

    if not options.package:
        parser.error('A package name is required. Please use the "--package" '
                     'option.')
    VerifyPackageName(options.package)

    if (options.app_root and options.app_local_path and not os.path.isfile(
            os.path.join(options.app_root, options.app_local_path))):
        print('Please make sure that the local path file of launching app '
              'does exist.')
        sys.exit(7)

    if options.target_dir:
        target_dir = os.path.abspath(os.path.expanduser(options.target_dir))
        options.target_dir = target_dir
        if not os.path.isdir(target_dir):
            os.makedirs(target_dir)

    if options.project_only and not options.project_dir:
        print('\nmake_apk.py error: Option --project-only must be used '
              'with --project-dir')
        sys.exit(8)

    try:
        MakeApk(options, app_info, manifest)
    except SystemExit as ec:
        return ec.code
    finally:
        CleanDir(GetBuildDir(app_info.android_name))
        CleanDir(xpk_temp_dir)
    return 0
示例#7
0
def main():
    parser = optparse.OptionParser()
    info = ('The package name. Such as: ' '--package=com.example.YourPackage')
    parser.add_option('--package', help=info)
    info = ('The apk name. Such as: --name="Your Application Name"')
    parser.add_option('--name', help=info)
    info = ('The version of the app. Such as: --app-version=TheVersionNumber')
    parser.add_option('--app-version', help=info)
    info = ('The versionCode of the app. Such as: --app-versionCode=24')
    parser.add_option('--app-versionCode', type='int', help=info)
    info = ('The application description. Such as:'
            '--description=YourApplicationdDescription')
    parser.add_option('--description', help=info)
    info = ('The permission list. Such as: --permissions="geolocation"'
            'For more permissions, such as:'
            '--permissions="geolocation:permission2"')
    parser.add_option('--permissions', help=info)
    info = ('The url of application. '
            'This flag allows to package website as apk. Such as: '
            '--app-url=http://www.intel.com')
    parser.add_option('--app-url', help=info)
    info = ('The root path of the web app. '
            'This flag allows to package local web app as apk. Such as: '
            '--app-root=/root/path/of/the/web/app')
    parser.add_option('--app-root', help=info)
    info = ('The reletive path of entry file based on |app_root|. '
            'This flag should work with "--app-root" together. '
            'Such as: --app-local-path=/reletive/path/of/entry/file')
    parser.add_option('--app-local-path', help=info)
    parser.add_option('--enable-remote-debugging',
                      action='store_true',
                      dest='enable_remote_debugging',
                      default=False,
                      help='Enable remote debugging.')
    parser.add_option('--use-animatable-view',
                      action='store_true',
                      dest='use_animatable_view',
                      default=False,
                      help='Enable using animatable view (TextureView).')
    parser.add_option('-f',
                      '--fullscreen',
                      action='store_true',
                      dest='fullscreen',
                      default=False,
                      help='Make application fullscreen.')
    parser.add_option('--keep-screen-on',
                      action='store_true',
                      default=False,
                      help='Support keeping screen on')
    info = ('The path list for external extensions separated by os separator.'
            'On Linux and Mac, the separator is ":". On Windows, it is ";".'
            'Such as: --extensions="/path/to/extension1:/path/to/extension2"')
    parser.add_option('--extensions', help=info)
    info = (
        'The orientation of the web app\'s display on the device. '
        'Such as: --orientation=landscape. The default value is "unspecified"'
        'The value options are the same as those on the Android: '
        'http://developer.android.com/guide/topics/manifest/'
        'activity-element.html#screen')
    parser.add_option('--orientation', help=info)
    parser.add_option('--manifest', help='The manifest path')
    info = (
        'Use command lines.'
        'Crosswalk is powered by Chromium and supports Chromium command line.'
        'For example, '
        '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'')
    info = ('Create an Android project directory at this location. ')
    parser.add_option('--project-dir', help=info)
    parser.add_option('--xwalk-command-line', default='', help=info)
    info = ('Minify and obfuscate javascript and css.'
            '--compressor: compress javascript and css.'
            '--compressor=js: compress javascript.'
            '--compressor=css: compress css.')
    parser.add_option('--compressor',
                      dest='compressor',
                      action='callback',
                      callback=ParseParameterForCompressor,
                      type='string',
                      nargs=0,
                      help=info)
    options, _ = parser.parse_args()
    try:
        icon_dict = {
            144: 'icons/icon_144.png',
            72: 'icons/icon_72.png',
            96: 'icons/icon_96.png',
            48: 'icons/icon_48.png'
        }
        app_info = AppInfo()
        if options.name is not None:
            app_info.android_name = options.name
        if options.app_root is None:
            app_info.app_root = os.path.join(xwalk_dir, 'test_data',
                                             'manifest')
        else:
            app_info.app_root = options.app_root
        if options.package is not None:
            app_info.package = options.package
        if options.orientation is not None:
            app_info.orientation = options.orientation
        if options.app_version is not None:
            app_info.app_version = options.app_version
        if options.enable_remote_debugging is not None:
            app_info.remote_debugging = options.enable_remote_debugging
        if options.fullscreen is not None:
            app_info.fullscreen_flag = options.fullscreen
        app_info.icon = os.path.join('test_data', 'manifest', 'icons',
                                     'icon_96.png')
        CustomizeAll(app_info, options.description, icon_dict,
                     options.permissions, options.app_url,
                     options.app_local_path, options.keep_screen_on,
                     options.extensions, None, options.xwalk_command_line,
                     options.compressor)

        # build project is now in /tmp/<name>. Copy to project_dir
        if options.project_dir:
            src_dir = GetBuildDir(app_info.android_name)
            dest_dir = os.path.join(options.project_dir, app_info.android_name)
            CreateAndCopyDir(src_dir, dest_dir, True)

    except SystemExit as ec:
        print('Exiting with error code: %d' % ec.code)
        return ec.code
    finally:
        CleanDir(GetBuildDir(app_info.android_name))
    return 0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option(
        "-v", "--version", action="store_true", dest="version", default=False, help="The version of this python tool."
    )
    parser.add_option("--verbose", action="store_true", dest="verbose", default=False, help="Print debug messages.")
    info = (
        "The packaging mode of the web application. The value 'shared' "
        "means that the runtime is shared across multiple application "
        "instances and that the runtime needs to be distributed separately. "
        "The value 'embedded' means that the runtime is embedded into the "
        "application itself and distributed along with it."
        "Set the default mode as 'embedded'. For example: --mode=embedded"
    )
    parser.add_option("--mode", choices=("embedded", "shared"), default="embedded", help=info)
    info = (
        "The target architecture of the embedded runtime. Supported values "
        "are 'x86' and 'arm'. Note, if undefined, APKs for all possible "
        "architestures will be generated."
    )
    parser.add_option("--arch", choices=AllArchitectures(), help=info)
    group = optparse.OptionGroup(
        parser,
        "Application Source Options",
        "This packaging tool supports 3 kinds of web application source: "
        "1) XPK package; 2) manifest.json; 3) various command line options, "
        "for example, '--app-url' for website, '--app-root' and "
        "'--app-local-path' for local web application.",
    )
    info = "The path of the XPK package. For example, --xpk=/path/to/xpk/file"
    group.add_option("--xpk", help=info)
    info = (
        "The manifest file with the detail description of the application. "
        "For example, --manifest=/path/to/your/manifest/file"
    )
    group.add_option("--manifest", help=info)
    info = (
        "The url of application. "
        "This flag allows to package website as apk. For example, "
        "--app-url=http://www.intel.com"
    )
    group.add_option("--app-url", help=info)
    info = (
        "The root path of the web app. "
        "This flag allows to package local web app as apk. For example, "
        "--app-root=/root/path/of/the/web/app"
    )
    group.add_option("--app-root", help=info)
    info = (
        "The relative path of entry file based on the value from "
        "'app_root'. This flag should work with '--app-root' together. "
        "For example, --app-local-path=/relative/path/of/entry/file"
    )
    group.add_option("--app-local-path", help=info)
    parser.add_option_group(group)
    group = optparse.OptionGroup(
        parser,
        "Mandatory arguments",
        "They are used for describing the APK information through " "command line options.",
    )
    info = 'The apk name. For example, --name="Your Application Name"'
    group.add_option("--name", help=info)
    info = "The package name. For example, " "--package=com.example.YourPackage"
    group.add_option("--package", help=info)
    parser.add_option_group(group)
    group = optparse.OptionGroup(
        parser,
        "Optional arguments",
        "They are used for various settings for applications through " "command line options.",
    )
    info = "The version name of the application. " "For example, --app-version=1.0.0"
    group.add_option("--app-version", help=info)
    info = "The version code of the application. " "For example, --app-versionCode=24"
    group.add_option("--app-versionCode", type="int", help=info)
    info = (
        "The version code base of the application. Version code will "
        "be made by adding a prefix based on architecture to the version "
        "code base. For example, --app-versionCodeBase=24"
    )
    group.add_option("--app-versionCodeBase", type="int", help=info)
    info = (
        "Use command lines."
        "Crosswalk is powered by Chromium and supports Chromium command line."
        "For example, "
        "--xwalk-command-line='--chromium-command-1 --xwalk-command-2'"
    )
    group.add_option("--xwalk-command-line", default="", help=info)
    info = "The description of the application. For example, " "--description=YourApplicationDescription"
    group.add_option("--description", help=info)
    group.add_option(
        "--enable-remote-debugging",
        action="store_true",
        dest="enable_remote_debugging",
        default=False,
        help="Enable remote debugging.",
    )
    info = (
        "The list of external extension paths splitted by OS separators. "
        "The separators are ':' , ';' and ':' on Linux, Windows and "
        "Mac OS respectively. For example, "
        "--extensions=/path/to/extension1:/path/to/extension2."
    )
    group.add_option("--extensions", help=info)
    group.add_option(
        "-f", "--fullscreen", action="store_true", dest="fullscreen", default=False, help="Make application fullscreen."
    )
    group.add_option("--keep-screen-on", action="store_true", default=False, help="Support keeping screen on")
    info = "The path of application icon. " "Such as: --icon=/path/to/your/customized/icon"
    group.add_option("--icon", help=info)
    info = (
        "The orientation of the web app's display on the device. "
        "For example, --orientation=landscape. The default value is "
        "'unspecified'. The permitted values are from Android: "
        "http://developer.android.com/guide/topics/manifest/"
        "activity-element.html#screen"
    )
    group.add_option("--orientation", help=info)
    info = "The list of permissions to be used by web application. For example, " "--permissions=geolocation:webgl"
    group.add_option("--permissions", help=info)
    info = "Packaging tool will move the output APKS to the target directory"
    group.add_option("--target-dir", default=os.getcwd(), help=info)
    parser.add_option_group(group)
    group = optparse.OptionGroup(
        parser,
        "Keystore Options",
        "The keystore is a signature from web developer, it's used when "
        "developer wants to distribute the applications.",
    )
    info = "The path to the developer keystore. For example, " "--keystore-path=/path/to/your/developer/keystore"
    group.add_option("--keystore-path", help=info)
    info = "The alias name of keystore. For example, --keystore-alias=name"
    group.add_option("--keystore-alias", help=info)
    info = "The passcode of keystore. For example, --keystore-passcode=code"
    group.add_option("--keystore-passcode", help=info)
    info = (
        "Minify and obfuscate javascript and css."
        "--compressor: compress javascript and css."
        "--compressor=js: compress javascript."
        "--compressor=css: compress css."
    )
    group.add_option(
        "--compressor",
        dest="compressor",
        action="callback",
        callback=ParseParameterForCompressor,
        type="string",
        nargs=0,
        help=info,
    )
    parser.add_option_group(group)
    options, _ = parser.parse_args()
    if len(argv) == 1:
        parser.print_help()
        return 0

    if options.version:
        if os.path.isfile("VERSION"):
            print(GetVersion("VERSION"))
            return 0
        else:
            parser.error("VERSION was not found, so Crosswalk's version could not " "be determined.")

    xpk_temp_dir = ""
    if options.xpk:
        xpk_name = os.path.splitext(os.path.basename(options.xpk))[0]
        xpk_temp_dir = xpk_name + "_xpk"
        ParseXPK(options, xpk_temp_dir)

    if options.app_root and not options.manifest:
        manifest_path = os.path.join(options.app_root, "manifest.json")
        if os.path.exists(manifest_path):
            print("Using manifest.json distributed with the application.")
            options.manifest = manifest_path

    app_info = AppInfo()
    if not options.manifest:
        if options.package:
            VerifyAppName(options.package, "packagename")
        else:
            parser.error('A package name is required. Please use the "--package" ' "option.")
        if options.name:
            VerifyAppName(options.name)
            app_info.original_name = options.name
            options.name = ReplaceSpaceWithUnderscore(options.name)
        else:
            parser.error('An APK name is required. Please use the "--name" option.')

        # The checks here are really convoluted, but at the moment make_apk
        # misbehaves any of the following conditions is true.
        if options.app_url:
            # 1) --app-url must be passed without either --app-local-path or
            #    --app-root.
            if options.app_root or options.app_local_path:
                parser.error(
                    'You must pass either "--app-url" or "--app-local-path" ' 'with "--app-root", but not all.'
                )
        else:
            # 2) --app-url is not passed but only one of --app-local-path and
            #    --app-root is set.
            if bool(options.app_root) != bool(options.app_local_path):
                parser.error('You must specify both "--app-local-path" and ' '"--app-root".')
            # 3) None of --app-url, --app-local-path and --app-root are passed.
            elif not options.app_root and not options.app_local_path:
                parser.error('You must pass either "--app-url" or "--app-local-path" ' 'with "--app-root".')

        if options.permissions:
            permission_list = options.permissions.split(":")
        else:
            print(
                "Warning: all supported permissions on Android port are added. "
                "Refer to https://github.com/crosswalk-project/"
                "crosswalk-website/wiki/Crosswalk-manifest"
            )
            permission_list = permission_mapping_table.keys()
        options.permissions = HandlePermissionList(permission_list)
        options.icon_dict = {}
    else:
        try:
            ParseManifest(options, app_info)
        except SystemExit as ec:
            return ec.code

    if (
        options.app_root
        and options.app_local_path
        and not os.path.isfile(os.path.join(options.app_root, options.app_local_path))
    ):
        print("Please make sure that the local path file of launching app " "does exist.")
        sys.exit(7)

    if options.target_dir:
        target_dir = os.path.abspath(os.path.expanduser(options.target_dir))
        options.target_dir = target_dir
        if not os.path.isdir(target_dir):
            os.makedirs(target_dir)

    try:
        MakeApk(options, app_info)
    except SystemExit as ec:
        CleanDir(options.name)
        CleanDir("out")
        CleanDir(xpk_temp_dir)
        return ec.code
    return 0
示例#9
0
def main(argv):
    settings, args = process_command_line(sys.argv[1:])
    cloudlet = None
    app_info = AppInfo(
        **{
            AppInfo.APP_ID:
            "moped",
            AppInfo.REQUIRED_RTT:
            30,
            AppInfo.REQUIRED_MIN_CPU_CLOCK:
            1600,  # in MHz
            AppInfo.REQUIRED_CACHE_URLS: [
                "http://amazon-asia.krha.kr/overlay-webapp-face.zip",
                "http://krha.kr/data/publications/mobisys203-kiryong.pdf",
            ],
            AppInfo.REQUIRED_CACHE_FILES: [
                "moped/**/*.xml",
            ]
        })

    # find the best cloudlet querying to the registration server
    if settings.register_server is not None:
        client = CloudletDiscoveryClient(settings.register_server)
        if settings.latitude is not None and settings.longitude is not None:
            cloudlet = client.find_by_gps(settings.latitude, \
                    settings.longitude, app_info=app_info)
        elif settings.client_ip is not None:
            cloudlet = client.find_by_ip(settings.client_ip, \
                    app_info=app_info)
        else:
            cloudlet = client.find_by_ip(app_info=app_info)
        LOG.debug("Query results:")
        LOG.debug(pprint.pformat(cloudlet))
        LOG.debug("Time Measurement")
        LOG.debug("%s" % client.get_time_measurement())

    # perform cloudlet provisioning using given VM overlay
    if cloudlet and (settings.overlay_file or settings.overlay_url):
        synthesis_client = None
        # provision the back-end server at the Cloudlet
        ip_addr = cloudlet.get("ip_address")
        port = SynthesisClient.CLOUDLET_PORT
        synthesis_option = dict()
        synthesis_option[Protocol.SYNTHESIS_OPTION_DISPLAY_VNC] = False
        synthesis_option[Protocol.SYNTHESIS_OPTION_EARLY_START] = False

        if settings.overlay_file:
            synthesis_client = SynthesisClient(
                ip_addr,
                port,
                overlay_file=settings.overlay_file,
                app_function=None,
                synthesis_option=synthesis_option)
        elif settings.overlay_url:
            synthesis_client = SynthesisClient(
                ip_addr,
                port,
                overlay_url=settings.overlay_url,
                app_function=None,
                synthesis_option=synthesis_option)

        try:
            synthesis_client.provisioning()
            #synthesis_client.terminate()
            sys.stdout.write("SUCCESS in Provisioning\n")
        except ClientError as e:
            sys.stderr.write(str(e))
        return 1
    return 0
示例#10
0
def main():
    parser = optparse.OptionParser()
    info = "The package name. Such as: " "--package=com.example.YourPackage"
    parser.add_option("--package", help=info)
    info = 'The apk name. Such as: --name="Your Application Name"'
    parser.add_option("--name", help=info)
    info = "The version of the app. Such as: --app-version=TheVersionNumber"
    parser.add_option("--app-version", help=info)
    info = "The versionCode of the app. Such as: --app-versionCode=24"
    parser.add_option("--app-versionCode", type="int", help=info)
    info = "The application description. Such as:" "--description=YourApplicationdDescription"
    parser.add_option("--description", help=info)
    info = (
        'The permission list. Such as: --permissions="geolocation"'
        "For more permissions, such as:"
        '--permissions="geolocation:permission2"'
    )
    parser.add_option("--permissions", help=info)
    info = (
        "The url of application. "
        "This flag allows to package website as apk. Such as: "
        "--app-url=http://www.intel.com"
    )
    parser.add_option("--app-url", help=info)
    info = (
        "The root path of the web app. "
        "This flag allows to package local web app as apk. Such as: "
        "--app-root=/root/path/of/the/web/app"
    )
    parser.add_option("--app-root", help=info)
    info = (
        "The reletive path of entry file based on |app_root|. "
        'This flag should work with "--app-root" together. '
        "Such as: --app-local-path=/reletive/path/of/entry/file"
    )
    parser.add_option("--app-local-path", help=info)
    parser.add_option(
        "--enable-remote-debugging",
        action="store_true",
        dest="enable_remote_debugging",
        default=False,
        help="Enable remote debugging.",
    )
    parser.add_option(
        "-f", "--fullscreen", action="store_true", dest="fullscreen", default=False, help="Make application fullscreen."
    )
    parser.add_option("--keep-screen-on", action="store_true", default=False, help="Support keeping screen on")
    info = (
        "The path list for external extensions separated by os separator."
        'On Linux and Mac, the separator is ":". On Windows, it is ";".'
        'Such as: --extensions="/path/to/extension1:/path/to/extension2"'
    )
    parser.add_option("--extensions", help=info)
    info = (
        "The orientation of the web app's display on the device. "
        'Such as: --orientation=landscape. The default value is "unspecified"'
        "The value options are the same as those on the Android: "
        "http://developer.android.com/guide/topics/manifest/"
        "activity-element.html#screen"
    )
    parser.add_option("--orientation", help=info)
    parser.add_option("--manifest", help="The manifest path")
    info = (
        "Use command lines."
        "Crosswalk is powered by Chromium and supports Chromium command line."
        "For example, "
        "--xwalk-command-line='--chromium-command-1 --xwalk-command-2'"
    )
    parser.add_option("--xwalk-command-line", default="", help=info)
    info = (
        "Minify and obfuscate javascript and css."
        "--compressor: compress javascript and css."
        "--compressor=js: compress javascript."
        "--compressor=css: compress css."
    )
    parser.add_option(
        "--compressor",
        dest="compressor",
        action="callback",
        callback=ParseParameterForCompressor,
        type="string",
        nargs=0,
        help=info,
    )
    options, _ = parser.parse_args()
    try:
        icon_dict = {
            144: "icons/icon_144.png",
            72: "icons/icon_72.png",
            96: "icons/icon_96.png",
            48: "icons/icon_48.png",
        }
        app_info = AppInfo()
        if options.name is not None:
            app_info.android_name = options.name
        if options.app_root is None:
            app_info.app_root = os.path.join("test_data", "manifest")
        else:
            app_info.app_root = options.app_root
        if options.package is not None:
            app_info.package = options.package
        if options.orientation is not None:
            app_info.orientation = options.orientation
        if options.app_version is not None:
            app_info.app_version = options.app_version
        if options.enable_remote_debugging is not None:
            app_info.remote_debugging = options.enable_remote_debugging
        if options.fullscreen is not None:
            app_info.fullscreen_flag = options.fullscreen
        app_info.icon = os.path.join("test_data", "manifest", "icons", "icon_96.png")
        CustomizeAll(
            app_info,
            options.description,
            icon_dict,
            options.permissions,
            options.app_url,
            options.app_local_path,
            options.keep_screen_on,
            options.extensions,
            None,
            options.xwalk_command_line,
            options.compressor,
        )
    except SystemExit as ec:
        print("Exiting with error code: %d" % ec.code)
        return ec.code
    return 0
示例#11
0
        },
    }
})



sql = """SELECT * FROM dsid_lppa_v2 WHERE id = 3249444"""
row = db.session.execute(sql).fetchone()
blob = row['lppa']
_ = msgpack.unpackb(blob)
pprint.pprint(_)

appList = []
try:
    lppa = msgpack.unpackb(blob)
    appList = [AppInfo.from_v1(k, v) for k, v in lppa.items()]
except msgpack.exceptions.UnpackException:
    pass

pprint.pprint(appList)

#
#  if len(appList) <= 0:
#      try:
#          b = lzma.decompress(blob)
#          lppa = simplejson.loads(b)
#          appList = [AppInfo(**item) for item in lppa]
#      except lzma.LZMAError:
#          pass

# pprint.pprint(appList)
示例#12
0
文件: app.py 项目: chamith/pixync
import argparse
import subprocess
import yaml
import os
import glob
import time
import shutil
import sqlite3
import xml.etree.ElementTree as ET
import gdrive_adapter
import metadata_util
from app_info import AppInfo
from app_config import AppConfig

appInfo = AppInfo()
appConfig = AppConfig(appInfo)
IGNORE_FILE = ".pixignore"
GDRIVE_REPO_PREFIX = 'gdrive:'
BANNER_WIDTH = 75
config_settings_global = None
config_settings_local = None


def print_banner():
    if quiet:
        return

    print("{:_<75}".format(''))
    print("""
__________._______  ________.___._______  _________  
示例#13
0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option('-v',
                      '--version',
                      action='store_true',
                      dest='version',
                      default=False,
                      help='The version of this python tool.')
    parser.add_option('--verbose',
                      action="store_true",
                      dest='verbose',
                      default=False,
                      help='Print debug messages.')
    info = (
        'The packaging mode of the web application. The value \'shared\' '
        'means that the runtime is shared across multiple application '
        'instances and that the runtime needs to be distributed separately. '
        'The value \'embedded\' means that the runtime is embedded into the '
        'application itself and distributed along with it.'
        'Set the default mode as \'embedded\'. For example: --mode=embedded')
    parser.add_option('--mode',
                      choices=('embedded', 'shared'),
                      default='embedded',
                      help=info)
    info = (
        'The target architecture of the embedded runtime. Supported values '
        'are \'x86\' and \'arm\'. Note, if undefined, APKs for all possible '
        'architestures will be generated.')
    parser.add_option('--arch', choices=AllArchitectures(), help=info)
    group = optparse.OptionGroup(
        parser, 'Application Source Options',
        'This packaging tool supports 3 kinds of web application source: '
        '1) XPK package; 2) manifest.json; 3) various command line options, '
        'for example, \'--app-url\' for website, \'--app-root\' and '
        '\'--app-local-path\' for local web application.')
    info = (
        'The path of the XPK package. For example, --xpk=/path/to/xpk/file')
    group.add_option('--xpk', help=info)
    info = (
        'The manifest file with the detail description of the application. '
        'For example, --manifest=/path/to/your/manifest/file')
    group.add_option('--manifest', help=info)
    info = ('The url of application. '
            'This flag allows to package website as apk. For example, '
            '--app-url=http://www.intel.com')
    group.add_option('--app-url', help=info)
    info = ('The root path of the web app. '
            'This flag allows to package local web app as apk. For example, '
            '--app-root=/root/path/of/the/web/app')
    group.add_option('--app-root', help=info)
    info = (
        'The relative path of entry file based on the value from '
        '\'app_root\'. This flag should work with \'--app-root\' together. '
        'For example, --app-local-path=/relative/path/of/entry/file')
    group.add_option('--app-local-path', help=info)
    parser.add_option_group(group)
    group = optparse.OptionGroup(
        parser, 'Mandatory arguments',
        'They are used for describing the APK information through '
        'command line options.')
    info = ('The apk name. For example, --name="Your Application Name"')
    group.add_option('--name', help=info)
    info = ('The package name. For example, '
            '--package=com.example.YourPackage')
    group.add_option('--package', help=info)
    parser.add_option_group(group)
    group = optparse.OptionGroup(
        parser, 'Optional arguments',
        'They are used for various settings for applications through '
        'command line options.')
    info = ('The version name of the application. '
            'For example, --app-version=1.0.0')
    group.add_option('--app-version', help=info)
    info = ('The version code of the application. '
            'For example, --app-versionCode=24')
    group.add_option('--app-versionCode', type='int', help=info)
    info = ('The version code base of the application. Version code will '
            'be made by adding a prefix based on architecture to the version '
            'code base. For example, --app-versionCodeBase=24')
    group.add_option('--app-versionCodeBase', type='int', help=info)
    info = (
        'Use command lines.'
        'Crosswalk is powered by Chromium and supports Chromium command line.'
        'For example, '
        '--xwalk-command-line=\'--chromium-command-1 --xwalk-command-2\'')
    group.add_option('--xwalk-command-line', default='', help=info)
    info = ('The description of the application. For example, '
            '--description=YourApplicationDescription')
    group.add_option('--description', help=info)
    group.add_option('--enable-remote-debugging',
                     action='store_true',
                     dest='enable_remote_debugging',
                     default=False,
                     help='Enable remote debugging.')
    info = ('The list of external extension paths splitted by OS separators. '
            'The separators are \':\' , \';\' and \':\' on Linux, Windows and '
            'Mac OS respectively. For example, '
            '--extensions=/path/to/extension1:/path/to/extension2.')
    group.add_option('--extensions', help=info)
    group.add_option('-f',
                     '--fullscreen',
                     action='store_true',
                     dest='fullscreen',
                     default=False,
                     help='Make application fullscreen.')
    group.add_option('--keep-screen-on',
                     action='store_true',
                     default=False,
                     help='Support keeping screen on')
    info = ('The path of application icon. '
            'Such as: --icon=/path/to/your/customized/icon')
    group.add_option('--icon', help=info)
    info = ('The orientation of the web app\'s display on the device. '
            'For example, --orientation=landscape. The default value is '
            '\'unspecified\'. The permitted values are from Android: '
            'http://developer.android.com/guide/topics/manifest/'
            'activity-element.html#screen')
    group.add_option('--orientation', help=info)
    info = (
        'The list of permissions to be used by web application. For example, '
        '--permissions=geolocation:webgl')
    group.add_option('--permissions', help=info)
    info = ('Packaging tool will move the output APKS to the target directory')
    group.add_option('--target-dir', default=os.getcwd(), help=info)
    parser.add_option_group(group)
    group = optparse.OptionGroup(
        parser, 'Keystore Options',
        'The keystore is a signature from web developer, it\'s used when '
        'developer wants to distribute the applications.')
    info = ('The path to the developer keystore. For example, '
            '--keystore-path=/path/to/your/developer/keystore')
    group.add_option('--keystore-path', help=info)
    info = ('The alias name of keystore. For example, --keystore-alias=name')
    group.add_option('--keystore-alias', help=info)
    info = ('The passcode of keystore. For example, --keystore-passcode=code')
    group.add_option('--keystore-passcode', help=info)
    info = ('Minify and obfuscate javascript and css.'
            '--compressor: compress javascript and css.'
            '--compressor=js: compress javascript.'
            '--compressor=css: compress css.')
    group.add_option('--compressor',
                     dest='compressor',
                     action='callback',
                     callback=ParseParameterForCompressor,
                     type='string',
                     nargs=0,
                     help=info)
    parser.add_option_group(group)
    options, _ = parser.parse_args()
    if len(argv) == 1:
        parser.print_help()
        return 0

    if options.version:
        if os.path.isfile('VERSION'):
            print(GetVersion('VERSION'))
            return 0
        else:
            parser.error('Can\'t get version due to the VERSION file missing!')

    xpk_temp_dir = ''
    if options.xpk:
        xpk_name = os.path.splitext(os.path.basename(options.xpk))[0]
        xpk_temp_dir = xpk_name + '_xpk'
        ParseXPK(options, xpk_temp_dir)

    if options.app_root and not options.manifest:
        manifest_path = os.path.join(options.app_root, 'manifest.json')
        if os.path.exists(manifest_path):
            print('Using manifest.json distributed with the application.')
            options.manifest = manifest_path

    app_info = AppInfo()
    if not options.manifest:
        if options.package:
            VerifyAppName(options.package, 'packagename')
        else:
            parser.error('The package name is required! '
                         'Please use "--package" option.')
        if options.name:
            VerifyAppName(options.name)
            app_info.original_name = options.name
            options.name = ReplaceSpaceWithUnderscore(options.name)
        else:
            parser.error(
                'The APK name is required! Please use "--name" option.')
        if not ((options.app_url and not options.app_root
                 and not options.app_local_path) or
                (not options.app_url and options.app_root
                 and options.app_local_path)):
            parser.error(
                'The entry is required. If the entry is a remote url, '
                'please use "--app-url" option; If the entry is local, '
                'please use "--app-root" and '
                '"--app-local-path" options together!')
        if options.permissions:
            permission_list = options.permissions.split(':')
        else:
            print(
                'Warning: all supported permissions on Android port are added. '
                'Refer to https://github.com/crosswalk-project/'
                'crosswalk-website/wiki/Crosswalk-manifest')
            permission_list = permission_mapping_table.keys()
        options.permissions = HandlePermissionList(permission_list)
        options.icon_dict = {}
    else:
        try:
            ParseManifest(options, app_info)
        except SystemExit as ec:
            return ec.code

    if (options.app_root and options.app_local_path and not os.path.isfile(
            os.path.join(options.app_root, options.app_local_path))):
        print('Please make sure that the local path file of launching app '
              'does exist.')
        sys.exit(7)

    if options.target_dir:
        target_dir = os.path.abspath(os.path.expanduser(options.target_dir))
        options.target_dir = target_dir
        if not os.path.isdir(target_dir):
            os.makedirs(target_dir)

    try:
        MakeApk(options, app_info)
    except SystemExit as ec:
        CleanDir(options.name)
        CleanDir('out')
        CleanDir(xpk_temp_dir)
        return ec.code
    return 0