From 622518e1a65ea9640468ad404f77d660c1241be0 Mon Sep 17 00:00:00 2001 From: wiro Date: Tue, 25 Dec 2018 14:18:40 +0100 Subject: [PATCH] Python codestyle changes --- gitlab-project-export.py | 39 ++++++++++++++++++++++++++------------- gitlab-project-import.py | 27 +++++++++++++++------------ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/gitlab-project-export.py b/gitlab-project-export.py index 6f00228..5b89502 100755 --- a/gitlab-project-export.py +++ b/gitlab-project-export.py @@ -26,10 +26,14 @@ epilog='Created by Robert Vojcik ') # Arguments - parser.add_argument('-c', dest='config', default='config.yaml', - help='config file') - parser.add_argument('-d', dest='debug', default=False, action='store_const', const=True, - help='Debug mode') + parser.add_argument( + '-c', dest='config', default='config.yaml', + help='config file' + ) + parser.add_argument( + '-d', dest='debug', default=False, action='store_const', + const=True, help='Debug mode' + ) args = parser.parse_args() @@ -42,19 +46,19 @@ # Init gitlab api object if args.debug: - print("%s, token"%(gitlab_url)) + print("%s, token" % (gitlab_url)) gitlab = gitlab.Api(gitlab_url, token) # Export each project for project in c.config["gitlab"]["projects"]: if args.debug: - print("Exporting %s"%(project)) + print("Exporting %s" % (project)) status = gitlab.project_export(project) # Export successful if status: if args.debug: - print("Success for %s"%(project)) + print("Success for %s" % (project)) # Download project to our destination if c.config["backup"]["project_dirs"]: destination = c.config["backup"]["destination"] + "/" + project @@ -62,19 +66,24 @@ destination = c.config["backup"]["destination"] if args.debug: - print(" Destination %s"%(destination)) + print(" Destination %s" % (destination)) # Prepare actual date d = date.today() # File template from config file_tmpl = c.config["backup"]["backup_name"] # Projectname in dest_file - dest_file = destination + "/" + file_tmpl.replace("{PROJECT_NAME}", project.replace("/", "-")) + dest_file = destination + "/" + file_tmpl.replace( + "{PROJECT_NAME}", + project.replace("/", "-") + ) # Date in dest_file - dest_file = dest_file.replace("{TIME}",d.strftime(c.config["backup"]["backup_time_format"])) + dest_file = dest_file.replace( + "{TIME}", d.strftime(c.config["backup"]["backup_time_format"]) + ) if args.debug: - print(" Destination file %s"%(dest_file)) + print(" Destination file %s" % (dest_file)) # Create directories if not os.path.isdir(destination): @@ -83,10 +92,14 @@ # Get URL from gitlab object url = gitlab.download_url["api_url"] if args.debug: - print(" URL: %s"%(url)) + print(" URL: %s" % (url)) # Download file - r = requests.get(url, allow_redirects=True, stream=True, headers={"PRIVATE-TOKEN": token}) + r = requests.get( + url, + allow_redirects=True, + stream=True, + headers={"PRIVATE-TOKEN": token}) with open(dest_file, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): diff --git a/gitlab-project-import.py b/gitlab-project-import.py index 3e164f4..0ab693f 100755 --- a/gitlab-project-import.py +++ b/gitlab-project-import.py @@ -26,14 +26,18 @@ epilog='Created by Robert Vojcik ') # Arguments - parser.add_argument('-c', dest='config', default='config.yaml', - help='config file') - parser.add_argument('-f', dest='filepath', default=False, - help='Path to gitlab exported project file') - parser.add_argument('-p', dest='project_path', default=False, - help='Project path') - parser.add_argument('-d', dest='debug', default=False, action='store_const', const=True, - help='Debug mode') + parser.add_argument( + '-c', dest='config', default='config.yaml', + help='config file') + parser.add_argument( + '-f', dest='filepath', default=False, + help='Path to gitlab exported project file') + parser.add_argument( + '-p', dest='project_path', default=False, + help='Project path') + parser.add_argument( + '-d', dest='debug', default=False, action='store_const', const=True, + help='Debug mode') args = parser.parse_args() @@ -46,18 +50,18 @@ # Init gitlab api object if args.debug: - print("%s, token"%(gitlab_url)) + print("%s, token" % (gitlab_url)) gitlab = gitlab.Api(gitlab_url, token) # import project if args.project_path and args.filepath and os.path.isfile(args.filepath): if args.debug: - print("Exporting %s"%(args.project_path)) + print("Exporting %s" % (args.project_path)) status = gitlab.project_import(args.project_path, args.filepath) # Import successful if status: - print("Import success for %s"%(args.project_path)) + print("Import success for %s" % (args.project_path)) sys.exit(0) else: print("Import was not successful") @@ -66,4 +70,3 @@ else: print("Error, you have to specify correct project_path and filepath") sys.exit(1) -