def _GetFeatureData(self, path): # Remove 'experimental_' from path name to match the keys in # _permissions_features.json. path = model.UnixName(path.replace('experimental_', '')) for filename in [ '_permission_features.json', '_manifest_features.json' ]: feature_data = self._GetFeatureFile(filename).get(path, None) if feature_data is not None: break # There are specific cases in which the feature is actually a list of # features where only one needs to match; but currently these are only # used to whitelist features for specific extension IDs. Filter those out. if isinstance(feature_data, list): feature_list = feature_data feature_data = None for single_feature in feature_list: if 'whitelist' in single_feature: continue if feature_data is not None: # Note: if you are seeing the exception below, add more heuristics as # required to form a single feature. raise ValueError( 'Multiple potential features match %s. I can\'t ' 'decide which one to use. Please help!' % path) feature_data = single_feature if feature_data and feature_data['channel'] in ('trunk', 'dev', 'beta'): feature_data[feature_data['channel']] = True return feature_data
def get(self, key, disable_refs=False): if key.endswith('.html') or key.endswith('.json') or key.endswith( '.idl'): path, ext = os.path.splitext(key) else: path = key unix_name = model.UnixName(path) idl_names = self._idl_names_cache.GetFromFileListing( self._base_path).Get() names = self._names_cache.GetFromFileListing(self._base_path).Get() if unix_name not in names and self._GetAsSubdirectory( unix_name) in names: unix_name = self._GetAsSubdirectory(unix_name) if disable_refs: cache, ext = ((self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else (self._json_cache_no_refs, '.json')) else: cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else (self._json_cache, '.json')) return self._GenerateHandlebarContext( cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)).Get())
def _GetFeatureFile(self, filename): try: perms = self._permissions_cache.GetFromFile( '%s/%s' % (self._base_path, filename)) return dict((model.UnixName(k), v) for k, v in perms.iteritems()) except FileNotFoundError: return {}
def _ExistsInFileSystem(api_name, file_system): '''Checks for existence of |api_name| within the list of files in the api/ directory found using the given file system. ''' file_names = file_system.GetFromFileListing(svn_constants.API_PATH) # File names switch from unix_hacker_style to camelCase at versions <= 20. return model.UnixName(api_name) in file_names or api_name in file_names
def _GetAPIsInSubdirectory(self, api_names, doc_type): public_templates = [] for root, _, files in self._file_system.Walk( self._public_path + doc_type): public_templates.extend( ('%s/%s' % (root, name)).lstrip('/') for name in files) template_names = set(os.path.splitext(name)[0] for name in public_templates) experimental_apis = [] chrome_apis = [] private_apis = [] for template_name in sorted(template_names): if model.UnixName(template_name) not in api_names: continue entry = {'name': template_name.replace('_', '.')} if template_name.startswith('experimental'): experimental_apis.append(entry) elif template_name.endswith('Private'): private_apis.append(entry) else: chrome_apis.append(entry) if len(chrome_apis): chrome_apis[-1]['last'] = True if len(experimental_apis): experimental_apis[-1]['last'] = True if len(private_apis): private_apis[-1]['last'] = True return { 'chrome': chrome_apis, 'experimental': experimental_apis, 'private': private_apis }
def get(self, key): path, ext = os.path.splitext(key) unix_name = model.UnixName(path) idl_names = self._idl_names_cache.GetFromFileListing(self._base_path) cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else (self._json_cache, '.json')) return self._GenerateHandlebarContext( cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), path)
def _GetFeature(self, path): # Remove 'experimental_' from path name to match the keys in # _permissions_features.json. path = model.UnixName(path.replace('experimental_', '')) for filename in ['_permission_features.json', '_manifest_features.json']: api_perms = self._GetPermsFromFile(filename).get(path, None) if api_perms is not None: break if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'): api_perms[api_perms['channel']] = True return api_perms
def get(self, key): path, ext = os.path.splitext(key) unix_name = model.UnixName(path) json_path = unix_name + '.json' idl_path = unix_name + '.idl' try: return self._json_cache.getFromFile(self._base_path + '/' + json_path) except: try: return self._idl_cache.getFromFile(self._base_path + '/' + idl_path) except: return None
def _GetAPIsInSubdirectory(self, api_names, doc_type): public_templates = self._identity_fs.GetFromFileListing( '%s%s/' % (self._public_path, doc_type)) template_names = set( os.path.splitext(name)[0] for name in public_templates) experimental_apis = [] chrome_apis = [] for template_name in sorted(template_names): if model.UnixName(template_name) not in api_names: continue entry = {'name': template_name.replace('_', '.')} if template_name.startswith('experimental'): experimental_apis.append(entry) else: chrome_apis.append(entry) if len(chrome_apis): chrome_apis[-1]['last'] = True if len(experimental_apis): experimental_apis[-1]['last'] = True return {'chrome': chrome_apis, 'experimental': experimental_apis}
def FilterSamples(self, key, api_name): """Fetches and filters the list of samples specified by |key|, returning only the samples that use the API |api_name|. |key| is either 'apps' or 'extensions'. """ api_search = '_' + api_name + '_' samples_list = [] try: for sample in self.get(key): api_calls_unix = [model.UnixName(call['name']) for call in sample['api_calls']] for call in api_calls_unix: if api_search in call: samples_list.append(sample) break except NotImplementedError: # If we're testing, the GithubFileSystem can't fetch samples. # Bug: http://crbug.com/141910 return [] return samples_list
def _GetAPIsInSubdirectory(self, api_names, doc_type): public_templates = self._file_system.ReadSingle(self._public_path + doc_type + '/') template_names = [ os.path.splitext(name)[0] for name in public_templates ] experimental_apis = [] chrome_apis = [] for template_name in sorted(template_names): if template_name in IGNORED_FILES: continue if model.UnixName(template_name) in api_names: if template_name.startswith('experimental'): experimental_apis.append( {'name': template_name.replace('_', '.')}) else: chrome_apis.append( {'name': template_name.replace('_', '.')}) if len(chrome_apis): chrome_apis[-1]['last'] = True if len(experimental_apis): experimental_apis[-1]['last'] = True return {'chrome': chrome_apis, 'experimental': experimental_apis}
def _GetAllNames(self, base_dir, apis): return [ model.UnixName( os.path.splitext(api[len('%s/' % self._base_path):])[0]) for api in apis ]
def _GetIDLNames(self, base_dir, apis): return [ model.UnixName( os.path.splitext(api[len('%s/' % self._base_path):])[0]) for api in apis if api.endswith('.idl') ]
def _GetExtNames(self, apis, exts): return [ model.UnixName(os.path.splitext(api)[0]) for api in apis if os.path.splitext(api)[1][1:] in exts ]
def _GetIDLNames(self, apis): return [model.UnixName(os.path.splitext(api.split('/')[-1])[0]) for api in apis if api.endswith('.idl')]
def _GetChannelFromManifestFeatures(api_name, file_system): return _GetChannelFromFeatures(#_manifest_features uses unix_style API names model.UnixName(api_name), file_system, _MANIFEST_FEATURES)