From 1a2c9ae1e62fdcd10a4167de6b07225c6aff182a Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 27 Apr 2014 07:05:51 -0700 Subject: [PATCH] the world is gonna roll me --- unsync.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/unsync.py b/unsync.py index d96508c..a4efd7e 100755 --- a/unsync.py +++ b/unsync.py @@ -62,21 +62,20 @@ def filterext(paths, exts): yield p def shouldsync(md): - rating = -1 - sync = u'' - if safetydance(md, 'rating'): - try: - rating = int(md['rating'][0]) - except ValueError: - pass - if safetydance(md, 'sync'): - sync = md['sync'][0].lower() + rating = safetydance(md, 'rating') + sync = safetydance(md, 'sync') + if rating != None: + rating = int(rating[0]) + if sync: + sync = sync[0].lower() + else: + sync = u'' if sync == u'no' or sync == u'space': return False if sync == u'yes' or sync == u'share': return True - if rating >= 3: + if rating != None and rating >= 3: return True return False @@ -93,7 +92,7 @@ def findmatching(haystack, needle): def run(args): if not len(args) in (2, 3): print("I need a path or two!", file=sys.stderr) - sys.exit(1) + return 1 inonly = len(args) == 2 @@ -109,7 +108,7 @@ def run(args): if inonly: print(p) else: tosync.append(md) - if inonly: return + if inonly: return 0 print("Beginning matching...", file=sys.stderr) outdir = args[2] @@ -127,7 +126,11 @@ def run(args): # TODO: just delete missing ones here print("MISSING", p) + return 0 + +ret = 0 try: - run(sys.argv) + ret = run(sys.argv) except KeyboardInterrupt: sys.exit(1) +sys.exit(ret)