#NEWLINE# def main( ) : #NEWLINE# #INDENT# 'Command line interface for the ``rotate-backups`` program.' #NEWLINE# coloredlogs . install ( syslog = True ) #NEWLINE# config_file = None #NEWLINE# dry_run = False #NEWLINE# exclude_list = [ ] #NEWLINE# include_list = [ ] #NEWLINE# io_scheduling_class = None #NEWLINE# rotation_scheme = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# use_sudo = False #NEWLINE# strict = True #NEWLINE# selected_locations = [ ] #NEWLINE# try : #NEWLINE# #INDENT# ( options , arguments ) = getopt . getopt ( sys . argv [ 1 : ] , 'H:d:w:m:y:I:x:ri:c:r:unvqh' , [ 'hourly=' , 'daily=' , 'weekly=' , 'monthly=' , 'yearly=' , 'include=' , 'exclude=' , 'relaxed' , 'ionice=' , 'config=' , 'use-sudo' , 'dry-run' , 'verbose' , 'quiet' , 'help' ] ) #NEWLINE# for ( option , value ) in options : #NEWLINE# #INDENT# if ( option in ( '-H' , '--hourly' ) ) : #NEWLINE# #INDENT# rotation_scheme [ 'hourly' ] = coerce_retention_period ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-d' , '--daily' ) ) : #NEWLINE# #INDENT# rotation_scheme [ 'daily' ] = coerce_retention_period ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-w' , '--weekly' ) ) : #NEWLINE# #INDENT# rotation_scheme [ 'weekly' ] = coerce_retention_period ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-m' , '--monthly' ) ) : #NEWLINE# #INDENT# rotation_scheme [ 'monthly' ] = coerce_retention_period ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-y' , '--yearly' ) ) : #NEWLINE# #INDENT# rotation_scheme [ 'yearly' ] = coerce_retention_period ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-I' , '--include' ) ) : #NEWLINE# #INDENT# include_list . append ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-x' , '--exclude' ) ) : #NEWLINE# #INDENT# exclude_list . append ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-r' , '--relaxed' ) ) : #NEWLINE# #INDENT# strict = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-i' , '--ionice' ) ) : #NEWLINE# #INDENT# value = value . lower ( ) . strip ( ) #NEWLINE# expected = ( 'idle' , 'best-effort' , 'realtime' ) #NEWLINE# if ( value not in expected ) : #NEWLINE# #INDENT# msg = 'Invalid I/O scheduling class! (got %r while valid options are %s)' #NEWLINE# raise Exception ( ( msg % ( value , concatenate ( expected ) ) ) ) #NEWLINE# #UNINDENT# io_scheduling_class = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-c' , '--config' ) ) : #NEWLINE# #INDENT# config_file = parse_path ( value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-u' , '--use-sudo' ) ) : #NEWLINE# #INDENT# use_sudo = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-n' , '--dry-run' ) ) : #NEWLINE# #INDENT# logger . info ( 'Performing a dry run (because of %s option) ..' , option ) #NEWLINE# dry_run = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( value in ( '-v' , '--verbose' ) ) : #NEWLINE# #INDENT# coloredlogs . increase_verbosity ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-q' , '--quiet' ) ) : #NEWLINE# #INDENT# coloredlogs . decrease_verbosity ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( option in ( '-h' , '--help' ) ) : #NEWLINE# #INDENT# usage ( __doc__ ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert False , 'Unhandled option! (programming error)' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if rotation_scheme : #NEWLINE# #INDENT# logger . debug ( 'Parsed rotation scheme: %s' , rotation_scheme ) #NEWLINE# #UNINDENT# if arguments : #NEWLINE# #INDENT# selected_locations . extend ( ( coerce_location ( value , sudo = use_sudo ) for value in arguments ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# selected_locations . extend ( ( location for ( location , rotation_scheme , options ) in load_config_file ( config_file ) ) ) #NEWLINE# #UNINDENT# if ( not selected_locations ) : #NEWLINE# #INDENT# usage ( __doc__ ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logger . error ( '%s' , e ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# for location in selected_locations : #NEWLINE# #INDENT# RotateBackups ( rotation_scheme = rotation_scheme , include_list = include_list , exclude_list = exclude_list , io_scheduling_class = io_scheduling_class , dry_run = dry_run , config_file = config_file , strict = strict ) . rotate_backups ( location )