|
26 | 26 | epilog='Created by Robert Vojcik <[email protected]>')
|
27 | 27 |
|
28 | 28 | # 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 | + ) |
33 | 37 |
|
34 | 38 | args = parser.parse_args()
|
35 | 39 |
|
|
42 | 46 |
|
43 | 47 | # Init gitlab api object
|
44 | 48 | if args.debug:
|
45 |
| - print("%s, token"%(gitlab_url)) |
| 49 | + print("%s, token" % (gitlab_url)) |
46 | 50 | gitlab = gitlab.Api(gitlab_url, token)
|
47 | 51 |
|
48 | 52 | # Export each project
|
49 | 53 | for project in c.config["gitlab"]["projects"]:
|
50 | 54 | if args.debug:
|
51 |
| - print("Exporting %s"%(project)) |
| 55 | + print("Exporting %s" % (project)) |
52 | 56 | status = gitlab.project_export(project)
|
53 | 57 |
|
54 | 58 | # Export successful
|
55 | 59 | if status:
|
56 | 60 | if args.debug:
|
57 |
| - print("Success for %s"%(project)) |
| 61 | + print("Success for %s" % (project)) |
58 | 62 | # Download project to our destination
|
59 | 63 | if c.config["backup"]["project_dirs"]:
|
60 | 64 | destination = c.config["backup"]["destination"] + "/" + project
|
61 | 65 | else:
|
62 | 66 | destination = c.config["backup"]["destination"]
|
63 | 67 |
|
64 | 68 | if args.debug:
|
65 |
| - print(" Destination %s"%(destination)) |
| 69 | + print(" Destination %s" % (destination)) |
66 | 70 |
|
67 | 71 | # Prepare actual date
|
68 | 72 | d = date.today()
|
69 | 73 | # File template from config
|
70 | 74 | file_tmpl = c.config["backup"]["backup_name"]
|
71 | 75 | # 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 | + ) |
73 | 80 | # 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 | + ) |
75 | 84 |
|
76 | 85 | if args.debug:
|
77 |
| - print(" Destination file %s"%(dest_file)) |
| 86 | + print(" Destination file %s" % (dest_file)) |
78 | 87 |
|
79 | 88 | # Create directories
|
80 | 89 | if not os.path.isdir(destination):
|
|
83 | 92 | # Get URL from gitlab object
|
84 | 93 | url = gitlab.download_url["api_url"]
|
85 | 94 | if args.debug:
|
86 |
| - print(" URL: %s"%(url)) |
| 95 | + print(" URL: %s" % (url)) |
87 | 96 |
|
88 | 97 | # 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}) |
90 | 103 |
|
91 | 104 | with open(dest_file, 'wb') as f:
|
92 | 105 | for chunk in r.iter_content(chunk_size=1024):
|
|
0 commit comments