aboutsummaryrefslogtreecommitdiff
path: root/hwpack
diff options
context:
space:
mode:
authorJames Westby <james.westby@linaro.org>2010-12-15 16:14:38 -0500
committerJames Westby <james.westby@linaro.org>2010-12-15 16:14:38 -0500
commit1936092958b9570acd91077bc6ca410702cd85ff (patch)
tree2cec591f538b059a061e4d98c536d0ccb476f7ea /hwpack
parent5b2fd26a1a7698033658dc6aed78350159bcfe61 (diff)
parentad107781a06a19f82023779c4a05846f78ee0941 (diff)
Add a --debug option to hwpack-create.
Diffstat (limited to 'hwpack')
-rw-r--r--hwpack/__init__.py10
-rw-r--r--hwpack/builder.py8
-rw-r--r--hwpack/packages.py10
-rw-r--r--hwpack/tests/test_script.py4
4 files changed, 30 insertions, 2 deletions
diff --git a/hwpack/__init__.py b/hwpack/__init__.py
index e69de29..edb06f6 100644
--- a/hwpack/__init__.py
+++ b/hwpack/__init__.py
@@ -0,0 +1,10 @@
+import logging
+
+
+class NullHandler(logging.Handler):
+ def emit(self, record):
+ pass
+
+
+h = NullHandler()
+logging.getLogger(__name__).addHandler(h)
diff --git a/hwpack/builder.py b/hwpack/builder.py
index f37a83c..260b295 100644
--- a/hwpack/builder.py
+++ b/hwpack/builder.py
@@ -1,3 +1,4 @@
+import logging
import errno
from hwpack.config import Config
@@ -5,6 +6,9 @@ from hwpack.hardwarepack import HardwarePack, Metadata
from hwpack.packages import PackageFetcher
+logger = logging.getLogger(__name__)
+
+
class ConfigFileMissing(Exception):
def __init__(self, filename):
@@ -28,11 +32,13 @@ class HardwarePackBuilder(object):
def build(self):
for architecture in self.config.architectures:
+ logger.info("Building for %s" % architecture)
metadata = Metadata.from_config(
self.config, self.version, architecture)
hwpack = HardwarePack(metadata)
sources = self.config.sources
hwpack.add_apt_sources(sources)
+ logger.info("Fetching packages")
fetcher = PackageFetcher(
sources.values(), architecture=architecture)
with fetcher:
@@ -40,7 +46,9 @@ class HardwarePackBuilder(object):
packages = fetcher.fetch_packages(
self.config.packages,
download_content=self.config.include_debs)
+ logger.debug("Adding packages to hwpack")
hwpack.add_packages(packages)
hwpack.add_dependency_package(self.config.packages)
with open(hwpack.filename(), 'w') as f:
hwpack.to_file(f)
+ logger.info("Wrote %s" % hwpack.filename())
diff --git a/hwpack/packages.py b/hwpack/packages.py
index a76d4b7..9a31efa 100644
--- a/hwpack/packages.py
+++ b/hwpack/packages.py
@@ -1,4 +1,5 @@
import hashlib
+import logging
import os
import re
import shutil
@@ -13,6 +14,9 @@ import apt_pkg
from debian.debfile import DebFile
+logger = logging.getLogger(__name__)
+
+
def get_packages_file(packages, extra_text=None):
"""Get the Packages file contents indexing `packages`.
@@ -411,6 +415,7 @@ class IsolatedAptCache(object):
of sources.
"""
self.cleanup()
+ logger.debug("Writing apt configs")
self.tempdir = tempfile.mkdtemp(prefix="hwpack-apt-cache-")
dirs = ["var/lib/dpkg",
"etc/apt/",
@@ -432,6 +437,7 @@ class IsolatedAptCache(object):
'Apt {\nArchitecture "%s";\n'
'Install-Recommends "true";\n}\n' % self.architecture)
self.cache = Cache(rootdir=self.tempdir, memonly=True)
+ logger.debug("Updating apt cache")
self.cache.update()
self.cache.open()
return self
@@ -526,6 +532,7 @@ class PackageFetcher(object):
:param packages: the list of package names to ignore.
:type packages: an iterable of str
"""
+ logger.debug("Ignoring %s" % packages)
for package in packages:
self.cache.cache[package].mark_install(auto_fix=False)
if self.cache.cache.broken_count:
@@ -544,6 +551,7 @@ class PackageFetcher(object):
candidate = package.installed
base = os.path.basename(candidate.filename)
installed.append(FetchedPackage.from_apt(candidate, base))
+ logger.debug("Ignored %s" % package.name)
self.cache.set_installed_packages(installed)
broken = [p.name for p in self.cache.cache
if p.is_inst_broken or p.is_now_broken]
@@ -561,6 +569,7 @@ class PackageFetcher(object):
seen_packages.add(package.name)
all_packages = set(package_dict.keys())
for unseen_package in all_packages.difference(seen_packages):
+ logger.debug("%s is ignored, skipping" % unseen_package)
del package_dict[unseen_package]
def fetch_packages(self, packages, download_content=True):
@@ -607,6 +616,7 @@ class PackageFetcher(object):
acq = apt_pkg.Acquire(DummyProgress())
acqfiles = []
for package in self.cache.cache.get_changes():
+ logger.debug("Fetching %s" % package)
candidate = package.candidate
base = os.path.basename(candidate.filename)
if package.name not in fetched:
diff --git a/hwpack/tests/test_script.py b/hwpack/tests/test_script.py
index b24ed4d..1cab08c 100644
--- a/hwpack/tests/test_script.py
+++ b/hwpack/tests/test_script.py
@@ -57,14 +57,14 @@ class ScriptTests(TestCaseWithFixtures):
def test_errors_on_missing_configfile_argument(self):
stdout, stderr = self.run_script([], expected_returncode=2)
self.assertEqual(
- "usage: linaro-hwpack-create [-h] CONFIG_FILE VERSION\n"
+ "usage: linaro-hwpack-create [-h] [--debug] CONFIG_FILE VERSION\n"
"linaro-hwpack-create: error: too few arguments\n", stderr)
self.assertEqual("", stdout)
def test_errors_on_missing_version_argument(self):
stdout, stderr = self.run_script(["somefile"], expected_returncode=2)
self.assertEqual(
- "usage: linaro-hwpack-create [-h] CONFIG_FILE VERSION\n"
+ "usage: linaro-hwpack-create [-h] [--debug] CONFIG_FILE VERSION\n"
"linaro-hwpack-create: error: too few arguments\n", stderr)
self.assertEqual("", stdout)