Skip to content

Commit 622518e

Browse files
author
wiro
committed
Python codestyle changes
1 parent 1ae4e7f commit 622518e

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

gitlab-project-export.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626
epilog='Created by Robert Vojcik <[email protected]>')
2727

2828
# Arguments
29-
parser.add_argument('-c', dest='config', default='config.yaml',
30-
help='config file')
31-
parser.add_argument('-d', dest='debug', default=False, action='store_const', const=True,
32-
help='Debug mode')
29+
parser.add_argument(
30+
'-c', dest='config', default='config.yaml',
31+
help='config file'
32+
)
33+
parser.add_argument(
34+
'-d', dest='debug', default=False, action='store_const',
35+
const=True, help='Debug mode'
36+
)
3337

3438
args = parser.parse_args()
3539

@@ -42,39 +46,44 @@
4246

4347
# Init gitlab api object
4448
if args.debug:
45-
print("%s, token"%(gitlab_url))
49+
print("%s, token" % (gitlab_url))
4650
gitlab = gitlab.Api(gitlab_url, token)
4751

4852
# Export each project
4953
for project in c.config["gitlab"]["projects"]:
5054
if args.debug:
51-
print("Exporting %s"%(project))
55+
print("Exporting %s" % (project))
5256
status = gitlab.project_export(project)
5357

5458
# Export successful
5559
if status:
5660
if args.debug:
57-
print("Success for %s"%(project))
61+
print("Success for %s" % (project))
5862
# Download project to our destination
5963
if c.config["backup"]["project_dirs"]:
6064
destination = c.config["backup"]["destination"] + "/" + project
6165
else:
6266
destination = c.config["backup"]["destination"]
6367

6468
if args.debug:
65-
print(" Destination %s"%(destination))
69+
print(" Destination %s" % (destination))
6670

6771
# Prepare actual date
6872
d = date.today()
6973
# File template from config
7074
file_tmpl = c.config["backup"]["backup_name"]
7175
# Projectname in dest_file
72-
dest_file = destination + "/" + file_tmpl.replace("{PROJECT_NAME}", project.replace("/", "-"))
76+
dest_file = destination + "/" + file_tmpl.replace(
77+
"{PROJECT_NAME}",
78+
project.replace("/", "-")
79+
)
7380
# Date in dest_file
74-
dest_file = dest_file.replace("{TIME}",d.strftime(c.config["backup"]["backup_time_format"]))
81+
dest_file = dest_file.replace(
82+
"{TIME}", d.strftime(c.config["backup"]["backup_time_format"])
83+
)
7584

7685
if args.debug:
77-
print(" Destination file %s"%(dest_file))
86+
print(" Destination file %s" % (dest_file))
7887

7988
# Create directories
8089
if not os.path.isdir(destination):
@@ -83,10 +92,14 @@
8392
# Get URL from gitlab object
8493
url = gitlab.download_url["api_url"]
8594
if args.debug:
86-
print(" URL: %s"%(url))
95+
print(" URL: %s" % (url))
8796

8897
# Download file
89-
r = requests.get(url, allow_redirects=True, stream=True, headers={"PRIVATE-TOKEN": token})
98+
r = requests.get(
99+
url,
100+
allow_redirects=True,
101+
stream=True,
102+
headers={"PRIVATE-TOKEN": token})
90103

91104
with open(dest_file, 'wb') as f:
92105
for chunk in r.iter_content(chunk_size=1024):

gitlab-project-import.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
epilog='Created by Robert Vojcik <[email protected]>')
2727

2828
# Arguments
29-
parser.add_argument('-c', dest='config', default='config.yaml',
30-
help='config file')
31-
parser.add_argument('-f', dest='filepath', default=False,
32-
help='Path to gitlab exported project file')
33-
parser.add_argument('-p', dest='project_path', default=False,
34-
help='Project path')
35-
parser.add_argument('-d', dest='debug', default=False, action='store_const', const=True,
36-
help='Debug mode')
29+
parser.add_argument(
30+
'-c', dest='config', default='config.yaml',
31+
help='config file')
32+
parser.add_argument(
33+
'-f', dest='filepath', default=False,
34+
help='Path to gitlab exported project file')
35+
parser.add_argument(
36+
'-p', dest='project_path', default=False,
37+
help='Project path')
38+
parser.add_argument(
39+
'-d', dest='debug', default=False, action='store_const', const=True,
40+
help='Debug mode')
3741

3842
args = parser.parse_args()
3943

@@ -46,18 +50,18 @@
4650

4751
# Init gitlab api object
4852
if args.debug:
49-
print("%s, token"%(gitlab_url))
53+
print("%s, token" % (gitlab_url))
5054
gitlab = gitlab.Api(gitlab_url, token)
5155

5256
# import project
5357
if args.project_path and args.filepath and os.path.isfile(args.filepath):
5458
if args.debug:
55-
print("Exporting %s"%(args.project_path))
59+
print("Exporting %s" % (args.project_path))
5660
status = gitlab.project_import(args.project_path, args.filepath)
5761

5862
# Import successful
5963
if status:
60-
print("Import success for %s"%(args.project_path))
64+
print("Import success for %s" % (args.project_path))
6165
sys.exit(0)
6266
else:
6367
print("Import was not successful")
@@ -66,4 +70,3 @@
6670
else:
6771
print("Error, you have to specify correct project_path and filepath")
6872
sys.exit(1)
69-

0 commit comments

Comments
 (0)