import re
import sys
+
def HandlePermissionList(permission_list):
"""This function is used to handle the permission list and return the string
of permissions.
return ':'.join(permissions)
+def ParseLaunchScreen(ret_dict, launch_screen_dict, orientation):
+ if orientation in launch_screen_dict:
+ sub_dict = launch_screen_dict[orientation]
+ if 'background_color' in sub_dict:
+ ret_dict['launch_screen_background_color_' + orientation] = (
+ sub_dict['background_color'])
+ if 'background_image' in sub_dict:
+ ret_dict['launch_screen_background_image_' + orientation] = (
+ sub_dict['background_image'])
+ if 'image' in sub_dict:
+ ret_dict['launch_screen_image_' + orientation] = (
+ sub_dict['image'])
+ if 'image_border' in sub_dict:
+ ret_dict['launch_screen_image_border_' + orientation] = (
+ sub_dict['image_border'])
+
+
+def PrintDeprecationWarning(item):
+ print ('WARNING: %s is deprecated for Crosswalk. Please follow '
+ 'https://www.crosswalk-project.org/#documentation/manifest.' % item)
+
+
class ManifestJsonParser(object):
- """ The class is used to parse json-format manifest file, recompose the fields
- and provide the field interfaces required by the packaging tool.
+ """ The class is used to parse json-format manifest file, recompose the
+ fields and provide the field interfaces required by the packaging tool.
Args:
input_path: the full path of the json-format manifest file.
input_src = input_file.read()
self.data_src = json.JSONDecoder().decode(input_src)
self.ret_dict = self._output_items()
- except (TypeError, ValueError, IOError):
- print('There is a parser error in manifest.json file.')
+ except (TypeError, ValueError, IOError) as error:
+ print('There is a parser error in manifest.json file: %s' % error)
sys.exit(1)
- except KeyError:
- print('There is a field error in manifest.json file.')
+ except KeyError as error:
+ print('There is a field error in manifest.json file: %s' % error)
sys.exit(1)
finally:
input_file.close()
permissions: The permission list.
required_version: The required crosswalk runtime version.
plugin: The plug-in information.
+ orientation The default allowed orientations.
fullscreen: The fullscreen flag of the application.
launch_screen: The launch screen configuration.
"""
print('Error: no \'version\' field in manifest.json file.')
sys.exit(1)
ret_dict['version'] = self.data_src['version']
- if 'launch_path' in self.data_src:
+ if 'start_url' in self.data_src:
+ app_url = self.data_src['start_url']
+ elif 'launch_path' in self.data_src:
+ PrintDeprecationWarning('launch_path')
app_url = self.data_src['launch_path']
elif ('app' in self.data_src and
- 'launch' in self.data_src['app'] and
- 'local_path' in self.data_src['app']['launch']):
+ 'launch' in self.data_src['app'] and
+ 'local_path' in self.data_src['app']['launch']):
+ PrintDeprecationWarning('app.launch.local_path')
app_url = self.data_src['app']['launch']['local_path']
else:
app_url = ''
app_url = ''
file_path_prefix = os.path.split(self.input_path)[0]
if 'icons' in self.data_src:
- ret_dict['icons'] = self.data_src['icons']
+ icons = self.data_src['icons']
+ if type(icons) == dict:
+ PrintDeprecationWarning('icons defined as dictionary form')
+ ret_dict['icons'] = icons
+ elif type(icons) == list:
+ icons_dict = {}
+ for icon in icons:
+ if 'sizes' in icon and 'src' in icon:
+ icons_dict[icon['sizes'].split('x')[0]] = icon['src']
+ ret_dict['icons'] = icons_dict
+ else:
+ ret_dict['icons'] = {}
else:
ret_dict['icons'] = {}
app_root = file_path_prefix
ret_dict['app_root'] = app_root
ret_dict['app_local_path'] = app_local_path
ret_dict['permissions'] = ''
- if 'permissions' in self.data_src:
+ if 'xwalk_permissions' in self.data_src:
+ try:
+ permission_list = self.data_src['xwalk_permissions']
+ ret_dict['permissions'] = HandlePermissionList(permission_list)
+ except (TypeError, ValueError, IOError):
+ print('\'Permissions\' field error in manifest.json file.')
+ sys.exit(1)
+ elif 'permissions' in self.data_src:
+ PrintDeprecationWarning('permissions')
try:
permission_list = self.data_src['permissions']
ret_dict['permissions'] = HandlePermissionList(permission_list)
ret_dict['plugin'] = ''
if 'plugin' in self.data_src:
ret_dict['plugin'] = self.data_src['plugin']
+ orientation = {'landscape':'landscape',
+ 'landscape-primary':'landscape',
+ 'landscape-secondary':'reverseLandscape',
+ 'portrait':'portrait',
+ 'portrait-primary':'portrait',
+ 'portrait-secondary':'reversePortrait',
+ 'any':'unspecified',
+ 'natural':'unspecified'}
+ if 'orientation' in self.data_src:
+ if self.data_src['orientation'] in orientation:
+ ret_dict['orientation'] = orientation[self.data_src['orientation']]
+ else:
+ ret_dict['orientation'] = 'unspecified'
+ else:
+ ret_dict['orientation'] = 'unspecified'
if 'display' in self.data_src and 'fullscreen' in self.data_src['display']:
ret_dict['fullscreen'] = 'true'
else:
ret_dict['fullscreen'] = ''
- if 'launch_screen' in self.data_src:
- self.ParseLaunchScreen(ret_dict, 'default')
- self.ParseLaunchScreen(ret_dict, 'portrait')
- self.ParseLaunchScreen(ret_dict, 'landscape')
+ if 'xwalk_launch_screen' in self.data_src:
+ launch_screen_dict = self.data_src['xwalk_launch_screen']
+ ParseLaunchScreen(ret_dict, launch_screen_dict, 'default')
+ ParseLaunchScreen(ret_dict, launch_screen_dict, 'portrait')
+ ParseLaunchScreen(ret_dict, launch_screen_dict, 'landscape')
+ elif 'launch_screen' in self.data_src:
+ PrintDeprecationWarning('launch_screen')
+ launch_screen_dict = self.data_src['launch_screen']
+ ParseLaunchScreen(ret_dict, launch_screen_dict, 'default')
+ ParseLaunchScreen(ret_dict, launch_screen_dict, 'portrait')
+ ParseLaunchScreen(ret_dict, launch_screen_dict, 'landscape')
return ret_dict
- def ParseLaunchScreen(self, ret_dict, orientation):
- if orientation in self.data_src['launch_screen']:
- sub_dict = self.data_src['launch_screen'][orientation]
- if 'background_color' in sub_dict:
- ret_dict['launch_screen_background_color_' + orientation] = (
- sub_dict['background_color'])
- if 'background_image' in sub_dict:
- ret_dict['launch_screen_background_image_' + orientation] = (
- sub_dict['background_image'])
- if 'image' in sub_dict:
- ret_dict['launch_screen_image_' + orientation] = (
- sub_dict['image'])
- if 'image_border' in sub_dict:
- ret_dict['launch_screen_image_border_' + orientation] = (
- sub_dict['image_border'])
-
def ShowItems(self):
"""Show the processed results, it is used for command-line
internal debugging."""
print("permissions: %s" % self.GetPermissions())
print("required_version: %s" % self.GetRequiredVersion())
print("plugins: %s" % self.GetPlugins())
+ print("orientation: %s" % self.GetOrientation())
print("fullscreen: %s" % self.GetFullScreenFlag())
print('launch_screen.default.background_color: %s' %
self.GetLaunchScreenBackgroundColor('default'))
print('launch_screen.landscape.image_border: %s' %
self.GetLaunchScreenImageBorder('landscape'))
-
def GetAppName(self):
"""Return the application name."""
return self.ret_dict['app_name']
"""Return the plug-in path and file name."""
return self.ret_dict['plugin']
+ def GetOrientation(self):
+ """Return the default allowed orientations"""
+ return self.ret_dict['orientation']
+
def GetFullScreenFlag(self):
"""Return the set fullscreen flag of the application."""
return self.ret_dict['fullscreen']
def GetLaunchScreenBackgroundColor(self, orientation):
"""Return the background color for launch_screen."""
- if 'launch_screen_background_color_' + orientation in self.ret_dict:
- return self.ret_dict['launch_screen_background_color_' + orientation]
- else:
- return ''
+ key = 'launch_screen_background_color_' + orientation
+ return self.ret_dict.get(key, '')
def GetLaunchScreenBackgroundImage(self, orientation):
"""Return the background image for launch_screen."""
- if 'launch_screen_background_image_' + orientation in self.ret_dict:
- return self.ret_dict['launch_screen_background_image_' + orientation]
- else:
- return ''
+ key = 'launch_screen_background_image_' + orientation
+ return self.ret_dict.get(key, '')
def GetLaunchScreenImage(self, orientation):
"""Return the image for launch_screen."""
- if 'launch_screen_image_' + orientation in self.ret_dict:
- return self.ret_dict['launch_screen_image_' + orientation]
- else:
- return ''
+ key = 'launch_screen_image_' + orientation
+ return self.ret_dict.get(key, '')
def GetLaunchScreenImageBorder(self, orientation):
"""Return the image border for launch_screen."""
- if 'launch_screen_image_border_' + orientation in self.ret_dict:
- return self.ret_dict['launch_screen_image_border_' + orientation]
- else:
- return ''
+ key = 'launch_screen_image_border_' + orientation
+ return self.ret_dict.get(key, '')
def main(argv):