forked from riag/manjaro-linux-for-wsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-pkgs.py
46 lines (36 loc) · 1.05 KB
/
install-pkgs.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
# coding=utf-8
import re
import io
import subprocess
import click
tag_pkg_pattern = re.compile('^>(\S+)\s+(\S+)(\s+#.*)*')
pkg_pattern = re.compile('^(\S+)(\s+#.*)*')
def load_pkg(fpath):
pkg_list = []
with io.open(fpath, encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line: continue
if line.startswith('#'): continue
t = tag_pkg_pattern.match(line)
if t:
pkg_list.append(t.group(2))
else:
t = pkg_pattern.match(line)
if t:
pkg_list.append(t.group(1))
return pkg_list
def install_pkgs(pkg_list):
for pkg in pkg_list:
cmd = ['pacman', '--noconfirm', '-S', pkg]
subprocess.run(cmd)
@click.command()
@click.argument('pkg_files', nargs=-1)
def main(pkg_files):
for fpath in pkg_files:
print('starting install package from %s' % fpath)
pkg_list = load_pkg(fpath)
print(pkg_list)
install_pkgs(pkg_list)
if __name__ == '__main__':
main()