2006-10-15 15:04:27 -04:00
|
|
|
#! /usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
# USA.
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import md5
|
|
|
|
import stat
|
|
|
|
|
|
|
|
|
|
|
|
# ALPM
|
|
|
|
PM_ROOT = "/"
|
|
|
|
PM_DBPATH = "var/lib/pacman"
|
2007-06-27 23:25:04 -04:00
|
|
|
PM_LOCK = "var/lib/pacman/db.lck"
|
2006-10-15 15:04:27 -04:00
|
|
|
PM_CACHEDIR = "var/cache/pacman/pkg"
|
|
|
|
PM_EXT_PKG = ".pkg.tar.gz"
|
|
|
|
PM_EXT_DB = ".db.tar.gz"
|
|
|
|
PM_PACNEW = ".pacnew"
|
|
|
|
PM_PACORIG = ".pacorig"
|
|
|
|
PM_PACSAVE = ".pacsave"
|
|
|
|
|
|
|
|
# Pacman
|
|
|
|
PACCONF = "etc/pacman.conf"
|
|
|
|
|
|
|
|
# Pactest
|
|
|
|
TMPDIR = "tmp"
|
|
|
|
SYNCREPO = "var/pub"
|
|
|
|
LOGFILE = "var/log/pactest.log"
|
|
|
|
|
|
|
|
verbose = 0
|
|
|
|
|
|
|
|
def err(msg):
|
2007-02-21 01:33:13 -05:00
|
|
|
print "error: " + msg
|
|
|
|
sys.exit(1)
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def vprint(msg):
|
2007-02-21 01:33:13 -05:00
|
|
|
if verbose:
|
|
|
|
print msg
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Methods to generate files
|
|
|
|
#
|
|
|
|
|
|
|
|
def getfilename(name):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
filename = ""
|
|
|
|
link = ""
|
2007-02-28 11:37:24 -05:00
|
|
|
if name.find(" -> ") != -1:
|
2007-02-21 01:33:13 -05:00
|
|
|
filename, link = name.split(" -> ")
|
|
|
|
elif name[-1] == "*":
|
|
|
|
filename = name.rstrip("*")
|
|
|
|
else:
|
|
|
|
filename = name
|
|
|
|
return filename
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def mkfile(name, data = ""):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
isaltered = 0
|
|
|
|
isdir = 0
|
|
|
|
islink = 0
|
|
|
|
link = ""
|
|
|
|
filename = ""
|
|
|
|
|
2007-02-28 11:37:24 -05:00
|
|
|
if name.find(" -> ") != -1:
|
2007-02-21 01:33:13 -05:00
|
|
|
islink = 1
|
|
|
|
filename, link = name.split(" -> ")
|
|
|
|
elif name[-1] == "*":
|
|
|
|
isaltered = 1
|
|
|
|
filename = name.rstrip("*")
|
|
|
|
else:
|
|
|
|
filename = name
|
|
|
|
if name[-1] == "/":
|
|
|
|
isdir = 1
|
|
|
|
|
|
|
|
if isdir:
|
|
|
|
path = filename
|
|
|
|
else:
|
|
|
|
path = os.path.dirname(filename)
|
|
|
|
try:
|
|
|
|
if path and not os.path.isdir(path):
|
|
|
|
os.makedirs(path, 0755)
|
|
|
|
except:
|
|
|
|
error("mkfile: could not create directory hierarchy '%s'" % path)
|
|
|
|
|
|
|
|
if isdir:
|
|
|
|
return
|
|
|
|
if islink:
|
|
|
|
curdir = os.getcwd()
|
|
|
|
os.chdir(path)
|
|
|
|
os.symlink(link, os.path.basename(filename))
|
|
|
|
os.chdir(curdir)
|
|
|
|
else:
|
|
|
|
fd = file(filename, "w")
|
|
|
|
if data:
|
|
|
|
fd.write(data)
|
|
|
|
if data[-1] != "\n":
|
|
|
|
fd.write("\n")
|
|
|
|
fd.close()
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def mkdescfile(filename, pkg):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
|
|
|
# desc
|
|
|
|
#data.append("pkgname = %s" % pkg.name)
|
|
|
|
#data.append("pkgver = %s" % pkg.version)
|
|
|
|
if pkg.desc:
|
|
|
|
data.append("pkgdesc = %s" % pkg.desc)
|
|
|
|
if pkg.url:
|
|
|
|
data.append("url = %s" % pkg.url)
|
|
|
|
if pkg.builddate:
|
|
|
|
data.append("builddate = %s" % pkg.builddate)
|
|
|
|
if pkg.packager:
|
|
|
|
data.append("packager = %s" % pkg.packager)
|
|
|
|
if pkg.size:
|
|
|
|
data.append("size = %s" % pkg.size)
|
|
|
|
if pkg.arch:
|
|
|
|
data.append("arch = %s" % pkg.arch)
|
|
|
|
for i in pkg.groups:
|
|
|
|
data.append("group = %s" % i)
|
|
|
|
for i in pkg.license:
|
|
|
|
data.append("license = %s" % i)
|
|
|
|
if pkg.md5sum:
|
|
|
|
data.append("md5sum = %s" % pkg.md5sum)
|
|
|
|
|
|
|
|
# depends
|
|
|
|
for i in pkg.replaces:
|
|
|
|
data.append("replaces = %s" % i)
|
|
|
|
for i in pkg.depends:
|
|
|
|
data.append("depend = %s" % i)
|
2007-11-02 18:26:31 -04:00
|
|
|
for i in pkg.optdepends:
|
|
|
|
data.append("optdepend = %s" % i)
|
2007-02-21 01:33:13 -05:00
|
|
|
for i in pkg.conflicts:
|
|
|
|
data.append("conflict = %s" % i)
|
|
|
|
for i in pkg.provides:
|
|
|
|
data.append("provides = %s" % i)
|
|
|
|
for i in pkg.backup:
|
|
|
|
data.append("backup = %s" % i)
|
|
|
|
if pkg.force:
|
|
|
|
data.append("force = 1")
|
|
|
|
|
|
|
|
mkfile(filename, "\n".join(data))
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def mkinstallfile(filename, install):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
data = []
|
|
|
|
for key, value in install.iteritems():
|
|
|
|
if value:
|
|
|
|
data.append("%s() {\n%s\n}" % (key, value))
|
|
|
|
|
|
|
|
mkfile(filename, "\n".join(data))
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def mkcfgfile(filename, root, option, db):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
# Options
|
|
|
|
data = ["[options]"]
|
|
|
|
for key, value in option.iteritems():
|
|
|
|
data.extend(["%s = %s" % (key, j) for j in value])
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
# Repositories
|
|
|
|
data.extend(["[%s]\n" \
|
|
|
|
"server = file://%s\n" \
|
2007-02-28 11:37:24 -05:00
|
|
|
% (value.treename, \
|
|
|
|
os.path.join(root, SYNCREPO, value.treename)) \
|
|
|
|
for key, value in db.iteritems() if key != "local"])
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-02-21 01:33:13 -05:00
|
|
|
mkfile(os.path.join(root, filename), "\n".join(data))
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# MD5 helpers
|
|
|
|
#
|
|
|
|
|
|
|
|
def getmd5sum(filename):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
fd = open(filename, "rb")
|
|
|
|
checksum = md5.new()
|
|
|
|
while 1:
|
|
|
|
block = fd.read(1048576)
|
|
|
|
if not block:
|
|
|
|
break
|
|
|
|
checksum.update(block)
|
|
|
|
fd.close()
|
|
|
|
digest = checksum.digest()
|
|
|
|
return "%02x"*len(digest) % tuple(map(ord, digest))
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def mkmd5sum(data):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
checksum = md5.new()
|
|
|
|
checksum.update("%s\n" % data)
|
|
|
|
digest = checksum.digest()
|
|
|
|
return "%02x"*len(digest) % tuple(map(ord, digest))
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Mtime helpers
|
|
|
|
#
|
|
|
|
|
|
|
|
def getmtime(filename):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
st = os.stat(filename)
|
|
|
|
return st[stat.ST_ATIME], st[stat.ST_MTIME], st[stat.ST_CTIME]
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
def diffmtime(mt1, mt2):
|
2007-02-21 01:33:13 -05:00
|
|
|
"""ORE: TBD
|
|
|
|
"""
|
|
|
|
return not mt1 == mt2
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Miscellaneous
|
|
|
|
#
|
|
|
|
|
|
|
|
def grep(filename, pattern):
|
2007-03-22 04:30:18 -04:00
|
|
|
lines = file(filename, 'r').readlines()
|
|
|
|
for line in lines:
|
|
|
|
if not line: break
|
2007-02-21 01:33:13 -05:00
|
|
|
if line.find(pattern) != -1:
|
2007-03-22 04:30:18 -04:00
|
|
|
return True
|
|
|
|
return False
|
2006-10-15 15:04:27 -04:00
|
|
|
|
2007-03-05 13:06:12 -05:00
|
|
|
def mkdir(dir):
|
|
|
|
if os.path.isdir(dir):
|
|
|
|
return
|
|
|
|
elif os.path.isfile(dir):
|
|
|
|
raise OSError("'%s' already exists and is not a directory" % dir)
|
|
|
|
else:
|
|
|
|
parent, thisdir = os.path.split(dir)
|
|
|
|
if parent: mkdir(parent) #recurse to make all parents
|
2007-03-05 17:13:33 -05:00
|
|
|
vprint("making dir %s" % thisdir)
|
2007-03-05 13:06:12 -05:00
|
|
|
if thisdir: os.mkdir(dir)
|
2006-10-15 15:04:27 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2007-02-21 01:33:13 -05:00
|
|
|
pass
|
|
|
|
# vim: set ts=4 sw=4 et:
|