Merge lp:~sylvain-pineau/checkbox/filter_packages_removal into lp:checkbox

Proposed by Sylvain Pineau
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 2550
Merged at revision: 2550
Proposed branch: lp:~sylvain-pineau/checkbox/filter_packages_removal
Merge into: lp:checkbox
Diff against target: 190 lines (+0/-183)
1 file modified
checkbox-old/scripts/filter_packages (+0/-183)
To merge this branch: bzr merge lp:~sylvain-pineau/checkbox/filter_packages_removal
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+198523@code.launchpad.net

Description of the change

this MR removes the unused filter_packages script.

Unused in checkbox/checkbox-certification/checkbox-oem.

Another benefit of this removal is that it will reduce the size of the future support package.
See https://blueprints.launchpad.net/checkbox/+spec/python3-checkbox-split.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'checkbox-old/scripts/filter_packages'
2--- checkbox-old/scripts/filter_packages 2013-05-29 07:50:30 +0000
3+++ checkbox-old/scripts/filter_packages 1970-01-01 00:00:00 +0000
4@@ -1,183 +0,0 @@
5-#!/usr/bin/env python3
6-
7-import os
8-import sys
9-import apt
10-import logging
11-
12-from optparse import OptionParser
13-from tempfile import TemporaryFile
14-
15-from checkbox.lib.log import set_logging
16-from checkbox.lib.redirect import RedirectEcho, RedirectTee
17-from checkbox.lib.template_i18n import TemplateI18n
18-
19-from checkbox.resource import ResourceMap
20-
21-
22-DEFAULT_LOG_LEVEL = "critical"
23-DEFAULT_OUTPUT = "-"
24-
25-
26-def get_redirect_file(input, output):
27- temp = TemporaryFile()
28- tee = RedirectTee(output, temp)
29- echo = RedirectEcho(input, tee)
30- echo.read()
31-
32- temp.seek(0)
33- return temp
34-
35-
36-def get_package_names(file):
37- package_names = set()
38-
39- class PackageObject(object):
40-
41- def __init__(self, compare):
42- self._compare = compare
43-
44- def __eq__(self, other):
45- package_names.add(other)
46- return self._compare
47-
48- # In order to read the package names from the requires field
49- # in messages, it is necessary to trick eval into thinking that
50- # package.name exists using the PackageResource. The problem is
51- # that since we don't have access to the expression tree, an 'or'
52- # operator will only evaluate the left hand side if it is true
53- # and an 'and' operator will only evaluate the left hand side if
54- # it is false. The solution is to compare against both zero and
55- # non-zero comparison results. Caveat, this doesn't work when
56- # both operators are used: foo or (bar and baz)
57- resource_0 = ResourceMap()
58- resource_0["package"] = [{"name": PackageObject(compare=True)}]
59- resource_1 = ResourceMap()
60- resource_1["package"] = [{"name": PackageObject(compare=True)}]
61-
62- template = TemplateI18n()
63- messages = template.load_file(file)
64- for message in messages:
65- if "requires_extended" in message:
66- requires = message["requires_extended"].split("\n")
67-
68- elif "requires" in message:
69- requires = [message["requires"]]
70-
71- else:
72- requires = []
73-
74- for require in requires:
75- resource_0.eval(require)
76- resource_1.eval(require)
77-
78- return list(package_names)
79-
80-
81-def install_package_names(names):
82- class CapturedInstallProgress(apt.InstallProgress):
83-
84- def fork(self):
85- self.stdout = TemporaryFile()
86- self.stderr = TemporaryFile()
87- p = os.fork()
88- if p == 0:
89- os.dup2(self.stdout.fileno(), sys.stdout.fileno())
90- os.dup2(self.stderr.fileno(), sys.stderr.fileno())
91- return p
92-
93- cache = apt.Cache()
94- for name in names:
95- if name in cache:
96- cache[name].markInstall()
97-
98- os.environ['DEBIAN_FRONTEND'] = 'noninteractive'
99- install_progress = CapturedInstallProgress()
100-
101- try:
102- cache.commit(None, install_progress)
103-
104- # Process stdout
105- install_progress.stdout.seek(0)
106- stdout = install_progress.stdout.read()
107- install_progress.stdout.close()
108- if stdout:
109- logging.debug(stdout)
110-
111- # Process stderr
112- install_progress.stderr.seek(0)
113- stderr = install_progress.stderr.read()
114- install_progress.stderr.close()
115- if stderr:
116- logging.error(stderr)
117-
118- except apt.cache.FetchCancelledException as e:
119- return False
120-
121- except (apt.cache.LockFailedException, apt.cache.FetchFailedException) as e:
122- logging.warning('Package fetching failed: %s', str(e))
123- raise SystemError(str(e))
124-
125- return True
126-
127-
128-def main(args):
129- usage = "Usage: %prog [OPTIONS] [FILE]"
130- parser = OptionParser(usage=usage)
131- parser.add_option("--dry-run",
132- action="store_true",
133- help="do not modify system")
134- parser.add_option("-l", "--log", metavar="FILE",
135- help="log file where to send output")
136- parser.add_option("--log-level",
137- default=DEFAULT_LOG_LEVEL,
138- help="one of debug, info, warning, error or critical")
139- parser.add_option("-o", "--output",
140- default=DEFAULT_OUTPUT,
141- help="output file, - for stdout")
142- (options, args) = parser.parse_args(args)
143-
144- # Set logging early
145- set_logging(options.log_level, options.log)
146-
147- # Parse options
148- if not options.dry_run and os.getuid():
149- parser.error("Must be run as root to modify the system")
150-
151- if options.output == "-":
152- output_file = sys.stdout
153-
154- else:
155- try:
156- output_file = open(options.output, "w")
157- except IOError as e:
158- parser.error("%s: %s" % (options.output, e.strerror))
159-
160- # Parse args
161- if len(args) > 1:
162- parser.error("Can only specify zero or one file")
163-
164- if args:
165- filename = args[0]
166- try:
167- input_file = open(filename, "r")
168- except IOError as e:
169- parser.error("%s: %s" % (filename, e.strerror))
170-
171- else:
172- input_file = sys.stdin
173-
174- # Get packages
175- file = get_redirect_file(input_file, output_file)
176- package_names = get_package_names(file)
177-
178- # Install packages
179- if not options.dry_run:
180- if not install_package_names(package_names):
181- parser.error("Failed to fetch packages")
182-
183- return 0
184-
185-
186-if __name__ == "__main__":
187- sys.exit(main(sys.argv[1:]))
188
189=== removed symlink 'plainbox-provider-checkbox/provider_bin/filter_packages'
190=== target was u'../../checkbox-old/scripts/filter_packages'

Subscribers

People subscribed via source and target branches