def print_header(): """ Print application name and version on command line. :rtype: None """ # get application name and version name_and_version = settings.get_name_and_version() print() print(name_and_version) print('=' * len(name_and_version))
def print_header(): """ Print application name and version on command line. :rtype: None """ # get application name and version name_and_version = settings.get_name_and_version() print() print(name_and_version) print('=' * len(name_and_version)) # on Linux, check whether the script runs with superuser rights if sys.platform == 'linux' and os.getuid() != 0: print('You probably want to run this application with ' 'superuser rights...') print()
def parse_command_line(settings): """ Parse command line. :param settings: backup settings and application information :type settings: lalikan.settings :returns: selected backup section (**None** for all sections) and whether a backup should be forced :rtype: tuple(section, force_backup) """ # initialise command line parser parser = argparse.ArgumentParser( description=settings.get_description(), formatter_class=argparse.RawDescriptionHelpFormatter) # argument: show version information parser.add_argument( '--version', action='version', version=settings.get_name_and_version()) # argument: show copyright and licence information parser.add_argument( '--licence', action='store_true', dest='licence', default=False, help='show copyright and licence information and exit') # argument: list all backup sections parser.add_argument( '-l', '--list', action='store_true', dest='list_sections', default=False, help='list all defined backup sections and exit') # argument: create backup for section only parser.add_argument( '-s', '--section', action='store', dest='section', metavar='SECTION', default=None, help='create backup for SECTION (otherwise, backups for all ' 'sections will be created)') # argument: force backup parser.add_argument( '--force', action='store_true', dest='force_backup', default=False, help='force backup') # parse command line args = parser.parse_args() # show copyright and licence information if args.licence: # get application name and version name_and_version = settings.get_name_and_version() print() print(name_and_version) print('=' * len(name_and_version)) print(settings.get_description()) print() print(settings.get_copyrights()) print() print(settings.get_license(True)) print() exit(0) # list defined sections and exit if args.list_sections: list_sections('Backup sections:') exit(0) # user asked to create a specific backup, ... if args.section is not None: # ..., but the specified backup section does not exist if args.section not in settings.sections(): # print error message, list defined sections and exit message = 'Could not find section "{}". '.format(args.section) message += 'Please use one of these sections:' list_sections(message) exit(1) return (args.section, args.force_backup)