Skip to content

Commit 97e9c76

Browse files
committed
More error tolerant cleaning + remove unused flags
1 parent 1b74b46 commit 97e9c76

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

jwb-index

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ parser = argparse.ArgumentParser(prog='jwb-index',
1212
usage='%(prog)s [options] [DIR]',
1313
description='Index or download media from tv.jw.org')
1414

15+
# The commented out options would only be valid with a --config file
1516
add_arguments(parser, ['--quiet',
1617
'--mode',
1718
'--lang',
1819
'--quality',
1920
'--subtitles',
20-
'--no-subtitles',
21+
#'--no-subtitles',
2122
'--download',
22-
'--checksum',
23+
#'--checksum',
2324
'--no-checksum',
2425
'--no-warning',
2526
'--free',
@@ -51,12 +52,17 @@ parser.add_argument('--curl-path',
5152
default='curl',
5253
metavar='PATH',
5354
help='path to the curl binary')
55+
parser.add_argument('--clean-symlinks',
56+
dest='clean',
57+
action='store_true',
58+
help='remove all old symlinks (only valid with --mode=filesystem)')
5459

5560
jwb = JWBroadcasting()
5661
# Default values, not set by JWBroadcasting
5762
jwb.work_dir = '.'
5863
jwb.mode = None
5964
jwb.warn = False
65+
jwb.clean = False
6066
jwb.exclude_category = 'VODSJJMeetings'
6167
parser.parse_args(namespace=jwb)
6268

@@ -87,7 +93,7 @@ elif mode == 'm3u':
8793
elif mode == 'm3ucompat':
8894
jo.output_m3u(r, wd, subdir, flat=True)
8995
elif mode == 'filesystem':
90-
jo.clean_symlinks(os.path.join(wd, subdir), quiet=jwb.quiet)
96+
jo.clean_symlinks(os.path.join(wd, subdir), quiet=jwb.quiet, clean_all=jwb.clean)
9197
jo.output_filesystem(r, wd, subdir)
9298
elif mode == 'html':
9399
jo.output_html(r, wd, subdir)

jwb-stream

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ parser = argparse.ArgumentParser(prog='jwb-stream',
1414
add_arguments(parser, ['--lang',
1515
'--quality',
1616
'--subtitles',
17-
'--no-subtitles'])
17+
#'--no-subtitles'
18+
])
1819
# TODO
1920
# parser.add_argument('--config')
2021
parser.add_argument('--channel',

jwlib/arguments.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
'help': 'prefer subtitled videos'},
3232
'--no-subtitles': {
3333
'action': 'store_false',
34-
'dest': 'subtitles'},
34+
'dest': 'subtitles',
35+
'help': 'prefer un-subtitled videos'},
3536
'--checksum': {
3637
'action': 'store_true',
3738
'dest': 'checksums',
3839
'help': 'check md5 checksum'},
3940
'--no-checksum': {
40-
'action': 'store_false'},
41+
'action': 'store_false',
42+
'dest': 'checksums',
43+
'help': 'don\'t check md5 checksum'},
4144
'--free': {
4245
'default': 0,
4346
'type': int,
@@ -88,7 +91,7 @@ def disk_usage_info(wd, keep_free: int, warn=True, quiet=0):
8891
makedirs(wd,exist_ok=True)
8992
free = disk_usage(wd).free
9093

91-
if quiet == 0:
94+
if quiet < 1:
9295
print('free space: {:} MiB, minimum limit: {:} MiB'.format(free//1024**2, keep_free//1024**2), file=stderr)
9396

9497
if warn and free < keep_free:

jwlib/output.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,24 @@ def clean_symlinks(d, clean_all=False, quiet=0):
169169
170170
:param d: Path to directory to clean
171171
:param clean_all: Remove non-broken symlinks too
172+
:param quiet: Log level (int)
172173
"""
173-
try:
174-
for subdir in os.listdir(d):
174+
if not os.path.isdir(d):
175+
return
176+
177+
for subdir in os.listdir(d):
175178
subdir = pj(d, subdir)
179+
if not os.path.isdir(subdir):
180+
continue
181+
176182
for file in os.listdir(subdir):
177183
file = pj(subdir, file)
178-
# If file is not a symlink it will raise OSError
179-
try:
180-
source = pj(subdir, os.readlink(file))
181-
except OSError:
184+
if not os.path.islink(file):
182185
continue
183186

184-
# Remove broken links
187+
source = pj(subdir, os.readlink(file))
188+
185189
if clean_all or not os.path.exists(source):
186190
if quiet < 2:
187-
print('removing broken link: ' + os.path.basename(file), file=stderr)
191+
print('removing link: ' + os.path.basename(file), file=stderr)
188192
os.remove(file)
189-
190-
except (NotADirectoryError, FileNotFoundError):
191-
pass

0 commit comments

Comments
 (0)