def _get_dirindex(path_dirindex_conf, path_rootfs): paths = dirindex.read_paths(file(path_dirindex_conf)) paths = [ re.sub(r'^(-?)', '\\1' + path_rootfs, path) for path in paths ] tmp = TempFile() dirindex.create(tmp.path, paths) filtered = [ re.sub(r'^' + path_rootfs, '', line) for line in file(tmp.path).readlines() ] return "".join(filtered)
def _write_whatchanged(dest, dest_olist, dirindex, dirindex_conf, overrides=[]): paths = read_paths(file(dirindex_conf)) paths += overrides changes = whatchanged(dirindex, paths) changes.sort(lambda a,b: cmp(a.path, b.path)) olist = [ change.path for change in changes if change.OP == 'o' ] changes.tofile(dest) file(dest_olist, "w").writelines((path + "\n" for path in olist))
def _get_dirindex(path_dirindex_conf, path_rootfs): paths = dirindex.read_paths(file(path_dirindex_conf)) paths = [re.sub(r'^(-?)', '\\1' + path_rootfs, path) for path in paths] tmp = TempFile() dirindex.create(tmp.path, paths) filtered = [ re.sub(r'^' + path_rootfs, '', line) for line in file(tmp.path).readlines() ] return "".join(filtered)
def _write_whatchanged(self, dest, dest_olist, dirindex, dirindex_conf, overrides=[]): paths = read_paths(file(dirindex_conf)) paths += overrides changes = whatchanged(dirindex, paths) changes.sort(lambda a, b: cmp(a.path, b.path)) changes.tofile(dest) olist = [change.path for change in changes if change.OP == 'o'] file(dest_olist, "w").writelines((path + "\n" for path in olist)) if self.verbose: if changes: self._log("Save list of filesystem changes to %s:\n" % dest) actions = list(changes.deleted(optimized=False)) + list( changes.statfixes(optimized=False)) actions.sort(lambda a, b: cmp(a.args[0], b.args[0])) umask = os.umask(0) os.umask(umask) for action in actions: if action.func is os.chmod: path, mode = action.args default_mode = (0777 if isdir(path) else 0666) ^ umask if default_mode == stat.S_IMODE(mode): continue elif action.func is os.lchown: path, uid, gid = action.args if uid == 0 and gid == 0: continue self._log(" " + str(action)) if olist: self._log("\nSave list of new files to %s:\n" % dest_olist) for path in olist: self._log(" " + path)
def _write_whatchanged(self, dest, dest_olist, dirindex, dirindex_conf, overrides=[]): paths = read_paths(file(dirindex_conf)) paths += overrides changes = whatchanged(dirindex, paths) changes.sort(lambda a,b: cmp(a.path, b.path)) changes.tofile(dest) olist = [ change.path for change in changes if change.OP == 'o' ] file(dest_olist, "w").writelines((path + "\n" for path in olist)) if self.verbose: if changes: self._log("Save list of filesystem changes to %s:\n" % dest) actions = list(changes.deleted(optimized=False)) + list(changes.statfixes(optimized=False)) actions.sort(lambda a,b: cmp(a.args[0], b.args[0])) umask = os.umask(0) os.umask(umask) for action in actions: if action.func is os.chmod: path, mode = action.args default_mode = (0777 if isdir(path) else 0666) ^ umask if default_mode == stat.S_IMODE(mode): continue elif action.func is os.lchown: path, uid, gid = action.args if uid == 0 and gid == 0: continue self._log(" " + str(action)) if olist: self._log("\nSave list of new files to %s:\n" % dest_olist) for path in olist: self._log(" " + path)
for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt in ('-c', '--create'): opt_create = True elif opt in ('-i', '--input'): opt_input = val if not args or (not opt_input and len(args) < 2): usage() path_index = args[0] paths = args[1:] if opt_input: fh = file(opt_input) if opt_input != '-' else sys.stdin paths = dirindex.read_paths(fh) + paths if opt_create: dirindex.create(path_index, paths) return for change in changes.whatchanged(path_index, paths): print change if __name__ == "__main__": main()
for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt in ('-c', '--create'): opt_create = True elif opt in ('-i', '--input'): opt_input = val if not args or (not opt_input and len(args) < 2): usage() path_index = args[0] paths = args[1:] if opt_input: fh = file(opt_input) if opt_input != '-' else sys.stdin paths = dirindex.read_paths(fh) + paths if opt_create: dirindex.create(path_index, paths) return for change in changes.whatchanged(path_index, paths): print change if __name__=="__main__": main()