def main(argv): parser = ArgumentParser(description=__doc__) parser.add_argument('location', default=None, help='root directory (e.g. $D)') parser.add_argument('old', default=None, help='original build prefix (e.g. /)') parser.add_argument('new', default=None, help='new install prefix (e.g. $EPREFIX)') opts = parser.parse_args(argv) location, old, new = opts.location, opts.old, opts.new is_text_file = IsTextFile() if not isinstance(location, bytes): location = location.encode(FS_ENCODING) if not isinstance(old, bytes): old = old.encode(FS_ENCODING) if not isinstance(new, bytes): new = new.encode(FS_ENCODING) st = os.lstat(location) if stat.S_ISDIR(st.st_mode): for parent, dirs, files in os.walk(location): for filename in files: filename = os.path.join(parent, filename) try: st = os.lstat(filename) except OSError: pass else: if stat.S_ISREG(st.st_mode): chpath_inplace(filename, is_text_file(filename), old, new) elif stat.S_ISLNK(st.st_mode): chpath_inplace_symlink(filename, st, old, new) elif stat.S_ISREG(st.st_mode): chpath_inplace(location, is_text_file(location), old, new) elif stat.S_ISLNK(st.st_mode): chpath_inplace_symlink(location, st, old, new) return os.EX_OK
def main(argv): parser = ArgumentParser(description=doc) parser.add_argument('paths', nargs='*', default=[]) actions = parser.add_argument_group('Actions') actions.add_argument('--dump', action='store_true', help='Dump the values of all extended ' 'attributes associated with null-separated' ' paths read from stdin.') actions.add_argument('--restore', action='store_true', help='Restore extended attributes using' ' a dump read from stdin.') options = parser.parse_args(argv) if sys.hexversion >= 0x3000000: file_in = sys.stdin.buffer.raw else: file_in = sys.stdin if not options.paths: options.paths += [x for x in file_in.read().split(b'\0') if x] if options.dump: if sys.hexversion >= 0x3000000: file_out = sys.stdout.buffer else: file_out = sys.stdout dump_xattrs(options.paths, file_out) elif options.restore: restore_xattrs(file_in) else: parser.error('missing action!') return os.EX_OK
def main(argv): parser = ArgumentParser(description=__doc__) parser.add_argument('paths', nargs='*', default=[]) actions = parser.add_argument_group('Actions') actions.add_argument('--dump', action='store_true', help='Dump the values of all extended ' 'attributes associated with null-separated' ' paths read from stdin.') actions.add_argument('--restore', action='store_true', help='Restore extended attributes using' ' a dump read from stdin.') options = parser.parse_args(argv) if sys.hexversion >= 0x3000000: file_in = sys.stdin.buffer.raw else: file_in = sys.stdin if not options.paths: options.paths += [x for x in file_in.read().split(b'\0') if x] if options.dump: if sys.hexversion >= 0x3000000: file_out = sys.stdout.buffer else: file_out = sys.stdout dump_xattrs(options.paths, file_out) elif options.restore: restore_xattrs(file_in) else: parser.error('missing action!') return os.EX_OK
def main(argv): parser = ArgumentParser(description=__doc__) try: parser.add_argument('location', default=None, help='root directory (e.g. $D)') parser.add_argument('old', default=None, help='original build prefix (e.g. /)') parser.add_argument('new', default=None, help='new install prefix (e.g. $EPREFIX)') opts = parser.parse_args(argv) location, old, new = opts.location, opts.old, opts.new except OptionError: # Argument parsing compatibility for Python 2.6 using optparse. if sys.hexversion < 0x2070000: parser = OptionParser(description=__doc__, usage="usage: %prog [-h] location old new\n\n" + \ " location: root directory (e.g. $D)\n" + \ " old: original build prefix (e.g. /)\n" + \ " new: new install prefix (e.g. $EPREFIX)") (opts, args) = parser.parse_args() if len(args) != 3: parser.print_usage() print("%s: error: expected 3 arguments, got %i" % (__file__, len(args))) return location, old, new = args[0:3] else: raise is_text_file = IsTextFile() if not isinstance(location, bytes): location = location.encode(FS_ENCODING) if not isinstance(old, bytes): old = old.encode(FS_ENCODING) if not isinstance(new, bytes): new = new.encode(FS_ENCODING) st = os.lstat(location) if stat.S_ISDIR(st.st_mode): for parent, dirs, files in os.walk(location): for filename in files: filename = os.path.join(parent, filename) try: st = os.lstat(filename) except OSError: pass else: if stat.S_ISREG(st.st_mode): chpath_inplace(filename, is_text_file(filename), old, new) elif stat.S_ISLNK(st.st_mode): chpath_inplace_symlink(filename, st, old, new) elif stat.S_ISREG(st.st_mode): chpath_inplace(location, is_text_file(location), old, new) elif stat.S_ISLNK(st.st_mode): chpath_inplace_symlink(location, st, old, new) return os.EX_OK
def main(argv): parser = ArgumentParser(description=__doc__) try: parser.add_argument('location', default=None, help='root directory (e.g. $D)') parser.add_argument('old', default=None, help='original build prefix (e.g. /)') parser.add_argument('new', default=None, help='new install prefix (e.g. $EPREFIX)') opts = parser.parse_args(argv) location, old, new = opts.location, opts.old, opts.new except OptionError: # Argument parsing compatibility for Python 2.6 using optparse. if sys.hexversion < 0x2070000: parser = OptionParser(description=__doc__, usage="usage: %prog [-h] location old new\n\n" + \ " location: root directory (e.g. $D)\n" + \ " old: original build prefix (e.g. /)\n" + \ " new: new install prefix (e.g. $EPREFIX)") (opts, args) = parser.parse_args() if len(args) != 3: parser.print_usage() print("%s: error: expected 3 arguments, got %i" % (__file__, len(args))) return location, old, new = args[0:3] else: raise is_text_file = IsTextFile() if not isinstance(location, bytes): location = location.encode(FS_ENCODING) if not isinstance(old, bytes): old = old.encode(FS_ENCODING) if not isinstance(new, bytes): new = new.encode(FS_ENCODING) st = os.lstat(location) if stat.S_ISDIR(st.st_mode): for parent, dirs, files in os.walk(location): for filename in files: filename = os.path.join(parent, filename) try: st = os.lstat(filename) except OSError: pass else: if stat.S_ISREG(st.st_mode): chpath_inplace(filename, is_text_file(filename), old, new) elif stat.S_ISLNK(st.st_mode): chpath_inplace_symlink(filename, st, old, new) elif stat.S_ISREG(st.st_mode): chpath_inplace(location, is_text_file(location), old, new) elif stat.S_ISLNK(st.st_mode): chpath_inplace_symlink(location, st, old, new) return os.EX_OK