Merge pull request #2 from cpressey/develop-0.3
Develop 0.3
Chris Pressey authored 4 years ago
GitHub committed 4 years ago
0 | 0 |
`tagfarm`
|
1 | 1 |
=========
|
2 | 2 |
|
3 | |
_Version 0.2_
|
|
3 |
_Version 0.3_
|
4 | 4 |
| _Entry_ [@ catseye.tc](https://catseye.tc/node/tagfarm)
|
5 | 5 |
| _See also:_ [shelf](https://github.com/catseye/shelf#readme)
|
6 | 6 |
∘ [ellsync](https://github.com/catseye/ellsync#readme)
|
|
92 | 92 |
symlinks (not, for example, regular files) and not broken. To have it replace all files
|
93 | 93 |
it happens to find in the tag link directory, pass `--force-relink`. This is occasionally
|
94 | 94 |
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.
|
96 | 97 |
|
97 | 98 |
`tagfarm repair` will also replace any links it finds that have absolute target paths,
|
98 | 99 |
with ones with relative target paths, even when the link is not broken.
|
34 | 34 |
|
35 | 35 |
|
36 | 36 |
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 |
)
|
38 | 44 |
|
39 | 45 |
|
40 | 46 |
def rename(media_root, options):
|
|
92 | 98 |
parser.add_argument('--verbose', action='store_true',
|
93 | 99 |
help='Produce more reporting output'
|
94 | 100 |
)
|
|
101 |
parser.add_argument('--version', action='version', version="%(prog)s 0.3")
|
95 | 102 |
|
96 | 103 |
subparsers = parser.add_subparsers()
|
97 | 104 |
|
|
133 | 140 |
parser_repair.add_argument('--prune', action='store_true',
|
134 | 141 |
help='Remove broken symlinks for which no candidate files can be found'
|
135 | 142 |
)
|
|
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 |
)
|
136 | 146 |
parser_repair.set_defaults(func=repair)
|
137 | 147 |
|
138 | 148 |
# - - - - rename - - - -
|
62 | 62 |
os.symlink(srcname, linkname)
|
63 | 63 |
|
64 | 64 |
|
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):
|
66 | 66 |
index = index_files(media_root)
|
67 | 67 |
|
68 | 68 |
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:
|
70 | 71 |
tagdir = os.path.join(by_tags_dir, tag)
|
71 | 72 |
if not os.path.isdir(tagdir):
|
72 | 73 |
continue
|
73 | 74 |
repairs_made = []
|
74 | 75 |
for basename in sorted(os.listdir(tagdir)):
|
75 | |
|
76 | 76 |
linkname = os.path.join(tagdir, basename)
|
77 | 77 |
|
78 | 78 |
if basename.startswith('Link to '):
|