Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/pacman/pmfile.py27
-rw-r--r--test/pacman/pmtest.py25
2 files changed, 46 insertions, 6 deletions
diff --git a/test/pacman/pmfile.py b/test/pacman/pmfile.py
index 7f96f6ca..417550d6 100644
--- a/test/pacman/pmfile.py
+++ b/test/pacman/pmfile.py
@@ -20,7 +20,32 @@ import stat
import util
-class PacmanFile(object):
+class pmfile(object):
+ def __init__(self, path, content, mode=0o644):
+ self.path = path
+ self.content = content
+ self.mode = mode
+
+ def mkfile(self, root):
+ path = os.path.join(root, self.path)
+
+ dir_path = os.path.dirname(path)
+ if dir_path and not os.path.isdir(dir_path):
+ os.makedirs(dir_path, 0o755)
+
+ fd = open(path, "w")
+ if self.content:
+ fd.write(self.content)
+ if self.content[-1] != "\n":
+ fd.write("\n")
+ fd.close()
+
+ os.chmod(path, self.mode)
+
+ return path
+
+
+class snapshot(object):
"""File object
"""
diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py
index 7774a7bf..a1081cc6 100644
--- a/test/pacman/pmtest.py
+++ b/test/pacman/pmtest.py
@@ -179,10 +179,14 @@ class pmtest(object):
# Filesystem
vprint(" Populating file system")
for f in self.filesystem:
- vprint("\t%s" % f)
- path = util.mkfile(self.root, f, f)
- if os.path.isfile(path):
- os.utime(path, (355, 355))
+ if type(f) is pmfile.pmfile:
+ vprint("\t%s" % f.path)
+ f.mkfile(self.root);
+ else:
+ vprint("\t%s" % f)
+ path = util.mkfile(self.root, f, f)
+ if os.path.isfile(path):
+ os.utime(path, (355, 355))
for pkg in self.db["local"].pkgs:
vprint("\tinstalling %s" % pkg.fullname())
pkg.install_package(self.root)
@@ -193,10 +197,21 @@ class pmtest(object):
# Done.
vprint(" Taking a snapshot of the file system")
for filename in self.snapshots_needed():
- f = pmfile.PacmanFile(self.root, filename)
+ f = pmfile.snapshot(self.root, filename)
self.files.append(f)
vprint("\t%s" % f.name)
+ def add_hook(self, name, content):
+ if not name.endswith(".hook"):
+ name = name + ".hook"
+ path = os.path.join("etc/pacman.d/hooks/", name)
+ self.filesystem.append(pmfile.pmfile(path, content))
+
+ def add_script(self, name, content):
+ if not content.startswith("#!"):
+ content = "#!/bin/sh\n" + content
+ path = os.path.join("bin/", name)
+ self.filesystem.append(pmfile.pmfile(path, content, mode=0o755))
def snapshots_needed(self):
files = set()