def Add(self, sources): '''Appends one or more source objects the list if it doesn't already exist. Args: sources: A SourceWithPath or an iterable of such objects. ''' if isinstance(sources, SourceWithPaths): sources = [sources] for source in sources: path = source.GetInPath() if path not in self._added_paths: self._added_paths.add(path) self._added_sources.append(source)
def _GetBase(sources): '''Gets the closure base.js file if present among the sources. Args: sources: Dictionary with input path names as keys and SourceWithPaths as values. Returns: SourceWithPath: The source file providing the goog namespace. ''' for source in sources.itervalues(): if (os.path.basename(source.GetInPath()) == 'base.js' and 'goog' in source.provides): return source Die('goog.base not provided by any file.')
def LinkOrCopyFiles(sources, dest_dir): '''Copies a list of sources to a destination directory.''' def LinkOrCopyOneFile(src, dst): if not os.path.exists(os.path.dirname(dst)): os.makedirs(os.path.dirname(dst)) if os.path.exists(dst): os.unlink(dst) try: os.link(src, dst) except: shutil.copy(src, dst) for source in sources: LinkOrCopyOneFile(source.GetInPath(), os.path.join(dest_dir, source.GetOutPath()))
def LinkOrCopyFiles(sources, dest_dir): '''Copies a list of sources to a destination directory.''' def LinkOrCopyOneFile(src, dst): try: os.makedirs(os.path.dirname(dst)) except OSError as err: if err.errno != errno.EEXIST: raise if os.path.exists(dst): os.unlink(dst) try: os.link(src, dst) except: shutil.copy(src, dst) for source in sources: LinkOrCopyOneFile(source.GetInPath(), os.path.join(dest_dir, source.GetOutPath()))
def LinkOrCopyFiles(sources, dest_dir): '''Copies a list of sources to a destination directory.''' def LinkOrCopyOneFile(src, dst): if not os.path.exists(os.path.dirname(dst)): os.makedirs(os.path.dirname(dst)) if os.path.exists(dst): # Avoid clobbering the inode if source and destination refer to the # same file already. if os.path.samefile(src, dst): return os.unlink(dst) try: os.link(src, dst) except: shutil.copy(src, dst) for source in sources: LinkOrCopyOneFile(source.GetInPath(), os.path.join(dest_dir, source.GetOutPath()))
def GetInPaths(self): return (source.GetInPath() for source in self._added_sources)
def GetBase(sources): for source in sources.itervalues(): if (os.path.basename(source.GetInPath()) == 'base.js' and 'goog' in source.provides): return source Die('goog.base not provided by any file')