fix for sksdump and adding journald support for the backup script

This commit is contained in:
brent s 2017-10-24 06:04:54 -04:00
parent 3bcdb408a1
commit 33558610a6
2 changed files with 28 additions and 5 deletions

View File

@ -120,7 +120,10 @@ def destPrep(args):
_dir = os.path.join(thisdir, d)
if os.path.isdir(_dir):
if len(os.listdir(_dir)) == 0:
try:
os.rmdir(os.path.join(thisdir, d))
except NotADirectoryError:
pass # in case it grabs the "current" symlink
#try:
# os.removedirs(sks['destdir']) # Remove empty dirs
#except:

View File

@ -35,23 +35,38 @@ loglvls = {'critical': logging.CRITICAL,
class Backup(object):
def __init__(self, args):
self.args = args
# Set up logging
### LOGGING ###
# Thanks to:
# https://web.archive.org/web/20170726052946/http://www.lexev.org/en/2013/python-logging-every-day/
# https://stackoverflow.com/a/42604392
# https://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html
# and user K900_ on r/python for entertaining my very silly question.
self.logger = logging.getLogger(__name__)
self.logger.setLevel(loglvls[self.args['loglevel']])
_logfmt = logging.Formatter(fmt = '{levelname}:{name}: {message} ({asctime}; {filename}:{lineno})',
style = '{',
datefmt = '%Y-%m-%d %H:%M:%S')
_journalfmt = logging.Formatter(fmt = '{levelname}:{name}: {message} ({filename}:{lineno})',
style = '{',
datefmt = '%Y-%m-%d %H:%M:%S')
handlers = []
if self.args['disklog']:
handlers.append(logging.handlers.RotatingFileHandler(self.args['logfile'],
encoding = 'utf8',
maxBytes = 100000,
backupCount = 1))
if self.args['verbose']:
handlers.append(logging.StreamHandler())
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.DEBUG)
if has_systemd:
handlers.append(journal.JournalHandler())
for h in handlers:
h.setFormatter(_logfmt)
h.setLevel(loglvls[self.args['loglevel']])
self.logger.addHandler(h)
### CONFIG ###
if not os.path.isfile(self.args['cfgfile']):
self.logger.error('{0} does not exist'.format(self.args['cfgfile']))
exit(1)

def create(self):
pass
@ -113,6 +128,11 @@ def parseArgs():
default = _logfile,
help = ('The path to the logfile, only used if -Ld/--log-to-disk ' +
'is specified. Default: \033[1m{0}\033[0m (dynamic)').format(_logfile))
args.add_argument('-v', '--verbose',
dest = 'verbose',
action = 'store_true',
help = ('If specified, log messages will be printed to STDOUT/STDERR ' +
'in addition to the other configured log systems.'))
### ARGS FOR ALL OPERATIONS ###
commonargs = argparse.ArgumentParser(add_help = False)
commonargs.add_argument('-r', '--repo',