error handling
This commit is contained in:
parent
130074788a
commit
72c1532284
@ -59,16 +59,24 @@ def sync(args):
|
|||||||
with open(args['lockfile'], 'w') as f:
|
with open(args['lockfile'], 'w') as f:
|
||||||
f.write(str(os.getpid()))
|
f.write(str(os.getpid()))
|
||||||
with open(args['logfile'], 'a') as log:
|
with open(args['logfile'], 'a') as log:
|
||||||
# try:
|
c = subprocess.run(cmd, stdout = log, stderr = subprocess.PIPE)
|
||||||
# Disabled the try/except because otherwise it complains on broken symlinks. Gah!
|
|
||||||
subprocess.call(cmd, stdout = log, stderr = subprocess.STDOUT)
|
|
||||||
now = int(datetime.datetime.timestamp(datetime.datetime.utcnow()))
|
now = int(datetime.datetime.timestamp(datetime.datetime.utcnow()))
|
||||||
with open(os.path.join(args['destination'], 'lastsync'), 'w') as f:
|
with open(os.path.join(args['destination'], 'lastsync'), 'w') as f:
|
||||||
f.write(str(now) + '\n')
|
f.write(str(now) + '\n')
|
||||||
os.remove(args['lockfile'])
|
os.remove(args['lockfile'])
|
||||||
# except:
|
# Only report errors at the end of the run if we aren't running in cron. Otherwise, log them.
|
||||||
# os.remove(args['lockfile'])
|
errors = c.stderr.decode('utf-8').splitlines()
|
||||||
# exit('!! The rsync has failed. See {0} for more details. !!'.format(args['logfile']))
|
if os.isatty(sys.stdin.fileno()):
|
||||||
|
print('We encountered some errors:')
|
||||||
|
for e in errors:
|
||||||
|
if e.startswith('symlink has no referent: '):
|
||||||
|
print('Broken upstream symlink: {0}'.format(e.split()[1].replace('"', '')))
|
||||||
|
else:
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
with open(args['logfile'], 'a') as f:
|
||||||
|
for e in errors:
|
||||||
|
f.write('{0}\n'.format(e))
|
||||||
return()
|
return()
|
||||||
|
|
||||||
def getDefaults():
|
def getDefaults():
|
||||||
|
Loading…
Reference in New Issue
Block a user