def _CreateFeaturesFromJSONFutures(json_futures):
    '''Returns a dict of features. The value of each feature is a list with
  all of its possible values.
  '''
    def ignore_feature(name, value):
        '''Returns true if this feature should be ignored. Features are ignored if
    they are only available to whitelisted apps or component extensions/apps, as
    in these cases the APIs are not available to public developers.

    Private APIs are also unavailable to public developers, but logic elsewhere
    makes sure they are not listed. So they shouldn't be ignored via this
    mechanism.
    '''
        if name.endswith('Private'):
            return False
        return value.get('location') == 'component' or 'whitelist' in value

    features = {}

    for json_future in json_futures:
        try:
            features_json = Parse(json_future.Get())
        except FileNotFoundError:
            # Not all file system configurations have the extra files.
            continue
        for name, rawvalue in features_json.iteritems():
            if name not in features:
                features[name] = []
            for value in (rawvalue if isinstance(rawvalue, list) else
                          (rawvalue, )):
                if not ignore_feature(name, value):
                    features[name].append(value)

    return features
Beispiel #2
0
def _CreateFeaturesFromJSONFutures(json_futures):
  '''Returns a dict of features. The value of each feature is a list with
  all of its possible values.
  '''
  def ignore_feature(name, value):
    '''Returns true if this feature should be ignored. Features are ignored if
    they are only available to whitelisted apps or component extensions/apps, as
    in these cases the APIs are not available to public developers.

    Private APIs are also unavailable to public developers, but logic elsewhere
    makes sure they are not listed. So they shouldn't be ignored via this
    mechanism.
    '''
    if name.endswith('Private'):
      return False
    return value.get('location') == 'component' or 'whitelist' in value

  features = {}

  for json_future in json_futures:
    try:
      features_json = Parse(json_future.Get())
    except FileNotFoundError:
      # Not all file system configurations have the extra files.
      continue
    for name, rawvalue in features_json.iteritems():
      if name not in features:
        features[name] = []
      for value in (rawvalue if isinstance(rawvalue, list) else (rawvalue,)):
        if not ignore_feature(name, value):
          features[name].append(value)

  return features
 def _CreateCache(self, _, features_json):
   extra_path_futures = [self._text_cache.GetFromFile(path)
                         for path in self._extra_paths]
   features = features_utility.Parse(Parse(features_json))
   for path_future in extra_path_futures:
     extra_json = path_future.Get()
     features = features_utility.MergedWith(
         features_utility.Parse(Parse(extra_json)), features)
   return features
    def _CreateManifestData(self, _, content):
        '''Take the contents of |_manifest_path| and create apps and extensions
    versions of a manifest example based on the contents of |_features_path|.
    '''
        def create_manifest_dict():
            manifest_dict = OrderedDict()
            for category in ('required', 'only_one', 'recommended',
                             'optional'):
                manifest_dict[category] = []
            return manifest_dict

        apps = create_manifest_dict()
        extensions = create_manifest_dict()

        manifest_json = Parse(content)
        features_json = Parse(self._file_system.ReadSingle(
            self._features_path))

        def add_property(feature, manifest_key, category):
            '''If |feature|, from features_json, has the correct extension_types, add
      |manifest_key| to either apps or extensions.
      '''
            added = False
            extension_types = feature['extension_types']
            if extension_types == 'all' or 'platform_app' in extension_types:
                apps[category].append(deepcopy(manifest_key))
                added = True
            if extension_types == 'all' or 'extension' in extension_types:
                extensions[category].append(deepcopy(manifest_key))
                added = True
            return added

        # Property types are: required, only_one, recommended, and optional.
        for category in manifest_json:
            for manifest_key in manifest_json[category]:
                # If a property is in manifest.json but not _manifest_features, this
                # will cause an error.
                feature = features_json[manifest_key['name']]
                if add_property(feature, manifest_key, category):
                    del features_json[manifest_key['name']]

        # All of the properties left in features_json are assumed to be optional.
        for feature in features_json.keys():
            item = features_json[feature]
            # Handles instances where a features entry is a union with a whitelist.
            if isinstance(item, list):
                item = item[0]
            add_property(item, {'name': feature}, 'optional')

        apps['optional'].sort(key=itemgetter('name'))
        extensions['optional'].sort(key=itemgetter('name'))

        self._ApplyAppsTransformations(apps)
        self._ApplyExtensionsTransformations(extensions)

        return {'apps': apps, 'extensions': extensions}
Beispiel #5
0
 def _CreateCache(self, _, features_json):
     extra_path_futures = [
         self._file_system.ReadSingle(path) for path in self._extra_paths
     ]
     features = features_utility.Parse(Parse(features_json))
     for path_future in extra_path_futures:
         extra_json = path_future.Get()
         features = features_utility.MergedWith(
             features_utility.Parse(Parse(extra_json)), features)
     return features
  def _CreateManifestData(self, _, content):
    '''Take the contents of |_manifest_path| and create apps and extensions
    versions of a manifest example based on the contents of |_features_path|.
    '''
    def create_manifest_dict():
      manifest_dict = OrderedDict()
      for category in ('required', 'only_one', 'recommended', 'optional'):
        manifest_dict[category] = []
      return manifest_dict

    apps = create_manifest_dict()
    extensions = create_manifest_dict()

    manifest_json = Parse(content)
    features_json = Parse(self._file_system.ReadSingle(
        self._features_path))

    def add_property(feature, manifest_key, category):
      '''If |feature|, from features_json, has the correct extension_types, add
      |manifest_key| to either apps or extensions.
      '''
      added = False
      extension_types = feature['extension_types']
      if extension_types == 'all' or 'platform_app' in extension_types:
        apps[category].append(deepcopy(manifest_key))
        added = True
      if extension_types == 'all' or 'extension' in extension_types:
        extensions[category].append(deepcopy(manifest_key))
        added = True
      return added

    # Property types are: required, only_one, recommended, and optional.
    for category in manifest_json:
      for manifest_key in manifest_json[category]:
        # If a property is in manifest.json but not _manifest_features, this
        # will cause an error.
        feature = features_json[manifest_key['name']]
        if add_property(feature, manifest_key, category):
          del features_json[manifest_key['name']]

    # All of the properties left in features_json are assumed to be optional.
    for feature in features_json.keys():
      item = features_json[feature]
      # Handles instances where a features entry is a union with a whitelist.
      if isinstance(item, list):
        item = item[0]
      add_property(item, {'name': feature}, 'optional')

    apps['optional'].sort(key=itemgetter('name'))
    extensions['optional'].sort(key=itemgetter('name'))

    self._ApplyAppsTransformations(apps)
    self._ApplyExtensionsTransformations(extensions)

    return {'apps': apps, 'extensions': extensions}
Beispiel #7
0
 def _CreateCache(self, _, features_json):
   extra_path_futures = [self._text_cache.GetFromFile(path)
                         for path in self._extra_paths]
   features = features_utility.Parse(Parse(features_json))
   for path_future in extra_path_futures:
     try:
       extra_json = path_future.Get()
     except FileNotFoundError:
       # Not all file system configurations have the extra files.
       continue
     features = features_utility.MergedWith(
         features_utility.Parse(Parse(extra_json)), features)
   return features
    def testCron(self):
        self._redirector.Cron()

        expected_paths = set([
            'public/redirects.json', 'public/apps/redirects.json',
            'public/extensions/redirects.json',
            'public/extensions/manifest/redirects.json'
        ])

        for path in expected_paths:
            self.assertEqual(
                Parse(file_system.ReadSingle(path)),
                # Access the cache's object store to see what files were hit during
                # the cron run. Returns strings parsed as JSON.
                self._redirector._cache._file_object_store.Get(
                    path).Get()._cache_data)
    def testRefresh(self):
        self._redirector.Refresh().Get()

        expected_paths = set([
            'redirects.json', 'apps/redirects.json',
            'extensions/redirects.json', 'extensions/manifest/redirects.json'
        ])

        for path in expected_paths:
            self.assertEqual(
                Parse(file_system.ReadSingle(path).Get()),
                # Access the cache's object store to see what files were hit during
                # the cron run. Returns strings parsed as JSON.
                # TODO(jshumway): Make a non hack version of this check.
                self._redirector._cache._file_object_store.Get(
                    path).Get().cache_data)
 def _CreateSidenavDict(self, _, content):
     items = Parse(content)
     # Start at level 2, the top <ul> element is level 1.
     _AddLevels(items, level=2)
     self._QualifyHrefs(items)
     return items
Beispiel #11
0
 def __init__(self, compiled_fs_factory, file_system, root_path):
     self._root_path = root_path
     self._file_system = file_system
     self._cache = compiled_fs_factory.Create(lambda _, rules: Parse(rules),
                                              Redirector)