-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsppa
More file actions
executable file
·126 lines (113 loc) · 3.38 KB
/
lsppa
File metadata and controls
executable file
·126 lines (113 loc) · 3.38 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
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
122
123
124
125
126
#!/usr/bin/python3
# Author: Chris Johnston <cjohnston@ubuntu.com>
# Initial inspiration from:
# https://gist.github.com/nathan-osman/b9158d058cc45916dcd20a591b66d0b4
from argparse import ArgumentParser
from sys import exit
try:
from launchpadlib.launchpad import Launchpad
from tabulate import tabulate
except ImportError:
print("python3-launchpadlib and python3-tabulate are required")
exit(1)
cachedir = "~/.launchpadlib/cache/"
def login(args):
if args.staging:
lp = Launchpad.login_anonymously(
'PPA Testing',
'staging',
cachedir,
version='devel',
)
else:
lp = Launchpad.login_anonymously(
'PPA Testing',
'production',
cachedir,
version='devel',
)
return lp
def fetch_packages(args):
launchpad = login(args)
user = launchpad.people[args.user]
archive = user.getPPAByName(name=args.ppa)
print("Retrieving packages...\n\n")
d = []
packages = archive.getPublishedBinaries(
binary_name=args.package,
exact_match=args.exact,
status=args.status,
)
for b in packages:
s = b.distro_arch_series
d.append((
b.binary_package_name,
b.binary_package_version,
s.display_name,
))
print(tabulate(d, headers=(
'Name',
'Version',
'Series',
)))
def parse_arguements(args=None):
parser = ArgumentParser(prog='ppa')
parser.add_argument(
'-v', '--verbosity', action='store', dest='verbosity', default=1,
type=int, choices=[1, 2, 3], help='Verbosity level; 1=errors only, '
'2=verbose output, 3=very verbose output. NOTE: currently only '
'supports httplib2.debuglevel 1',
)
parser.add_argument(
'--staging',
help="If passed, uses the staging instance of Launchpad.",
action="store_true",
required=False,
)
subparsers = parser.add_subparsers(title='actions', help='commands')
packages_parser = subparsers.add_parser(
'packages',
help="Get infomration about packages in a PPA",
)
packages_parser.add_argument(
'--user',
help="PPA Owner's Launchpad ID (can be a team)",
required=True,
)
packages_parser.add_argument(
'--ppa',
help="Launchpad ID or team name and name of PPA to look at",
required=True,
)
packages_parser.add_argument(
'--package',
help="Name of package to look at. Leaving blank will print all",
required=False,
)
packages_parser.add_argument(
'--exact',
help="If passed, only get packages that match the exact name.",
action="store_true",
required=False,
)
packages_parser.add_argument(
'--status',
help="View packages with a specific status. Default: Published",
required=False,
default="Published",
choices=["Pending", "Published", "Superseded", "Deleted", "Obsolete"],
)
packages_parser.set_defaults(func=fetch_packages)
return parser.parse_args(args)
def main(args=None):
try:
args = parse_arguements(args)
if args.verbosity > 1:
import httplib2
httplib2.debuglevel = 1
args.func(args)
return 0
except Exception:
return 1
if __name__ == '__main__':
exit(main())