git @ Cat's Eye Technologies tagfarm / 22e0e7b
Merge pull request #2 from cpressey/develop-0.3 Develop 0.3 Chris Pressey authored 4 years ago GitHub committed 4 years ago
3 changed file(s) with 17 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
00 `tagfarm`
11 =========
22
3 _Version 0.2_
3 _Version 0.3_
44 | _Entry_ [@ catseye.tc](https://catseye.tc/node/tagfarm)
55 | _See also:_ [shelf](https://github.com/catseye/shelf#readme)
66 ∘ [ellsync](https://github.com/catseye/ellsync#readme)
9292 symlinks (not, for example, regular files) and not broken. To have it replace all files
9393 it happens to find in the tag link directory, pass `--force-relink`. This is occasionally
9494 handy for converting a directory full of copies of elsewhere-existing media files,
95 into links.
95 into links. In conjunction with this, `--restrict-to-tag` may be used to name a single tag,
96 and this operation will be applied only to that tag.
9697
9798 `tagfarm repair` will also replace any links it finds that have absolute target paths,
9899 with ones with relative target paths, even when the link is not broken.
3434
3535
3636 def repair(media_root, options):
37 perform_repair(media_root, verbose=options.verbose, force_relink=options.force_relink, prune=options.prune)
37 perform_repair(
38 media_root,
39 verbose=options.verbose,
40 force_relink=options.force_relink,
41 restrict_to_tag=options.restrict_to_tag,
42 prune=options.prune
43 )
3844
3945
4046 def rename(media_root, options):
9298 parser.add_argument('--verbose', action='store_true',
9399 help='Produce more reporting output'
94100 )
101 parser.add_argument('--version', action='version', version="%(prog)s 0.3")
95102
96103 subparsers = parser.add_subparsers()
97104
133140 parser_repair.add_argument('--prune', action='store_true',
134141 help='Remove broken symlinks for which no candidate files can be found'
135142 )
143 parser_repair.add_argument('--restrict-to-tag', metavar='TAG', type=str, default=None,
144 help='Only attempt to repair taglinks with this tag'
145 )
136146 parser_repair.set_defaults(func=repair)
137147
138148 # - - - - rename - - - -
6262 os.symlink(srcname, linkname)
6363
6464
65 def perform_repair(media_root, verbose=False, force_relink=False, prune=False):
65 def perform_repair(media_root, verbose=False, force_relink=False, restrict_to_tag=None, prune=False):
6666 index = index_files(media_root)
6767
6868 by_tags_dir = os.path.join(media_root, 'by-tag')
69 for tag in sorted(os.listdir(by_tags_dir)):
69 tags = [restrict_to_tag] if restrict_to_tag else sorted(os.listdir(by_tags_dir))
70 for tag in tags:
7071 tagdir = os.path.join(by_tags_dir, tag)
7172 if not os.path.isdir(tagdir):
7273 continue
7374 repairs_made = []
7475 for basename in sorted(os.listdir(tagdir)):
75
7676 linkname = os.path.join(tagdir, basename)
7777
7878 if basename.startswith('Link to '):