36
35
helpers = [AptFacadeHelper]
38
def _add_package(self, packages_file, name, architecture="all",
39
version="1.0", control_fields=None):
40
if control_fields is None:
42
package_stanza = textwrap.dedent("""
48
Architecture: %(architecture)s
52
Description: description
53
""" % {"name": name, "version": version,
54
"architecture": architecture})
55
package_stanza = apt_pkg.rewrite_section(
56
apt_pkg.TagSection(package_stanza), apt_pkg.REWRITE_PACKAGE_ORDER,
57
control_fields.items())
58
append_file(packages_file, package_stanza + "\n")
60
def _add_system_package(self, name, architecture="all", version="1.0",
62
"""Add a package to the dpkg status file."""
63
system_control_fields = {"Status": "install ok installed"}
64
if control_fields is not None:
65
system_control_fields.update(control_fields)
67
self.dpkg_status, name, architecture=architecture, version=version,
68
control_fields=system_control_fields)
70
def _install_deb_file(self, path):
71
"""Fake the the given deb file is installed in the system."""
73
deb = apt_inst.DebFile(deb_file)
74
control = deb.control.extractdata("control")
76
lines = control.splitlines()
77
lines.insert(1, "Status: install ok installed")
78
status = "\n".join(lines)
79
append_file(self.dpkg_status, status + "\n\n")
81
def _add_package_to_deb_dir(self, path, name, version="1.0",
83
"""Add fake package information to a directory.
85
There will only be basic information about the package
86
available, so that get_packages() have something to return.
87
There won't be an actual package in the dir.
89
if control_fields is None:
92
os.path.join(path, "Packages"), name, version=version,
93
control_fields=control_fields)
95
def _touch_packages_file(self, deb_dir):
96
"""Make sure the Packages file get a newer mtime value.
98
If we rely on simply writing to the file to update the mtime, we
99
might end up with the same as before, since the resolution is
100
seconds, which causes apt to not reload the file.
102
packages_path = os.path.join(deb_dir, "Packages")
103
mtime = int(time.time() + 1)
104
os.utime(packages_path, (mtime, mtime))
106
37
def test_default_root(self):
108
39
C{AptFacade} can be created by not providing a root directory,