Merge lp:~james-w/linaro-image-tools/debug into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 161
Merged at revision: 198
Proposed branch: lp:~james-w/linaro-image-tools/debug
Merge into: lp:linaro-image-tools/11.11
Diff against target: 156 lines (+42/-0)
4 files modified
hwpack/__init__.py (+10/-0)
hwpack/builder.py (+8/-0)
hwpack/packages.py (+10/-0)
linaro-hwpack-create (+14/-0)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/debug
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+40116@code.launchpad.net

Description of the change

Hi,

This adds some output as the tool is running, and also adds a --debug
option that we can add more info to.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Seems basically fine. I'm a bit confused as to what is INFO and what is DEBUG. Would it make sense to have things that happen once per run at INFO and once per package at DEBUG? But I guess it's not that important.

Revision history for this message
James Westby (james-w) wrote :

On Fri, 05 Nov 2010 02:07:44 -0000, Michael Hudson-Doyle <email address hidden> wrote:
> Seems basically fine. I'm a bit confused as to what is INFO and what
> is DEBUG. Would it make sense to have things that happen once per run
> at INFO and once per package at DEBUG? But I guess it's not that
> important.

Yeah, I just made some simple ones INFO. I'll spend a few minutes
thinking about the desired output and add that as INFO, and leave the
rest as DEBUG.

Thanks,

James

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Meant to approve it the first time.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hwpack/__init__.py'
2--- hwpack/__init__.py 2010-08-27 18:27:58 +0000
3+++ hwpack/__init__.py 2010-11-04 16:16:05 +0000
4@@ -0,0 +1,10 @@
5+import logging
6+
7+
8+class NullHandler(logging.Handler):
9+ def emit(self, record):
10+ pass
11+
12+
13+h = NullHandler()
14+logging.getLogger(__name__).addHandler(h)
15
16=== modified file 'hwpack/builder.py'
17--- hwpack/builder.py 2010-09-14 18:09:01 +0000
18+++ hwpack/builder.py 2010-11-04 16:16:05 +0000
19@@ -1,3 +1,4 @@
20+import logging
21 import errno
22
23 from hwpack.config import Config
24@@ -5,6 +6,9 @@
25 from hwpack.packages import PackageFetcher
26
27
28+logger = logging.getLogger(__name__)
29+
30+
31 class ConfigFileMissing(Exception):
32
33 def __init__(self, filename):
34@@ -28,11 +32,13 @@
35
36 def build(self):
37 for architecture in self.config.architectures:
38+ logger.info("Building for %s" % architecture)
39 metadata = Metadata.from_config(
40 self.config, self.version, architecture)
41 hwpack = HardwarePack(metadata)
42 sources = self.config.sources
43 hwpack.add_apt_sources(sources)
44+ logger.info("Fetching packages")
45 fetcher = PackageFetcher(
46 sources.values(), architecture=architecture)
47 with fetcher:
48@@ -40,6 +46,8 @@
49 packages = fetcher.fetch_packages(
50 self.config.packages,
51 download_content=self.config.include_debs)
52+ logger.debug("Adding packages to hwpack")
53 hwpack.add_packages(packages)
54 with open(hwpack.filename(), 'w') as f:
55 hwpack.to_file(f)
56+ logger.info("Wrote %s" % hwpack.filename())
57
58=== modified file 'hwpack/packages.py'
59--- hwpack/packages.py 2010-09-24 20:00:05 +0000
60+++ hwpack/packages.py 2010-11-04 16:16:05 +0000
61@@ -1,3 +1,4 @@
62+import logging
63 import os
64 import shutil
65 import tempfile
66@@ -7,6 +8,9 @@
67 import apt_pkg
68
69
70+logger = logging.getLogger(__name__)
71+
72+
73 def get_packages_file(packages, extra_text=None):
74 """Get the Packages file contents indexing `packages`.
75
76@@ -280,6 +284,7 @@
77 of sources.
78 """
79 self.cleanup()
80+ logger.debug("Writing apt configs")
81 self.tempdir = tempfile.mkdtemp(prefix="hwpack-apt-cache-")
82 dirs = ["var/lib/dpkg",
83 "etc/apt/",
84@@ -299,6 +304,7 @@
85 with open(apt_conf, 'w') as f:
86 f.write('Apt {\nArchitecture "%s";\n}\n' % self.architecture)
87 self.cache = Cache(rootdir=self.tempdir, memonly=True)
88+ logger.debug("Updating apt cache")
89 self.cache.update()
90 self.cache.open()
91 return self
92@@ -393,6 +399,7 @@
93 :param packages: the list of package names to ignore.
94 :type packages: an iterable of str
95 """
96+ logger.debug("Ignoring %s" % packages)
97 for package in packages:
98 self.cache.cache[package].mark_install(auto_fix=False)
99 if self.cache.cache.broken_count:
100@@ -411,6 +418,7 @@
101 candidate = package.installed
102 base = os.path.basename(candidate.filename)
103 installed.append(FetchedPackage.from_apt(candidate, base))
104+ logger.debug("Ignored %s" % package.name)
105 self.cache.set_installed_packages(installed)
106 broken = [p.name for p in self.cache.cache
107 if p.is_inst_broken or p.is_now_broken]
108@@ -428,6 +436,7 @@
109 seen_packages.add(package.name)
110 all_packages = set(package_dict.keys())
111 for unseen_package in all_packages.difference(seen_packages):
112+ logger.debug("%s is ignored, skipping" % unseen_package)
113 del package_dict[unseen_package]
114
115 def fetch_packages(self, packages, download_content=True):
116@@ -474,6 +483,7 @@
117 acq = apt_pkg.Acquire(DummyProgress())
118 acqfiles = []
119 for package in self.cache.cache.get_changes():
120+ logger.debug("Fetching %s" % package)
121 candidate = package.candidate
122 base = os.path.basename(candidate.filename)
123 if package.name not in fetched:
124
125=== modified file 'linaro-hwpack-create'
126--- linaro-hwpack-create 2010-09-13 19:15:28 +0000
127+++ linaro-hwpack-create 2010-11-04 16:16:05 +0000
128@@ -1,6 +1,7 @@
129 #!/usr/bin/python
130
131 import argparse
132+import logging
133 import sys
134
135 from hwpack.builder import ConfigFileMissing, HardwarePackBuilder
136@@ -14,7 +15,20 @@
137 "from.")
138 parser.add_argument(
139 "VERSION", help="The version of the hardware pack to create.")
140+ parser.add_argument("--debug", action="store_true")
141 args = parser.parse_args()
142+ ch = logging.StreamHandler()
143+ ch.setLevel(logging.INFO)
144+ formatter = logging.Formatter("%(message)s")
145+ ch.setFormatter(formatter)
146+ logger = logging.getLogger("hwpack")
147+ logger.setLevel(logging.INFO)
148+ logger.addHandler(ch)
149+ if args.debug:
150+ ch.setLevel(logging.DEBUG)
151+ formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
152+ ch.setFormatter(formatter)
153+ logger.setLevel(logging.DEBUG)
154 try:
155 builder = HardwarePackBuilder(args.CONFIG_FILE, args.VERSION)
156 except ConfigFileMissing, e:

Subscribers

People subscribed via source and target branches