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/>.
27 PM_DBPATH
= "var/lib/pacman"
28 PM_SYNCDBPATH
= "var/lib/pacman/sync"
29 PM_LOCK
= "var/lib/pacman/db.lck"
30 PM_CACHEDIR
= "var/cache/pacman/pkg"
31 PM_EXT_PKG
= ".pkg.tar.gz"
34 PACCONF
= "etc/pacman.conf"
39 LOGFILE
= "var/log/pactest.log"
48 # Methods to generate files
51 def getfilename(name
):
56 if filename
[-1] == "*":
57 filename
= filename
.rstrip("*")
58 if filename
.find(" -> ") != -1:
59 filename
, extra
= filename
.split(" -> ")
60 elif filename
.find("|") != -1:
61 filename
, extra
= filename
.split("|")
64 def mkfile(name
, data
= ""):
74 if filename
[-1] == "*":
75 filename
= filename
.rstrip("*")
76 if filename
.find(" -> ") != -1:
78 filename
, link
= filename
.split(" -> ")
79 elif filename
.find("|") != -1:
81 filename
, perms
= filename
.split("|")
82 if filename
[-1] == "/":
88 path
= os
.path
.dirname(filename
)
89 if path
and not os
.path
.isdir(path
):
90 os
.makedirs(path
, 0755)
98 os
.symlink(link
, os
.path
.basename(filename
))
101 fd
= file(filename
, "w")
108 os
.chmod(filename
, int(perms
, 8))
110 def mkinstallfile(filename
, install
):
114 for key
, value
in install
.iteritems():
116 data
.append("%s() {\n%s\n}" % (key
, value
))
118 mkfile(filename
, "\n".join(data
))
120 def mkcfgfile(filename
, root
, option
, db
):
125 for key
, value
in option
.iteritems():
126 data
.extend(["%s = %s" % (key
, j
) for j
in value
])
129 # sort by repo name so tests can predict repo order, rather than be
130 # subjects to the whims of python dict() ordering
131 for key
in sorted(db
.iterkeys()):
134 data
.append("[%s]\n" \
136 "Server = file://%s" \
137 % (value
.treename
, value
.getverify(), \
138 os
.path
.join(root
, SYNCREPO
, value
.treename
)))
139 for optkey
, optval
in value
.option
.iteritems():
140 data
.extend(["%s = %s" % (optkey
, j
) for j
in optval
])
142 mkfile(os
.path
.join(root
, filename
), "\n".join(data
))
149 def getmd5sum(filename
):
152 if not os
.path
.isfile(filename
):
153 print "file %s does not exist!" % filename
155 fd
= open(filename
, "rb")
156 checksum
= hashlib
.md5()
158 block
= fd
.read(32 * 1024)
161 checksum
.update(block
)
163 return checksum
.hexdigest()
168 checksum
= hashlib
.md5()
169 checksum
.update("%s\n" % data
)
170 return checksum
.hexdigest()
177 def getmtime(filename
):
180 if not os
.path
.exists(filename
):
181 print "path %s does not exist!" % filename
183 st
= os
.stat(filename
)
184 return st
[stat
.ST_ATIME
], st
[stat
.ST_MTIME
], st
[stat
.ST_CTIME
]
191 path
= os
.environ
["PATH"].split(':')
193 f
= os
.path
.join(p
, filename
)
194 if os
.access(f
, os
.F_OK
):
198 def grep(filename
, pattern
):
199 pat
= re
.compile(pattern
)
200 myfile
= open(filename
, 'r')
209 if os
.path
.isdir(path
):
211 elif os
.path
.isfile(path
):
212 raise OSError("'%s' already exists and is not a directory" % path
)
213 os
.makedirs(path
, 0755)
215 # vim: set ts=4 sw=4 et: