forked from tarantool/mkrepo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mkrepo.py
executable file
·121 lines (90 loc) · 2.98 KB
/
mkrepo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
import argparse
import os
import debrepo
import rpmrepo
import storage
def is_deb_repo(stor):
result = False
for _ in stor.files("pool/"):
result = True
break
return result
def is_rpm_repo(stor):
result = False
for _ in stor.files("Packages/"):
result = True
break
return result
def update_repo(path, args):
stor = None
if not os.path.exists(args.temp_dir):
os.mkdir(args.temp_dir)
if path.startswith('s3://'):
path = path[len('s3://'):]
if '/' in path:
bucket, prefix = path.split('/', 1)
else:
bucket, prefix = path, '.'
stor = storage.S3Storage(args.s3_endpoint,
bucket,
prefix,
args.s3_access_key_id,
args.s3_secret_access_key,
args.s3_region,
args.s3_public_read)
else:
stor = storage.FilesystemStorage(path)
if is_deb_repo(stor):
print("Updating deb repository: %s" % path)
debrepo.update_repo(stor, args.sign, args.temp_dir, args.force)
elif is_rpm_repo(stor):
print("Updating rpm repository: %s" % path)
rpmrepo.update_repo(stor, args.sign, args.temp_dir, args.force)
else:
print("Unknown repository: %s" % path)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--temp-dir',
default=".mkrepo",
help='directory used to store temporary artifacts')
parser.add_argument(
'--s3-access-key-id', help='access key for connecting to S3')
parser.add_argument(
'--s3-secret-access-key', help='secret key for connecting to S3')
parser.add_argument(
'--s3-endpoint',
help='region endpoint for connecting to S3 (default: s3.amazonaws.com)')
parser.add_argument(
'--s3-region',
help='S3 region name')
parser.add_argument(
'--s3-public-read',
action='store_true',
default=False,
help='set read-only permission on files uploaded to S3 to an anonymous users')
parser.add_argument(
'--sign',
action='store_true',
default=False,
help='sign package metadata')
parser.add_argument(
'--force',
action='store_true',
default=False,
help="""when adding packages to the index, the malformed one will be
skipped. By default, a malformed package will cause the utility
to stop working. The malformed_list.txt file will also be added
to the repository
"""
)
parser.add_argument(
'path', nargs='+',
help='List of paths to scan. Either s3://bucket/prefix or /path/on/local/fs')
args = parser.parse_args()
paths = args.path
for path in paths:
update_repo(path, args)
if __name__ == '__main__':
main()