-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathyankpackages
More file actions
executable file
·124 lines (105 loc) · 4.21 KB
/
yankpackages
File metadata and controls
executable file
·124 lines (105 loc) · 4.21 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
#!/usr/bin/env python
"""Destroy Packages"""
import argparse
import configparser
from Packagecloud import abort
from Packagecloud import destroy_package
from Packagecloud import get_all_packages
from Packagecloud import show_packagelist
def configure():
"""Configure"""
parser = argparse.ArgumentParser()
parser.add_argument('--config', required=True,
help='Config file')
parser.add_argument('--srcrepo', required=True,
help='Source Repository')
parser.add_argument('--interactive', action='store_true',
help='Interactive Mode')
parser.add_argument('--force', action='store_true',
help='Skip confirmation prompt')
parser.add_argument('--distro', required=False,
help='Filter selection by distro')
parser.add_argument('--version', required=False,
help='Filter selection by package version')
parser.add_argument('--name', required=False,
help='Filter selection by package name')
parser.add_argument('--match', required=False,
help='Filter selection by filename substring match')
parser.add_argument('--type', required=False,
help='Filter selection by package type')
parser.add_argument('--debug', action='store_true',
help='Print debug output')
args = parser.parse_args()
config = configparser.SafeConfigParser()
config.read(args.config)
token = config.get('packagecloud', 'token')
http_scheme = config.get('packagecloud', 'http_scheme')
api_domain = config.get('packagecloud', 'api_domain')
api_version = config.get('packagecloud', 'api_version')
conf = {
'domain_base': '{}://{}:@{}'.format(
http_scheme, token, api_domain),
'url_base': '{}://{}:@{}/api/{}'.format(
http_scheme, token, api_domain, api_version),
'repouser': config.get('packagecloud', 'repo_user'),
'srcrepo': args.srcrepo,
'debug': args.debug,
'interactive': args.interactive,
'force': args.force,
'distro': args.distro,
'version': args.version,
'name': args.name,
'type': args.type,
'match': args.match,
'args': args
}
return conf
def main():
"""Main"""
conf = configure()
packages = get_all_packages(conf['repouser'], conf['srcrepo'], conf)
if not conf['force']:
show_packagelist(conf['repouser'], conf['srcrepo'], packages,
conf['distro'], conf['version'], conf['name'],
conf['match'], conf['type'])
if not conf['interactive'] and not conf['force']:
yankall = input("Are you sure you want to yank all (y/N)? "). \
lower() == 'y'
if not yankall:
abort('Aborted', 1)
yancount = 0
skpcount = 0
errcount = 0
yank = True
for package in packages:
if conf['distro'] and not package['distro_version'] == conf['distro']:
continue
elif conf['version'] and not package['version'] == conf['version']:
continue
elif conf['name'] and not package['name'] == conf['name']:
continue
elif conf['type'] and not conf['type'] == package['type']:
continue
elif conf['match'] and not conf['match'] in package['filename']:
continue
print('Going to yank {:<45} from {:>15}/{:<15} '.format(
package['filename'], conf['repouser'], conf['srcrepo']), end='')
if conf['interactive']:
yank = input("Yank this package (y/N)? ").lower() == 'y'
if yank:
yankresult = destroy_package(package, conf)
if yankresult:
print('[OK]')
yancount += 1
else:
print('[ERROR]')
errcount += 1
else:
print('Skipped {}'.format(package['filename']))
skpcount += 1
print('-----------------------------------------')
print('Total packages processed: ', (yancount + skpcount + errcount))
print('Yanked: ', yancount)
print('Skipped: ', skpcount)
print('Errors: ', errcount)
main()