summaryrefslogtreecommitdiff
path: root/test/pacman/util.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-23 21:35:32 -0500
committerDan McGee <dan@archlinux.org>2011-06-30 11:55:00 -0500
commit0ed848a9ea7a543192cef1ca78695a9046ee4e98 (patch)
tree195bba351892afdd328adf397607f74648850d24 /test/pacman/util.py
parent13235ba65ab55d852dbdc0acabdc047442e74e28 (diff)
pactest: create packages in memory
This is similar to what was just done for the sync databases. Move a few pieces around so we never need to actually write out the filesystem to create a package, and simply stream the tarfile out from the data we've collected. Once again, a few newline addition hacks and other things have to be left in place in order not to break everything; this time however most of the assumptions are in pactest and not libalpm. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'test/pacman/util.py')
-rw-r--r--test/pacman/util.py80
1 files changed, 47 insertions, 33 deletions
diff --git a/test/pacman/util.py b/test/pacman/util.py
index 0cf0eabe..dbe416f2 100644
--- a/test/pacman/util.py
+++ b/test/pacman/util.py
@@ -47,49 +47,63 @@ def vprint(msg):
# Methods to generate files
#
-def mkfile(name, data = ""):
- isdir = 0
- islink = 0
- setperms = 0
- filename = name
- link = ""
- perms = ""
-
+def getfileinfo(filename):
+ data = {
+ 'changed': False,
+ 'isdir': False,
+ 'islink': False,
+ 'link': None,
+ 'hasperms': False,
+ 'perms': None,
+ }
if filename[-1] == "*":
+ data["changed"] = True
filename = filename.rstrip("*")
if filename.find(" -> ") != -1:
- islink = 1
filename, link = filename.split(" -> ")
+ data["islink"] = True
+ data["link"] = link
elif filename.find("|") != -1:
- setperms = 1
filename, perms = filename.split("|")
+ data["hasperms"] = True
+ data["perms"] = int(perms, 8)
if filename[-1] == "/":
- isdir = 1
+ data["isdir"] = True
- if isdir:
- path = filename
- else:
- path = os.path.dirname(filename)
- if path and not os.path.isdir(path):
- os.makedirs(path, 0755)
+ data["filename"] = filename
+ return data
+
+def mkfile(base, name, data=""):
+ info = getfileinfo(name)
+ filename = info["filename"]
- if isdir:
+ path = os.path.join(base, filename)
+ if info["isdir"]:
+ if not os.path.isdir(path):
+ os.makedirs(path, 0755)
return
- if islink:
- curdir = os.getcwd()
- if path:
- os.chdir(path)
- os.symlink(link, os.path.basename(filename))
- os.chdir(curdir)
+
+ dir_path = os.path.dirname(path)
+ if dir_path and not os.path.isdir(dir_path):
+ os.makedirs(dir_path, 0755)
+
+ if info["islink"]:
+ os.symlink(info["link"], path)
else:
- fd = file(filename, "w")
- if data:
- fd.write(data)
- if data[-1] != "\n":
- fd.write("\n")
- fd.close()
- if setperms:
- os.chmod(filename, int(perms, 8))
+ writedata(path, data)
+
+ if info["perms"]:
+ os.chmod(path, info["perms"])
+
+def writedata(filename, data):
+ if isinstance(data, list):
+ data = "\n".join(data)
+ fd = file(filename, "w")
+ if data:
+ fd.write(data)
+ if data[-1] != "\n":
+ fd.write("\n")
+ fd.close()
def mkcfgfile(filename, root, option, db):
# Options
@@ -111,7 +125,7 @@ def mkcfgfile(filename, root, option, db):
for optkey, optval in value.option.iteritems():
data.extend(["%s = %s" % (optkey, j) for j in optval])
- mkfile(os.path.join(root, filename), "\n".join(data))
+ mkfile(root, filename, "\n".join(data))
#