def FindResourceGivenRelativePath(self, relative_path, binary=False): """Returns a Resource for the given relative path.""" absolute_path = None for script_path in self.source_paths: absolute_path = os.path.join(script_path, relative_path) if os.path.exists(absolute_path): return resource_module.Resource(script_path, absolute_path, binary) return None
def FindResourceGivenAbsolutePath(self, absolute_path, binary=False): """Returns a Resource for the given absolute path.""" candidate_paths = [] for source_path in self.source_paths: if absolute_path.startswith(source_path): candidate_paths.append(source_path) if len(candidate_paths) == 0: return None # Sort by length. Longest match wins. candidate_paths.sort(key=(lambda x: len(x))) longest_candidate = candidate_paths[-1] return resource_module.Resource(longest_candidate, absolute_path, binary)
def LoadRawScript(self, relative_raw_script_path): resource = None for source_path in self.source_paths: possible_absolute_path = os.path.join( source_path, os.path.normpath(relative_raw_script_path)) if os.path.exists(possible_absolute_path): resource = resource_module.Resource(source_path, possible_absolute_path) break if not resource: raise module.DepsException( 'Could not find a file for raw script %s in %s' % (relative_raw_script_path, self.source_paths)) assert relative_raw_script_path == resource.unix_style_relative_path, ( 'Expected %s == %s' % (relative_raw_script_path, resource.unix_style_relative_path)) if resource.absolute_path in self.loaded_raw_scripts: return self.loaded_raw_scripts[resource.absolute_path] raw_script = module.RawScript(resource) self.loaded_raw_scripts[resource.absolute_path] = raw_script return raw_script
def testBasic(self): r = resource.Resource('/a', '/a/b/c.js') self.assertEquals('b.c', r.name) self.assertEquals(os.path.join('b', 'c.js'), r.relative_path) self.assertEquals('b/c.js', r.unix_style_relative_path)