many many changes

db fixes
should work fairly well now
This commit is contained in:
pjmattal 2005-01-24 01:48:43 +00:00
parent 828615ad07
commit 25f0a8bd50

View file

@ -48,35 +48,38 @@ class PackageDatabase:
def lookup(self, packagename):
warning("DB: Looking up package: " + packagename)
q = self.cursor()
q.execute("SELECT ID FROM Packages WHERE Name = '" + MySQLdb.escape_string(packagename) + "'")
q.execute("SELECT ID FROM Packages WHERE Name = '" +
MySQLdb.escape_string(packagename) + "'")
if (q.rowcount != 0):
row = q.fetchone()
return row[0]
return None
def insert(self, package, locationId):
global repo_dir
warning("DB: Inserting package: " + package.name)
global repo_dir
q = self.cursor()
q.execute("INSERT INTO Packages (Name, Version, FSPath, LocationID, Description, URL) VALUES ('" +
q.execute("INSERT INTO Packages " +
"(Name, Version, FSPath, LocationID, Description, URL) VALUES ('" +
MySQLdb.escape_string(package.name) + "', '" +
MySQLdb.escape_string(package.new.version) + "', '" +
MySQLdb.escape_string(os.path.join(repo_dir, os.path.basename(package.new.file))) + "', '" +
MySQLdb.escape_string(
os.path.join(repo_dir, os.path.basename(package.new.file))) + "', '" +
MySQLdb.escape_string(str(package.desc)) + "', '" +
MySQLdb.escape_string(str(package.url)) + "', 3)")
id = self.lookup(package.name)
self.insertNewInfo(package, id, locationId)
def update(self, id, package, locationId):
warning("DB: Updating package: " + package.name + " with id " + str(id))
global repo_dir
warning("DB: Updating package: " + package.name)
q = self.cursor()
q.execute("UPDATE Packages SET " +
"Version = '" + MySQLdb.escape_string(package.new.version) + "', " +
"FSPath = '" + MySQLdb.escape_string(os.path.join(repo_dir, os.path.basename(package.new.file))) + "', " +
"FSPath = '" + MySQLdb.escape_string(
os.path.join(repo_dir, os.path.basename(package.new.file))) + "', " +
"Description = '" + MySQLdb.escape_string(str(package.desc)) + "', " +
"URL = '" + MySQLdb.escape_string(str(package.url)) + "', " +
"LocationID = " + str(locationId) + " " +
"WHERE ID = " + str(id))
self.clearOldInfo(id)
self.insertNewInfo(package, id, locationId)
def remove(self, id, locationId):
warning("DB: Removing package with id: " + str(id))
@ -95,6 +98,7 @@ class PackageDatabase:
return retval
self.createDummy(packagename, locationId)
def createDummy(self, packagename, locationId):
warning("DB: Creating dummy package for: " + packagename)
q = self.cursor()
q.execute("INSERT INTO Packages " +
"(Name, Description, LocationID, DummyPkg) " +
@ -106,10 +110,14 @@ class PackageDatabase:
")")
return self.lookup(packagename)
def insertNewInfo(self, package, id, locationId):
warning("DB: Inserting new package info for: " + package.name)
q = self.cursor()
# PackageContents (punt for now)
# first delete the old; this is never bad
self.clearOldInfo(id)
warning("DB: Inserting new package info for " + package.name +
" with id " + str(id))
# PackageSources
for source in package.sources:
q.execute("INSERT INTO PackageSources (PackageID, Source) " +
@ -184,7 +192,8 @@ def infoFromPkgbuildFileOld(filename):
def infoFromPkgbuildFile(filename):
# load the file with pacman library
pkg = pacman.load(filename)
return pkg.name, pkg.version + "-" + pkg.release, pkg.desc, pkg.url, pkg.depends, pkg.source
return (pkg.name, pkg.version + "-" + pkg.release, pkg.desc,
pkg.url, pkg.depends, pkg.source)
############################################################
# Functions for doing the final steps of execution
@ -229,18 +238,18 @@ def error(string):
# ARGUMENTS
#
# tupkgupdate [-n] [--delete] [--paranoid] [--complete] <repo_dir> <pkgbuild_dir> <build_dir>
# tupkgupdate [-n] [--delete] [--paranoid] <repo_dir> <pkgbuild_dir> <build_dir>
# First call getopt
switch_list,args_proper = getopt.getopt(sys.argv[1:], 'n',
[ "delete", "paranoid", "complete" ])
[ "delete", "paranoid" ])
switches = {}
for switch in switch_list:
switches[switch[0]] = 1
# Then handle the remaining arguments
if (len(args_proper) < 3):
print >>sys.stderr, "syntax: tupkgupdate [-n] [--delete] [--paranoid] [--complete] <repo_dir> <pkgbuild_tree> <build_tree>"
print >>sys.stderr, "syntax: tupkgupdate [-n] [--delete] [--paranoid] <repo_dir> <pkgbuild_tree> <build_tree>"
sys.exit(-1)
repo_dir, pkgbuild_dir, build_dir = args_proper
@ -351,43 +360,40 @@ for c_file in c_files:
# Go through the package collection
# 1 - if package has no new, place its old file on the "delete" list (and package on "dbremove")
# 2 - if package has a new but no new.file, and old file doesn't
# have the same version, then ignore (or error and skip if 'complete' set)
# have the same version, then error (because gensync won't rebuild)
# 3 - if package has no old, add new file to "copy" list into repo dir (and package on "dbmodify")
# 4 - if old > new, error and skip (no db change)
# 5 - if new == old, compare them and error and skip if files not the same
# 6 - add entry to "delete" list for old file and "copy" list for
# 4 - if new == old and paranoid is set, compare the files and error if not the same;
# otherwise just skip (no update)
# 5 - if we got here, it's a legit nontrivial new version which we allow
# add entry to "delete" list for old file and "copy" list for
# new file into repo dir (and package to "dbmodify")
for package in packages.values():
# 1
print "TYPE 1"
if (package.new == None):
delete.append(package.old.file)
dbremove.append(package)
continue
# 2
print "TYPE 2"
if (package.new.file == None):
if (package.old == None or package.old.file == None or package.old.version != package.new.version):
if (package.old == None or package.old.file == None or
package.old.version != package.new.version):
errstr = "No new package supplied for " + package.name + " " + package.new.version + "!"
if (switches.get("--complete") == True):
error(errstr)
else:
warning("warning: " + errstr)
continue
# 3
print "TYPE 3"
if (package.old == None):
copy.append(package.new.file)
dbmodify.append(package)
continue
# 4
if (package.old.version < package.new.version):
delete.append(package.old.file)
copy.append(package.new.file)
continue
# 5
print "TYPE 4"
if (package.old.version == package.new.version):
if (switches.get("--paranoid") == True):
if not (areFilesIdentical(package.old.file, package.new.file)):
@ -395,11 +401,13 @@ for package in packages.values():
package.new.file + "' is different than the old one:")
if (switches.get("--delete") == True):
warning(" Deleting the new file.")
delete.append(package.new.file)
else:
warning(" Ignoring the new file.")
continue
# 6
# 5
print "TYPE 5"
delete.append(package.old.file)
copy.append(package.new.file)
dbmodify.append(package)