-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadd-package
More file actions
executable file
·47 lines (38 loc) · 1.19 KB
/
add-package
File metadata and controls
executable file
·47 lines (38 loc) · 1.19 KB
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
#!/usr/bin/env python3
import json
import os
import os.path
import subprocess
import sys
assert len(sys.argv) >= 4, \
'Usage: add-package <env> <distribution> <.deb-file>+'
env, distribution = sys.argv[1:3]
packages = sys.argv[3:]
base_path = os.path.expanduser('~') + '/aptly'
repo_path = '/'.join((base_path, env, distribution))
config_file = '{}/{}-{}.conf'.format(base_path, env, distribution)
def run_aptly(*args):
aptly_cmd = ['aptly', '-config=' + config_file]
subprocess.call(aptly_cmd + list(args))
def init_config():
os.makedirs(base_path, exist_ok=True)
contents = {
'rootDir': repo_path,
'architectures': ['amd64', 'all'],
}
with open(config_file, 'w') as conf:
json.dump(contents, conf)
def init_repo():
if os.path.exists(repo_path + '/db'):
return
os.makedirs(repo_path, exist_ok=True)
run_aptly('repo', 'create', '-distribution=' + distribution, 'myrepo')
run_aptly('publish', 'repo', 'myrepo')
def add_packages():
for pkg in packages:
run_aptly('repo', 'add', 'myrepo', pkg)
run_aptly('publish', 'update', distribution)
if __name__ == '__main__':
init_config();
init_repo();
add_packages();