def test_iterscan(self): path = os.path.join(self.dir, "iscan") os.mkdir(path) files = [ os.path.normpath(os.path.join(path, x)) for x in ["tmp", "blah", "dar"] ] # cheap version of a touch. map(lambda x: open(x, "w").close(), files) dirs = [ os.path.normpath(os.path.join(path, x)) for x in ["a", "b", "c"] ] map(os.mkdir, dirs) dirs.append(path) for obj in livefs.iter_scan(path): self.assertInstance(obj, fs.fsBase) if fs.isreg(obj): self.assertTrue(obj.location in files) elif fs.isdir(obj): self.assertTrue(obj.location in dirs) else: raise Exception( "unknown object popped up in testing dir, '%s'" % obj) self.check_attrs(obj, obj.location) # do offset verification now. offset = os.path.join(self.dir, "iscan") for obj in livefs.iter_scan(path, offset=offset): self.check_attrs(obj, obj.location, offset=offset) seen = [] for obj in livefs.iter_scan(files[0]): self.check_attrs(obj, obj.location) seen.append(obj.location) self.assertEqual((files[0], ), tuple(sorted(seen)))
def test_iterscan(self): path = os.path.join(self.dir, "iscan") os.mkdir(path) files = [os.path.normpath(os.path.join(path, x)) for x in [ "tmp", "blah", "dar"]] # cheap version of a touch. map(lambda x:open(x, "w").close(), files) dirs = [os.path.normpath(os.path.join(path, x)) for x in [ "a", "b", "c"]] map(os.mkdir, dirs) dirs.append(path) for obj in livefs.iter_scan(path): self.assertInstance(obj, fs.fsBase) if fs.isreg(obj): self.assertTrue(obj.location in files) elif fs.isdir(obj): self.assertTrue(obj.location in dirs) else: raise Exception( "unknown object popped up in testing dir, '%s'" % obj) self.check_attrs(obj, obj.location) # do offset verification now. offset = os.path.join(self.dir, "iscan") for obj in livefs.iter_scan(path, offset=offset): self.check_attrs(obj, obj.location, offset=offset) seen = [] for obj in livefs.iter_scan(files[0]): self.check_attrs(obj, obj.location) seen.append(obj.location) self.assertEqual((files[0],), tuple(sorted(seen)))
def fix_fsobject(location): from pkgcore.fs import livefs, fs for obj in livefs.iter_scan(location): if not fs.isreg(obj) or not obj.basename.endswith(".la"): continue updated, content = rewrite_lafile(open(obj.location, 'r')) if updated: open(obj.location, 'w').write(content)
def update(self, fetchables, chfs=None): """Update the related Manifest file. :param fetchables: fetchables of the package """ if self.thin and not fetchables: # thin doesn't require a manifest to be written # if there is no fetchables. return _key_sort = operator.itemgetter(0) excludes = frozenset(["CVS", ".svn", "Manifest"]) aux, ebuild, misc = {}, {}, {} if not self.thin: filesdir = '/files/' for obj in iter_scan('/', offset=dirname(self.path), chksum_types=chfs): if not obj.is_reg: continue pathname = obj.location if excludes.intersection(pathname.split('/')): continue if pathname.startswith(filesdir): d = aux pathname = pathname[len(filesdir):] elif obj.dirname == '/': pathname = pathname[1:] if obj.location[-7:] == '.ebuild': d = ebuild else: d = misc else: raise Exception("Unexpected directory found in %r; %r" % (self.path, obj.dirname)) d[pathname] = dict(obj.chksums) handle = open(self.path, 'w') # write it in alphabetical order; aux gets flushed now. for path, chksums in sorted(aux.iteritems(), key=_key_sort): _write_manifest(handle, 'AUX', path, chksums) # next dist... for fetchable in sorted(fetchables, key=operator.attrgetter('filename')): _write_manifest(handle, 'DIST', basename(fetchable.filename), dict(fetchable.chksums)) # then ebuild and misc for mtype, inst in (("EBUILD", ebuild), ("MISC", misc)): for path, chksum in sorted(inst.iteritems(), key=_key_sort): _write_manifest(handle, mtype, path, chksum)
def fix_fsobject(location): from pkgcore.fs import livefs, fs for obj in livefs.iter_scan(location): if not fs.isreg(obj) or not obj.basename.endswith(".la"): continue with open(obj.location, 'r') as f: updated, content = rewrite_lafile(f, obj.basename) if updated: with open(obj.location, 'w') as f: f.write(content)
def serialize_manifest(pkgdir, fetchables, chfs=None, thin=False): """ Write a manifest given a pkg_instance :param pkgdir: the location of the package dir :param fetchables: the fetchables of the package """ if thin and not fetchables: # thin doesn't require a manifest to be written # if there is no fetchables. return _key_sort = operator.itemgetter(0) excludes = frozenset(["CVS", ".svn", "Manifest"]) aux, ebuild, misc = {}, {}, {} if not thin: filesdir = '/files/' for obj in iter_scan('/', offset=pkgdir, chksum_types=chfs): if not obj.is_reg: continue pathname = obj.location if excludes.intersection(pathname.split('/')): continue if pathname.startswith(filesdir): d = aux pathname = pathname[len(filesdir):] elif obj.dirname == '/': pathname = pathname[1:] if obj.location[-7:] == '.ebuild': d = ebuild else: d = misc else: raise Exception("Unexpected directory found in %r; %r" % (pkgdir, obj.dirname)) d[pathname] = dict(obj.chksums) handle = open(pkgdir + '/Manifest', 'w') # write it in alphabetical order; aux gets flushed now. for path, chksums in sorted(aux.iteritems(), key=_key_sort): _write_manifest(handle, 'AUX', path, chksums) # next dist... for fetchable in sorted(fetchables, key=operator.attrgetter('filename')): _write_manifest(handle, 'DIST', basename(fetchable.filename), dict(fetchable.chksums)) # then ebuild and misc for mtype, inst in (("EBUILD", ebuild), ("MISC", misc)): for path, chksum in sorted(inst.iteritems(), key=_key_sort): _write_manifest(handle, mtype, path, chksum)
def _read_config_file(path): """Read all the data files under a given path.""" try: for fs_obj in iter_scan(path, follow_symlinks=True): if not fs_obj.is_reg or '/.' in fs_obj.location: continue for lineno, line in iter_read_bash( fs_obj.location, allow_line_cont=True, enum_line=True): yield line, lineno, fs_obj.location except FileNotFoundError: pass except EnvironmentError as e: raise Failure(f"failed reading {filename!r}: {e}") from e