forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetGolangPackages.py
67 lines (54 loc) · 1.68 KB
/
getGolangPackages.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
from modules.Packages import getPackagesFromPkgDb, loadPackages, LocalDB
import optparse
def getPkgs():
pkgs_pkgdb = getPackagesFromPkgDb()
pkgs_local = loadPackages()
# Any new or removed packages
set_pkgdb = set(pkgs_pkgdb)
set_local = set(pkgs_local)
return set_pkgdb, set_local
def printPkgs(pkgs):
for pkg in pkgs:
print pkg
if __name__ == "__main__":
parser = optparse.OptionParser("%prog [-n] [-r] [-l] [-u]")
parser.add_option(
"", "-n", "--new", dest="new", action = "store_true", default = False,
help = "Scan for new golang packages"
)
parser.add_option(
"", "-r", "--removed", dest="removed", action = "store_true", default = False,
help = "Scan for removed golang packages"
)
parser.add_option(
"", "-l", "--list", dest="list", action = "store_true", default = False,
help = "List all golang packages saved in a local database"
)
parser.add_option(
"", "-u", "--update", dest="update", action = "store_true", default = False,
help = "Update local databases with new golang packages"
)
options, args = parser.parse_args()
# new packages
if options.new:
set_pkgdb, set_local = getPkgs()
printPkgs(list(set_pkgdb - set_local))
elif options.removed:
set_pkgdb, set_local = getPkgs()
printPkgs(list(set_local - set_pkgdb))
elif options.list:
pkgs = loadPackages()
printPkgs(sorted(pkgs))
elif options.update:
set_pkgdb, set_local = getPkgs()
ldb = LocalDB()
new_pkgs = list(set_pkgdb - set_local)
err, ret = ldb.addPackages(new_pkgs)
if ret:
print "%s packages added" % len(new_pkgs)
if err != []:
print "\n".join(err)
else:
print "\n".join(err)
else:
print "Synopsis: [-n] [-r] [-l] [-u]"