fix for sksdump and adding journald support for the backup script
This commit is contained in:
		
							parent
							
								
									3bcdb408a1
								
							
						
					
					
						commit
						33558610a6
					
				@ -120,7 +120,10 @@ def destPrep(args):
 | 
				
			|||||||
            _dir = os.path.join(thisdir, d)
 | 
					            _dir = os.path.join(thisdir, d)
 | 
				
			||||||
            if os.path.isdir(_dir):
 | 
					            if os.path.isdir(_dir):
 | 
				
			||||||
                if len(os.listdir(_dir)) == 0:
 | 
					                if len(os.listdir(_dir)) == 0:
 | 
				
			||||||
                    os.rmdir(os.path.join(thisdir, d))
 | 
					                    try:
 | 
				
			||||||
 | 
					                        os.rmdir(os.path.join(thisdir, d))
 | 
				
			||||||
 | 
					                    except NotADirectoryError:
 | 
				
			||||||
 | 
					                        pass  # in case it grabs the "current" symlink
 | 
				
			||||||
    #try:
 | 
					    #try:
 | 
				
			||||||
    #    os.removedirs(sks['destdir'])  # Remove empty dirs
 | 
					    #    os.removedirs(sks['destdir'])  # Remove empty dirs
 | 
				
			||||||
    #except:
 | 
					    #except:
 | 
				
			||||||
 | 
				
			|||||||
@ -35,23 +35,38 @@ loglvls = {'critical': logging.CRITICAL,
 | 
				
			|||||||
class Backup(object):
 | 
					class Backup(object):
 | 
				
			||||||
    def __init__(self, args):
 | 
					    def __init__(self, args):
 | 
				
			||||||
        self.args = 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})',
 | 
					        _logfmt = logging.Formatter(fmt = '{levelname}:{name}: {message} ({asctime}; {filename}:{lineno})',
 | 
				
			||||||
                                    style = '{',
 | 
					                                    style = '{',
 | 
				
			||||||
                                    datefmt = '%Y-%m-%d %H:%M:%S')
 | 
					                                    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 = []
 | 
					        handlers = []
 | 
				
			||||||
        if self.args['disklog']:
 | 
					        if self.args['disklog']:
 | 
				
			||||||
            handlers.append(logging.handlers.RotatingFileHandler(self.args['logfile'],
 | 
					            handlers.append(logging.handlers.RotatingFileHandler(self.args['logfile'],
 | 
				
			||||||
                                                                 encoding = 'utf8',
 | 
					                                                                 encoding = 'utf8',
 | 
				
			||||||
                                                                 maxBytes = 100000,
 | 
					                                                                 maxBytes = 100000,
 | 
				
			||||||
                                                                 backupCount = 1))
 | 
					                                                                 backupCount = 1))
 | 
				
			||||||
        handlers.append(logging.StreamHandler())
 | 
					        if self.args['verbose']:
 | 
				
			||||||
        self.logger = logging.getLogger(__name__)
 | 
					            handlers.append(logging.StreamHandler())
 | 
				
			||||||
        self.logger.setLevel(logging.DEBUG)
 | 
					        if has_systemd:
 | 
				
			||||||
 | 
					            handlers.append(journal.JournalHandler())
 | 
				
			||||||
        for h in handlers:
 | 
					        for h in handlers:
 | 
				
			||||||
            h.setFormatter(_logfmt)
 | 
					            h.setFormatter(_logfmt)
 | 
				
			||||||
            h.setLevel(loglvls[self.args['loglevel']])
 | 
					            h.setLevel(loglvls[self.args['loglevel']])
 | 
				
			||||||
            self.logger.addHandler(h)
 | 
					            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):
 | 
					        def create(self):
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
@ -113,6 +128,11 @@ def parseArgs():
 | 
				
			|||||||
                      default = _logfile,
 | 
					                      default = _logfile,
 | 
				
			||||||
                      help = ('The path to the logfile, only used if -Ld/--log-to-disk ' +
 | 
					                      help = ('The path to the logfile, only used if -Ld/--log-to-disk ' +
 | 
				
			||||||
                              'is specified. Default: \033[1m{0}\033[0m (dynamic)').format(_logfile))
 | 
					                              '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 ###
 | 
					    ### ARGS FOR ALL OPERATIONS ###
 | 
				
			||||||
    commonargs = argparse.ArgumentParser(add_help = False)
 | 
					    commonargs = argparse.ArgumentParser(add_help = False)
 | 
				
			||||||
    commonargs.add_argument('-r', '--repo',
 | 
					    commonargs.add_argument('-r', '--repo',
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user