def main(): parser = argparse.ArgumentParser(description='Backup files to Glacier') parser.add_argument('--info', dest='log_level', action='store_const', const='info', help="Set log level to info") parser.add_argument('--debug', dest='log_level', action='store_const', const='debug', help="Set log level to debug") parser.add_argument('--include', dest='include', help="File extensions to include, separated by commas (ej: jpg,JPG)") parser.add_argument('--exclude', dest='exclude', help="File extensions to exclude, separated by commas (ej: avi,AVI,mov,MOV,xcf,XCF)") parser.add_argument('--one-file', dest='one_file', help="To upload only one file, if needed") parser.add_argument('--dry-run', dest='dry_run', action='store_true', help="Simulate process and report, without uploading anything") parser.add_argument('directory', nargs='+', metavar='DIRECTORY', help="Directory to backup") args = parser.parse_args() if args.log_level == 'debug': logging_.basicConfig(level=logging_.DEBUG) elif args.log_level == 'info': logging_.basicConfig(level=logging_.INFO) else: logging_.basicConfig(level=logging_.WARN) ctx = Context() if args.include and args.exclude: parser.error("Can't use --include and --exclude at the same time.") return elif args.include: ctx.set_include_extensions(args.include.split(',')) elif args.exclude: ctx.set_exclude_extensions(args.exclude.split(',')) if args.dry_run: ctx.dry_run = True if 'FROKUP_FTP_MODE' in os.environ: main = Main(ctx=ctx, glacier=GlacierFtpBased) try: main.glacier.launch() main.glacier.wait_for_ftpserver() for a_directory in args.directory: main.process_directory(a_directory) main.close() finally: main.glacier.kill_ftp() else: main = Main(ctx=ctx) if args.one_file: main.process_file(args.directory[0], args.one_file) else: for a_directory in args.directory: main.process_directory(a_directory) main.close() included, excluded = ctx.get_log_processed() print "{0} included file(s):".format(len(included)) for dirname, filename in included: print " + {0}/{1}".format(dirname, filename) print "{0} excluded file(s):".format(len(excluded)) for dirname, filename in excluded: print " - {0}/{1}".format(dirname, filename)