13
18
def set_up(self, test_case):
14
19
test_case.apt_root = test_case.makeDir()
15
test_case.dpkg_status = os.path.join(
20
self.dpkg_status = os.path.join(
16
21
test_case.apt_root, "var", "lib", "dpkg", "status")
17
22
test_case.facade = AptFacade(root=test_case.apt_root)
18
23
test_case.facade.refetch_package_index = True
24
test_case._add_system_package = self._add_system_package
25
test_case._install_deb_file = self._install_deb_file
26
test_case._add_package_to_deb_dir = self._add_package_to_deb_dir
27
test_case._touch_packages_file = self._touch_packages_file
29
def _add_package(self, packages_file, name, architecture="all",
30
version="1.0", control_fields=None):
31
if control_fields is None:
33
package_stanza = textwrap.dedent("""
39
Architecture: %(architecture)s
43
Description: description
44
""" % {"name": name, "version": version,
45
"architecture": architecture})
46
package_stanza = apt_pkg.rewrite_section(
47
apt_pkg.TagSection(package_stanza), apt_pkg.REWRITE_PACKAGE_ORDER,
48
control_fields.items())
49
append_file(packages_file, "\n" + package_stanza + "\n")
51
def _add_system_package(self, name, architecture="all", version="1.0",
53
"""Add a package to the dpkg status file."""
54
system_control_fields = {"Status": "install ok installed"}
55
if control_fields is not None:
56
system_control_fields.update(control_fields)
58
self.dpkg_status, name, architecture=architecture, version=version,
59
control_fields=system_control_fields)
61
def _install_deb_file(self, path):
62
"""Fake the the given deb file is installed in the system."""
64
deb = apt_inst.DebFile(deb_file)
65
control = deb.control.extractdata("control")
67
lines = control.splitlines()
68
lines.insert(1, "Status: install ok installed")
69
status = "\n".join(lines)
70
append_file(self.dpkg_status, status + "\n\n")
72
def _add_package_to_deb_dir(self, path, name, version="1.0",
74
"""Add fake package information to a directory.
76
There will only be basic information about the package
77
available, so that get_packages() have something to return.
78
There won't be an actual package in the dir.
80
if control_fields is None:
83
os.path.join(path, "Packages"), name, version=version,
84
control_fields=control_fields)
86
def _touch_packages_file(self, deb_dir):
87
"""Make sure the Packages file get a newer mtime value.
89
If we rely on simply writing to the file to update the mtime, we
90
might end up with the same as before, since the resolution is
91
seconds, which causes apt to not reload the file.
93
packages_path = os.path.join(deb_dir, "Packages")
94
mtime = int(time.time() + 1)
95
os.utime(packages_path, (mtime, mtime))
21
98
class SimpleRepositoryHelper(object):