Create a tar file containing all the source_files

    Args:
        source_files (List[str]): List of file paths that will be contained in the tar file

    Returns:
         (str): path to created tar file
13545
def create_tar_file(source_files, target=None):
    
    if target:
        filename = target
    else:
        _, filename = tempfile.mkstemp()

    with tarfile.open(filename, mode='w:gz') as t:
        for sf in source_files:
            # Add all files from the directory into the root of the directory structure of the tar
            t.add(sf, arcname=os.path.basename(sf))
    return filename
484854
def get_file_list(self, lstPaths, lstXtn, lstExcluded, VERBOSE = False):
        
        if VERBOSE:
            print("Generating list of Files...")
            print("Paths = ", lstPaths)
            print("Xtns  = ", lstXtn)
            print("exclude = ", lstExcluded)
        numFiles = 0
        self.filelist = []
        self.fl_metadata = []
        for rootPath in lstPaths:
            if VERBOSE:
                print(rootPath)
            for root, dirs, files in os.walk(rootPath):
                if VERBOSE:
                    print(dirs)
                for basename in files:
                    for xtn in lstXtn:
                        if fnmatch.fnmatch(basename, xtn):
                            filename = os.path.join(root, basename)
                            includeThisFile = "Y"
                            if len(lstExcluded) > 0:
                                for exclude in lstExcluded:
                                    if filename.find(exclude) != -1:
                                        includeThisFile = "N"
                            if includeThisFile == "Y":
                                numFiles = numFiles + 1
                                self.filelist.append(filename)
                                self.add_file_metadata(filename)    # not sure why there is a 2nd list, but there is.

        if VERBOSE:
            print("Found ", numFiles, " files")
        return self.filelist
1267622
def getSourcePaths(self, makeGlyphs=True, makeKerning=True, makeInfo=True):
        
        paths = []
        for name in self.sources.keys():
            paths.append(self.sources[name][0].path)
        return paths
872445
def _files_in_layers(self, layers, directory):
        
        files = {}

        for layer in layers:
            self.log.debug("Generating list of files in layer '%s'..." % layer)
            tar_file = os.path.join(directory, layer, "layer.tar")
            with tarfile.open(tar_file, 'r', format=tarfile.PAX_FORMAT) as tar:
                files[layer] = [self._normalize_path(
                    x) for x in tar.getnames()]
            self.log.debug("Done, found %s files" % len(files[layer]))

        return files
316316
def create_tar (archive, compression, cmd, verbosity, interactive, filenames):
    """"""
    cmdlist = [cmd, '--create']
    add_tar_opts(cmdlist, compression, verbosity)
    cmdlist.extend(["--file", archive, '--'])
    cmdlist.extend(filenames)
    return cmdlist
355375
def write_source_patches
      from_directory do
        id = @git.latest_id("tetra: sources-tarball")
        destination_path = File.join(full_path, packages_dir, name)
        @git.format_patch("src", id, destination_path)
      end
    end
173911
def _context_source_file_url(path_or_url):
    
    if path_or_url.startswith('http'):
        # Remote CSV. Just return the URL
        return path_or_url

    if path_or_url.startswith('/'):
        # Absolute path
        return "file://" + path_or_url

    return "file://" + os.path.join(os.path.realpath(os.getcwd()), path_or_url)
677795
def build_from_c_and_cpp_files(extensions):
    
    for extension in extensions:
        sources = []
        for sfile in extension.sources:
            path, ext = os.path.splitext(sfile)
            if ext in ('.pyx', '.py'):
                if extension.language == 'c++':
                    ext = '.cpp'
                else:
                    ext = '.c'
                sfile = path + ext
            sources.append(sfile)
        extension.sources = sources
1081366
def source_lines(self, filename):
        
        with self.filesystem.open(filename) as f:
            return f.readlines()
118595
def create_tar_archive(self):
        
        #file filter
        EXCLUDE_FILES = glob.glob(os.path.join(self.savefolder, 'cells'))
        EXCLUDE_FILES += glob.glob(os.path.join(self.savefolder,
                                                'populations', 'subsamples'))
        EXCLUDE_FILES += glob.glob(os.path.join(self.savefolder,
                                                'raw_nest_output'))

        def filter_function(tarinfo):
            print(tarinfo.name)
            if len([f for f in EXCLUDE_FILES if os.path.split(tarinfo.name)[-1]
                    in os.path.split(f)[-1]]) > 0 or \
               len([f for f in EXCLUDE_FILES if os.path.split(tarinfo.path)[-1]
                    in os.path.split(f)[-1]]) > 0:
                print('excluding %s' % tarinfo.name)

                return None
            else:
                return tarinfo

        if RANK == 0:
            print('creating archive %s' % (self.savefolder + '.tar'))
            #open file
            f = tarfile.open(self.savefolder + '.tar', 'w')
            #avoid adding files to repo as /scratch/$USER/hybrid_model/...
            arcname = os.path.split(self.savefolder)[-1]

            f.add(name=self.savefolder,
                  arcname=arcname,
                  filter=filter_function)
            f.close()

        #resync
        COMM.Barrier()
1336975
def make_files(self):
        

        # get the files from the template
        files = []
        try:
            files = self.files()
        except AttributeError:
            self.term.print_info(u"No file in the template. Weird, but why not?")

        # get the substitutes intersecting the template and the cli
        try:
            for key in self.substitutes().keys():
                if key not in self.substitutes_dict:
                    self.substitutes_dict[key] = self.substitutes()[key]

        except AttributeError:
            self.term.print_info(u"No substitute in the template.")

        working_dir = os.getcwd()
        # iteratively create the files
        for directory, name, template_file in files:
            if directory:
                filepath = working_dir + '/' + directory + '/' + name
                filename = directory + '/' + name
            else:
                filepath = working_dir + '/' + name
                filename = name

            # open the file to write into
            try:
                output = open(filepath, 'w')
            except IOError:
                self.term.print_error_and_exit(u"Can't create destination"\
                                                " file: {0}".format(filepath))

            # open the template to read from
            if template_file:
                input_file = join(dirname(__file__), template_file + '.txt')

                # write each line of input file into output file,
                # templatized with substitutes
                try:
                    with open(input_file, 'r') as line:
                        template_line = Template(line.read())
                        try:
                            output.write(template_line.
                                safe_substitute(self.substitutes_dict).encode('utf-8'))
                        except TypeError:
                            output.write(template_line.
                                safe_substitute(self.substitutes_dict))
                    output.close()
                except IOError:
                    self.term.print_error_and_exit(u"Can't create template file"\
                                                   ": {0}".format(input_file))
            else:
                output.close() # the file is empty, but still created

            self.term.print_info(u"Creating file '{0}'"
                             .format(self.term.text_in_color(filename, TERM_YELLOW)))
390095
def _iter_full_paths(path_list):
    
    for path in path_list:
        if not os.path.isdir(path):
            full_path = os.path.realpath(path)
            yield path
        else:
            for root, dirs, filenames in os.walk(path):
                for filename in filenames:
                    full_path = os.path.realpath(os.path.join(root, filename))
                    yield full_path
272776
def pysourcefiles(self):
        """"""
        sourcefiles = set()
        for (name, child) in vars(self).items():
            try:
                parents = inspect.getmro(child)
            except AttributeError:
                continue
            for parent in parents:
                try:
                    sourcefile = inspect.getfile(parent)
                except TypeError:
                    break
                sourcefiles.add(sourcefile)
        return Lines(*sourcefiles)
317461
def from_sources_field(sources, spec_path):
    
    if sources is None:
      return Files(spec_path=spec_path)
    elif isinstance(sources, BaseGlobs):
      return sources
    elif isinstance(sources, string_types):
      return Files(sources, spec_path=spec_path)
    elif isinstance(sources, (MutableSet, MutableSequence, tuple)) and \
         all(isinstance(s, string_types) for s in sources):
      return Files(*sources, spec_path=spec_path)
    else:
      raise ValueError('Expected either a glob or list of literal sources: got: {}'.format(sources))
430216
def find_source_files_from_list(self, file_names):
        
        for file_name in file_names:
            if os.path.exists(file_name):
                routine_name = os.path.splitext(os.path.basename(file_name))[0]
                if routine_name not in self._source_file_names:
                    self._source_file_names[routine_name] = file_name
                else:
                    self._io.error("Files '{0}' and '{1}' have the same basename.".
                                   format(self._source_file_names[routine_name], file_name))
                    self.error_file_names.add(file_name)
            else:
                self._io.error("File not exists: '{0}'".format(file_name))
                self.error_file_names.add(file_name)
1301947
def build_sourcemap(sources):
    
    sourcemap = {}
    for sfile in sources:
        inc = find_includes(sfile)
        sourcemap[sfile] = set(inc)
    return sourcemap
1048123
def _to_tarfile(self, file_generator):
        
        if file_generator.to_path_compression == "tar":
            tar_mode = "w"
        elif file_generator.to_path_compression == "tar.gz":
            tar_mode = "w:gz"
        elif file_generator.to_path_compression == 'tar.bz2':
            tar_mode = "w:bz2"
        else:
            tar_mode = "w"

        with tarfile.open(file_generator.to_path, mode=tar_mode) as outfile:
            for f in file_generator:
                outpath = self._output_path(f.source, file_generator.to_format, archive=True)
                info = tarfile.TarInfo(outpath)
                data = f.writestr(file_generator.to_format).encode()
                info.size = len(data)
                outfile.addfile(tarinfo=info, fileobj=io.BytesIO(data))