-
Notifications
You must be signed in to change notification settings - Fork 23
/
remove_packages.py
executable file
·69 lines (52 loc) · 2.39 KB
/
remove_packages.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
68
69
#!/usr/bin/env python
# This is a script to remove packages from all repos quickly. It will prompt to show what would happen (using listfilter) and the remove using removefilter.
from __future__ import print_function
import argparse
import subprocess
import sys
import time
DISTROS = ['precise', 'quantal', 'raring', 'saucy', 'trusty', 'utopic', 'vivid']
REPOS = ['/var/www/repos/ros_bootstrap',]
import argparse
parser = argparse.ArgumentParser(description='Find and remove packages from ROS repos.')
parser.add_argument('regex',
help='the regex to use in reprepro')
parser.add_argument('--repo', dest='repos', action='append', default=[],
help="Repos to operate on. Default: %s" % REPOS)
parser.add_argument('--distro', dest='distros', action='append', default=[],
help="Distros to operate on. Default: %s" % DISTROS)
parser.add_argument('--add', dest='add', action='store_true', default=False,
help="Add the filename defined as positional argument.")
parser.add_argument('-n', dest='dry_run', action='store_true', default=False,
help="Dry run do not execute, only echo the commands.")
args = parser.parse_args()
if not args.repos:
args.repos = REPOS
if not args.distros:
args.distros = DISTROS
def apply_command_template(repo, command_arg, distro, regex, dry_run=False):
command_template = '/usr/bin/reprepro -b %(repo)s -V %(command_arg)s %(distro)s' % locals()
if dry_run:
command_template = 'echo ' + command_template
_cmd = command_template.split() + [regex]
print("Running %s" % _cmd)
subprocess.Popen(_cmd)
# sleep to let the lock file cleanup before iterating
print('Sleeping to allow lock reset')
time.sleep(4.0)
for repo in args.repos:
for distro in args.distros:
if args.add:
apply_command_template(repo, 'includedeb', distro, args.regex, args.dry_run)
else:
apply_command_template(repo, 'listfilter', distro, args.regex, args.dry_run)
if args.add:
# short circuit, add was already done
sys.exit(0)
confirmation = raw_input('Would you like to remove these packages? If so type "yes":')
if confirmation != "yes":
print('You did not enter "yes" exiting.')
sys.exit(1)
for repo in args.repos:
for distro in args.distros:
apply_command_template(repo, 'removefilter', distro, args.regex, args.dry_run)