Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/shasum.py @ 105:b0631f320efd
Implement "--follow-symlinks" to allow to control whether to follow directory symlinks
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 29 May 2022 01:06:25 +0200 |
| parents | 08fd0609fdd4 |
| children | 5fe6f63f0be7 |
comparison
equal
deleted
inserted
replaced
| 104:08fd0609fdd4 | 105:b0631f320efd |
|---|---|
| 84 "--checklist-allow-distinfo", action="store_true", | 84 "--checklist-allow-distinfo", action="store_true", |
| 85 dest="allow_distinfo", | 85 dest="allow_distinfo", |
| 86 help='Allow FreeBSD "distinfo" formatted checklists: ignore SIZE and TIMESTAMP lines.') | 86 help='Allow FreeBSD "distinfo" formatted checklists: ignore SIZE and TIMESTAMP lines.') |
| 87 | 87 |
| 88 aparser.add_argument( | 88 aparser.add_argument( |
| 89 "--follow-symlinks", action="store_true", dest="follow_symlinks", | |
| 90 help="""Also follow symlinks that resolve to directories. Only effective if `--recurse` is activated.""") | |
| 91 | |
| 92 aparser.add_argument( | |
| 89 "--mmap", action="store_true", dest="mmap", default=None, | 93 "--mmap", action="store_true", dest="mmap", default=None, |
| 90 help="""Use mmap if available. Default is to determine automatically | 94 help="""Use mmap if available. Default is to determine automatically |
| 91 from the filesize.""") | 95 from the filesize.""") |
| 92 aparser.add_argument( | 96 aparser.add_argument( |
| 93 "--no-mmap", action="store_false", dest="mmap", default=None, | 97 "--no-mmap", action="store_false", dest="mmap", default=None, |
| 94 help="Dont use mmap.") | 98 help="Dont use mmap.") |
| 95 | 99 |
| 96 aparser.add_argument( | 100 aparser.add_argument( |
| 97 "--recurse", action="store_true", | 101 "--recurse", action="store_true", |
| 98 help="Recurse into sub-directories while interpreting every FILE as a directory") | 102 help="Recurse into sub-directories while interpreting every FILE as a directory.") |
| 99 | 103 |
| 100 aparser.add_argument( | 104 aparser.add_argument( |
| 101 "--reverse", "-r", action="store_false", dest="bsd", default=False, | 105 "--reverse", "-r", action="store_false", dest="bsd", default=False, |
| 102 help="Explicitely select normal coreutils style output (to be option compatible with BSD style commands and :command:`openssl dgst -r`)") | 106 help="Explicitely select normal coreutils style output (to be option compatible with BSD style commands and :command:`openssl dgst -r`)") |
| 103 aparser.add_argument( | 107 aparser.add_argument( |
| 172 if not os.path.isdir(dn): | 176 if not os.path.isdir(dn): |
| 173 if os.path.exists(dn): | 177 if os.path.exists(dn): |
| 174 raise OSError(errno.ENOTDIR, "not a directory", dn) | 178 raise OSError(errno.ENOTDIR, "not a directory", dn) |
| 175 else: | 179 else: |
| 176 raise OSError(errno.ENOENT, "directory does not exist", dn) | 180 raise OSError(errno.ENOENT, "directory does not exist", dn) |
| 177 for dirpath, dirnames, dirfiles in os.walk(dn, followlinks=True): | 181 for dirpath, dirnames, dirfiles in os.walk( |
| 182 dn, followlinks=opts.follow_symlinks): | |
| 178 for fn in dirfiles: | 183 for fn in dirfiles: |
| 179 path = os.path.join(dirpath, fn) | 184 path = os.path.join(dirpath, fn) |
| 180 out(opts.dest or sys.stdout, | 185 out(opts.dest or sys.stdout, |
| 181 compute_digest_file(opts.algorithm[0], path, | 186 compute_digest_file(opts.algorithm[0], path, |
| 182 use_mmap=opts.mmap), | 187 use_mmap=opts.mmap), |
