Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 219:19eaba51c632
Refactored the printing of FLAGS: print flags always and explicitely print symlink behaviour and encoding configuration
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 25 Jan 2025 13:49:12 +0100 |
| parents | dee891ed2307 |
| children | 8db78850d800 |
comparison
equal
deleted
inserted
replaced
| 218:dee891ed2307 | 219:19eaba51c632 |
|---|---|
| 513 flags.append("with-metadata-fullmode") | 513 flags.append("with-metadata-fullmode") |
| 514 elif self._with_metadata_mode: | 514 elif self._with_metadata_mode: |
| 515 flags.append("with-metadata-mode") | 515 flags.append("with-metadata-mode") |
| 516 if self._with_metadata_mtime: | 516 if self._with_metadata_mtime: |
| 517 flags.append("with-metadata-mtime") | 517 flags.append("with-metadata-mtime") |
| 518 if self._follow_symlinks.command_line: | 518 flags.append("follow-symlinks-commandline" |
| 519 flags.append("follow-symlinks-commandline") | 519 if self._follow_symlinks.command_line |
| 520 if self._follow_symlinks.directory: | 520 else "no-follow-symlinks-commandline") |
| 521 flags.append("follow-symlinks-directory") | 521 flags.append("follow-symlinks-directory" |
| 522 if self._follow_symlinks.file: | 522 if self._follow_symlinks.directory |
| 523 flags.append("follow-symlinks-file") | 523 else "no-follow-symlinks-directory") |
| 524 flags.append("follow-symlinks-file" | |
| 525 if self._follow_symlinks.file | |
| 526 else "no-follow-symlinks-file") | |
| 524 if self._size_only: | 527 if self._size_only: |
| 525 flags.append("size-only") | 528 flags.append("size-only") |
| 526 if self._utf8_mode: | 529 flags.append("utf8-encoding" if self._utf8_mode else "fs-encoding") |
| 527 flags.append("utf8-mode") | |
| 528 if self._print_size: | 530 if self._print_size: |
| 529 flags.append("print-size") | 531 flags.append("print-size") |
| 530 if flags: | 532 flags.sort() |
| 531 flags.sort() | 533 self._outfp.write( |
| 532 self._outfp.write( | 534 format_bsd_line("FLAGS", ",".join(flags), None, False)) |
| 533 format_bsd_line("FLAGS", ",".join(flags), None, False)) | |
| 534 | 535 |
| 535 if self._minimal is None: | 536 if self._minimal is None: |
| 536 # Write execution timestamps in POSIX epoch and ISO format | 537 # Write execution timestamps in POSIX epoch and ISO format |
| 537 ts = int(time.time()) | 538 ts = int(time.time()) |
| 538 self._outfp.write(format_bsd_line("TIMESTAMP", ts, None, False)) | 539 self._outfp.write(format_bsd_line("TIMESTAMP", ts, None, False)) |
| 863 if self._size_only: | 864 if self._size_only: |
| 864 self._outfp.write(format_bsd_line( | 865 self._outfp.write(format_bsd_line( |
| 865 "SIZE", None, opath, False, dir_size)) | 866 "SIZE", None, opath, False, dir_size)) |
| 866 else: | 867 else: |
| 867 if dir_tainted: | 868 if dir_tainted: |
| 869 # | |
| 870 # IMPORTANT: Print errors BEFORE the associated digest line. | |
| 871 # Otherwise the "info" command has a problem. | |
| 872 # | |
| 868 self._outfp.write(format_bsd_line( | 873 self._outfp.write(format_bsd_line( |
| 869 b"ERROR", None, b"directory is tainted", False, None)) | 874 b"ERROR", None, b"directory is tainted", False, None)) |
| 870 logging.error("Directory has filename problems: %r", opath) | 875 logging.error("Directory has filename problems: %r", opath) |
| 871 if self._print_size: | 876 if self._print_size: |
| 872 self._outfp.write(format_bsd_line( | 877 self._outfp.write(format_bsd_line( |
| 1238 reader = TreesumReader.from_path(fn) | 1243 reader = TreesumReader.from_path(fn) |
| 1239 | 1244 |
| 1240 with reader: | 1245 with reader: |
| 1241 root = generator = flags = fsencoding = algorithm = digest \ | 1246 root = generator = flags = fsencoding = algorithm = digest \ |
| 1242 = size = None | 1247 = size = None |
| 1248 errors = set() | |
| 1243 comments = [] | 1249 comments = [] |
| 1244 in_block = False | 1250 in_block = False |
| 1245 block_no = 0 | 1251 block_no = 0 |
| 1246 for record in reader: | 1252 for record in reader: |
| 1247 if record[0] == "VERSION": | 1253 if record[0] == "VERSION": |
| 1259 flags = record[1] | 1265 flags = record[1] |
| 1260 elif record[0] == "ROOT": | 1266 elif record[0] == "ROOT": |
| 1261 root = record[1] | 1267 root = record[1] |
| 1262 elif record[0] == "COMMENT": | 1268 elif record[0] == "COMMENT": |
| 1263 comments.append(record[1]) | 1269 comments.append(record[1]) |
| 1270 elif record[0] == "ERROR": | |
| 1271 errors.add(record[1]) | |
| 1264 elif record[0] in ("TIMESTAMP", "ISOTIMESTAMP"): | 1272 elif record[0] in ("TIMESTAMP", "ISOTIMESTAMP"): |
| 1265 pass | 1273 pass |
| 1266 elif record[0] == "CRC32": | 1274 elif record[0] == "CRC32": |
| 1267 pass | 1275 pass |
| 1268 # in_block = False | 1276 # in_block = False |
| 1281 size = record[3] | 1289 size = record[3] |
| 1282 if not print_only_last_block: | 1290 if not print_only_last_block: |
| 1283 print_block_data( | 1291 print_block_data( |
| 1284 block_no, | 1292 block_no, |
| 1285 root, generator, fsencoding, flags, comments, | 1293 root, generator, fsencoding, flags, comments, |
| 1286 algorithm, digest, size) | 1294 errors, algorithm, digest, size) |
| 1287 root = flags = algorithm = digest = size = None | 1295 root = generator = flags = fsencoding = algorithm \ |
| 1296 = digest = size = None | |
| 1297 errors = set() | |
| 1298 comments = [] | |
| 1288 in_block = False | 1299 in_block = False |
| 1289 if print_only_last_block: | 1300 if print_only_last_block: |
| 1290 if not in_block: | 1301 if not in_block: |
| 1291 if digest is not None or size is not None: | 1302 if digest is not None or size is not None: |
| 1292 print_block_data( | 1303 print_block_data( |
| 1293 block_no, | 1304 block_no, |
| 1294 root, generator, fsencoding, flags, comments, | 1305 root, generator, fsencoding, flags, comments, errors, |
| 1295 algorithm, digest, size) | 1306 algorithm, digest, size) |
| 1296 else: | 1307 else: |
| 1297 logging.warning("missing block end") | 1308 logging.warning("missing block end") |
| 1298 | 1309 |
| 1299 | 1310 |
| 1300 def print_block_data(block_no, tag, generator, fsencoding, flags, comments, | 1311 def print_block_data(block_no, tag, generator, fsencoding, flags, comments, |
| 1301 algorithm, digest, size): | 1312 errors, algorithm, digest, size): |
| 1302 digeststr = util.n(binascii.hexlify(digest)) if digest else "<no digest>" | 1313 digeststr = util.n(binascii.hexlify(digest)) if digest else "<no digest>" |
| 1303 sizestr = str(size) if size is not None else "<no size>" | 1314 sizestr = str(size) if size is not None else "<no size>" |
| 1304 print("BLOCK No %d:" % (block_no,)) | 1315 print("BLOCK No %d:" % (block_no,)) |
| 1305 print(" Tag:", tag) | 1316 print(" Tag:", tag) |
| 1306 print(" FS-Encoding:", fsencoding) | 1317 print(" FS-Encoding:", fsencoding) |
| 1310 print(" Comments:", comments if comments else "") | 1321 print(" Comments:", comments if comments else "") |
| 1311 print(" Algorithm:", algorithm) | 1322 print(" Algorithm:", algorithm) |
| 1312 if algorithm != "SIZE": | 1323 if algorithm != "SIZE": |
| 1313 print(" Digest:", digeststr) | 1324 print(" Digest:", digeststr) |
| 1314 print(" Size:", sizestr) | 1325 print(" Size:", sizestr) |
| 1326 print(" Errors:", errors if errors else "<none>") | |
| 1315 | 1327 |
| 1316 | 1328 |
| 1317 if __name__ == "__main__": | 1329 if __name__ == "__main__": |
| 1318 sys.exit(main()) | 1330 sys.exit(main()) |
