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 mkfile(name
, data
= ""):
58 if filename
[-1] == "*":
59 filename
= filename
.rstrip("*")
60 if filename
.find(" -> ") != -1:
62 filename
, link
= filename
.split(" -> ")
63 elif filename
.find("|") != -1:
65 filename
, perms
= filename
.split("|")
66 if filename
[-1] == "/":
72 path
= os
.path
.dirname(filename
)
73 if path
and not os
.path
.isdir(path
):
74 os
.makedirs(path
, 0755)
82 os
.symlink(link
, os
.path
.basename(filename
))
85 fd
= file(filename
, "w")
92 os
.chmod(filename
, int(perms
, 8))
94 def mkcfgfile(filename
, root
, option
, db
):
97 for key
, value
in option
.iteritems():
98 data
.extend(["%s = %s" % (key
, j
) for j
in value
])
101 # sort by repo name so tests can predict repo order, rather than be
102 # subjects to the whims of python dict() ordering
103 for key
in sorted(db
.iterkeys()):
106 data
.append("[%s]\n" \
108 "Server = file://%s" \
109 % (value
.treename
, value
.getverify(), \
110 os
.path
.join(root
, SYNCREPO
, value
.treename
)))
111 for optkey
, optval
in value
.option
.iteritems():
112 data
.extend(["%s = %s" % (optkey
, j
) for j
in optval
])
114 mkfile(os
.path
.join(root
, filename
), "\n".join(data
))
121 def getmd5sum(filename
):
122 if not os
.path
.isfile(filename
):
124 fd
= open(filename
, "rb")
125 checksum
= hashlib
.md5()
127 block
= fd
.read(32 * 1024)
130 checksum
.update(block
)
132 return checksum
.hexdigest()
135 checksum
= hashlib
.md5()
136 checksum
.update("%s\n" % data
)
137 return checksum
.hexdigest()
145 path
= os
.environ
["PATH"].split(':')
147 f
= os
.path
.join(p
, filename
)
148 if os
.access(f
, os
.F_OK
):
152 def grep(filename
, pattern
):
153 pat
= re
.compile(pattern
)
154 myfile
= open(filename
, 'r')
163 if os
.path
.isdir(path
):
165 elif os
.path
.isfile(path
):
166 raise OSError("'%s' already exists and is not a directory" % path
)
167 os
.makedirs(path
, 0755)
169 # vim: set ts=4 sw=4 et: