This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dispatch.py
67 lines (61 loc) · 1.96 KB
/
dispatch.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
import subprocess as sp
import sys
import re
def dispatch(args):
sys.tracebacklimit = 0
# Query
if args.Q:
if args.c:
sp.check_call(["brew", "log"]+args.targets)
elif args.i:
sp.check_call(["brew", "info"]+args.targets)
elif args.l:
sp.check_call(["brew", "list"]+args.targets)
elif args.o:
raise NotImplementedError
elif args.s:
out = sp.check_output(["brew", "list"]).decode("utf-8")
result = [ln for ln in out.splitlines()
if re.search(args.targets[0], ln)]
for i in result:
print(i)
elif args.u:
out = sp.check_output(["brew", "outdated"]).decode("utf-8")
result = [ln for ln in out.splitlines()
if re.search(args.targets[0], ln)]
for i in result:
print(i)
else:
# pacman -Q
raise NotImplementedError
# Remove
elif args.R:
if args.s:
raise NotImplementedError
else:
# pacman -R
sp.check_call(["brew", "remove"]+args.targets)
# Sync
elif args.S:
if args.c == 1:
sp.check_call(["brew", "cleanup"]+args.targets)
elif args.c == 2:
sp.check_call(["brew", "cleanup", "-s"]+args.targets)
elif args.c == 3:
raise NotImplementedError
elif args.i:
sp.check_call(["brew", "info"]+args.targets)
elif args.s:
sp.check_call(["brew", "search"]+[" ".join(args.targets)])
elif args.u or args.y:
if args.y:
# pacman -Sy
sp.check_call(["brew", "update"]+args.targets)
if args.u:
# pacman -Su
sp.check_call(["brew", "upgrade"]+args.targets)
else:
# pacman -Q
raise NotImplementedError
else:
raise NotImplementedError