def walk(self, parents, full_path, rel_path, dirs, files, skipFile=__MANIFEST__): """recursive walk through directory tree""" # first do files here for f in files: if f != skipFile: path = os.path.join(full_path, f) self.files.append( FE(f, rel_path, parents[-1], self.hashfile(path), os.path.getsize(path))) for d in dirs: # the walk will go into these dirs first tmp_fe = FE(d, rel_path, parents[-1], "-", 0) self.files.append(tmp_fe) parents.append(tmp_fe) new_full_path = os.path.join(full_path, d) new_rel_path = os.path.join(rel_path, d) new_dirs, new_files = self.listdir(new_full_path)[:2] self.walk(parents, new_full_path, new_rel_path, new_dirs, new_files) parents.pop()
def createManifest(self, path, manifestName=None): """inventory all files in path and create a manifest file""" if manifestName is None: manifestName = __MANIFEST__ # make the root file entity root_path = os.path.abspath(path) root_fe = FE('root', ".", None, "-", 0) self.files.append(root_fe) # now make all the ones below parents = [root_fe] dirs, files = self.listdir(path)[:2] self.walk(parents, root_path, '', dirs, files, skipFile=manifestName) with open(os.path.join(path, manifestName), 'w') as man_fh: # print the header man_fh.write("##%s##\tData manifest created by ScreamingBackpack version %s\n" % (self.type, __version__)) for f in self.files: if f.parent is not None: man_fh.write("%s\n" % f)