3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 PM_DBPATH
= "var/lib/pacman"
27 PM_SYNCDBPATH
= "var/lib/pacman/sync"
28 PM_LOCK
= "var/lib/pacman/db.lck"
29 PM_CACHEDIR
= "var/cache/pacman/pkg"
30 PM_EXT_PKG
= ".pkg.tar.gz"
33 PACCONF
= "etc/pacman.conf"
38 LOGFILE
= "var/log/pactest.log"
47 # Methods to generate files
50 def getfileinfo(filename
):
59 if filename
[-1] == "*":
60 data
["changed"] = True
61 filename
= filename
.rstrip("*")
62 if filename
.find(" -> ") != -1:
63 filename
, link
= filename
.split(" -> ")
66 elif filename
.find("|") != -1:
67 filename
, perms
= filename
.split("|")
68 data
["hasperms"] = True
69 data
["perms"] = int(perms
, 8)
70 if filename
[-1] == "/":
73 data
["filename"] = filename
76 def mkfile(base
, name
, data
=""):
77 info
= getfileinfo(name
)
78 filename
= info
["filename"]
80 path
= os
.path
.join(base
, filename
)
82 if not os
.path
.isdir(path
):
83 os
.makedirs(path
, 0755)
86 dir_path
= os
.path
.dirname(path
)
87 if dir_path
and not os
.path
.isdir(dir_path
):
88 os
.makedirs(dir_path
, 0755)
91 os
.symlink(info
["link"], path
)
96 os
.chmod(path
, info
["perms"])
98 def writedata(filename
, data
):
99 if isinstance(data
, list):
100 data
= "\n".join(data
)
101 fd
= file(filename
, "w")
108 def mkcfgfile(filename
, root
, option
, db
):
111 for key
, value
in option
.iteritems():
112 data
.extend(["%s = %s" % (key
, j
) for j
in value
])
115 # sort by repo name so tests can predict repo order, rather than be
116 # subjects to the whims of python dict() ordering
117 for key
in sorted(db
.iterkeys()):
120 data
.append("[%s]\n" \
122 "Server = file://%s" \
123 % (value
.treename
, value
.getverify(), \
124 os
.path
.join(root
, SYNCREPO
, value
.treename
)))
125 for optkey
, optval
in value
.option
.iteritems():
126 data
.extend(["%s = %s" % (optkey
, j
) for j
in optval
])
128 mkfile(root
, filename
, "\n".join(data
))
135 def getmd5sum(filename
):
136 if not os
.path
.isfile(filename
):
138 fd
= open(filename
, "rb")
139 checksum
= hashlib
.md5()
141 block
= fd
.read(32 * 1024)
144 checksum
.update(block
)
146 return checksum
.hexdigest()
149 checksum
= hashlib
.md5()
150 checksum
.update("%s\n" % data
)
151 return checksum
.hexdigest()
159 path
= os
.environ
["PATH"].split(':')
161 f
= os
.path
.join(p
, filename
)
162 if os
.access(f
, os
.F_OK
):
166 def grep(filename
, pattern
):
167 pat
= re
.compile(pattern
)
168 myfile
= open(filename
, 'r')
177 if os
.path
.isdir(path
):
179 elif os
.path
.isfile(path
):
180 raise OSError("'%s' already exists and is not a directory" % path
)
181 os
.makedirs(path
, 0755)
183 # vim: set ts=4 sw=4 et: