mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
many many changes
db fixes should work fairly well now
This commit is contained in:
parent
828615ad07
commit
25f0a8bd50
1 changed files with 38 additions and 30 deletions
|
@ -48,35 +48,38 @@ class PackageDatabase:
|
||||||
def lookup(self, packagename):
|
def lookup(self, packagename):
|
||||||
warning("DB: Looking up package: " + packagename)
|
warning("DB: Looking up package: " + packagename)
|
||||||
q = self.cursor()
|
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):
|
if (q.rowcount != 0):
|
||||||
row = q.fetchone()
|
row = q.fetchone()
|
||||||
return row[0]
|
return row[0]
|
||||||
return None
|
return None
|
||||||
def insert(self, package, locationId):
|
def insert(self, package, locationId):
|
||||||
global repo_dir
|
|
||||||
warning("DB: Inserting package: " + package.name)
|
warning("DB: Inserting package: " + package.name)
|
||||||
|
global repo_dir
|
||||||
q = self.cursor()
|
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.name) + "', '" +
|
||||||
MySQLdb.escape_string(package.new.version) + "', '" +
|
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.desc)) + "', '" +
|
||||||
MySQLdb.escape_string(str(package.url)) + "', 3)")
|
MySQLdb.escape_string(str(package.url)) + "', 3)")
|
||||||
id = self.lookup(package.name)
|
id = self.lookup(package.name)
|
||||||
self.insertNewInfo(package, id, locationId)
|
self.insertNewInfo(package, id, locationId)
|
||||||
def update(self, id, package, locationId):
|
def update(self, id, package, locationId):
|
||||||
|
warning("DB: Updating package: " + package.name + " with id " + str(id))
|
||||||
global repo_dir
|
global repo_dir
|
||||||
warning("DB: Updating package: " + package.name)
|
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
q.execute("UPDATE Packages SET " +
|
q.execute("UPDATE Packages SET " +
|
||||||
"Version = '" + MySQLdb.escape_string(package.new.version) + "', " +
|
"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)) + "', " +
|
"Description = '" + MySQLdb.escape_string(str(package.desc)) + "', " +
|
||||||
"URL = '" + MySQLdb.escape_string(str(package.url)) + "', " +
|
"URL = '" + MySQLdb.escape_string(str(package.url)) + "', " +
|
||||||
"LocationID = " + str(locationId) + " " +
|
"LocationID = " + str(locationId) + " " +
|
||||||
"WHERE ID = " + str(id))
|
"WHERE ID = " + str(id))
|
||||||
self.clearOldInfo(id)
|
|
||||||
self.insertNewInfo(package, id, locationId)
|
self.insertNewInfo(package, id, locationId)
|
||||||
def remove(self, id, locationId):
|
def remove(self, id, locationId):
|
||||||
warning("DB: Removing package with id: " + str(id))
|
warning("DB: Removing package with id: " + str(id))
|
||||||
|
@ -95,6 +98,7 @@ class PackageDatabase:
|
||||||
return retval
|
return retval
|
||||||
self.createDummy(packagename, locationId)
|
self.createDummy(packagename, locationId)
|
||||||
def createDummy(self, packagename, locationId):
|
def createDummy(self, packagename, locationId):
|
||||||
|
warning("DB: Creating dummy package for: " + packagename)
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
q.execute("INSERT INTO Packages " +
|
q.execute("INSERT INTO Packages " +
|
||||||
"(Name, Description, LocationID, DummyPkg) " +
|
"(Name, Description, LocationID, DummyPkg) " +
|
||||||
|
@ -106,10 +110,14 @@ class PackageDatabase:
|
||||||
")")
|
")")
|
||||||
return self.lookup(packagename)
|
return self.lookup(packagename)
|
||||||
def insertNewInfo(self, package, id, locationId):
|
def insertNewInfo(self, package, id, locationId):
|
||||||
warning("DB: Inserting new package info for: " + package.name)
|
|
||||||
q = self.cursor()
|
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
|
# PackageSources
|
||||||
for source in package.sources:
|
for source in package.sources:
|
||||||
q.execute("INSERT INTO PackageSources (PackageID, Source) " +
|
q.execute("INSERT INTO PackageSources (PackageID, Source) " +
|
||||||
|
@ -184,7 +192,8 @@ def infoFromPkgbuildFileOld(filename):
|
||||||
def infoFromPkgbuildFile(filename):
|
def infoFromPkgbuildFile(filename):
|
||||||
# load the file with pacman library
|
# load the file with pacman library
|
||||||
pkg = pacman.load(filename)
|
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
|
# Functions for doing the final steps of execution
|
||||||
|
@ -229,18 +238,18 @@ def error(string):
|
||||||
|
|
||||||
# ARGUMENTS
|
# 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
|
# First call getopt
|
||||||
switch_list,args_proper = getopt.getopt(sys.argv[1:], 'n',
|
switch_list,args_proper = getopt.getopt(sys.argv[1:], 'n',
|
||||||
[ "delete", "paranoid", "complete" ])
|
[ "delete", "paranoid" ])
|
||||||
switches = {}
|
switches = {}
|
||||||
for switch in switch_list:
|
for switch in switch_list:
|
||||||
switches[switch[0]] = 1
|
switches[switch[0]] = 1
|
||||||
|
|
||||||
# Then handle the remaining arguments
|
# Then handle the remaining arguments
|
||||||
if (len(args_proper) < 3):
|
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)
|
sys.exit(-1)
|
||||||
|
|
||||||
repo_dir, pkgbuild_dir, build_dir = args_proper
|
repo_dir, pkgbuild_dir, build_dir = args_proper
|
||||||
|
@ -351,43 +360,40 @@ for c_file in c_files:
|
||||||
# Go through the package collection
|
# Go through the package collection
|
||||||
# 1 - if package has no new, place its old file on the "delete" list (and package on "dbremove")
|
# 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
|
# 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")
|
# 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)
|
# 4 - if new == old and paranoid is set, compare the files and error if not the same;
|
||||||
# 5 - if new == old, compare them and error and skip if files not the same
|
# otherwise just skip (no update)
|
||||||
# 6 - add entry to "delete" list for old file and "copy" list for
|
# 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")
|
# new file into repo dir (and package to "dbmodify")
|
||||||
|
|
||||||
for package in packages.values():
|
for package in packages.values():
|
||||||
# 1
|
# 1
|
||||||
|
print "TYPE 1"
|
||||||
if (package.new == None):
|
if (package.new == None):
|
||||||
delete.append(package.old.file)
|
delete.append(package.old.file)
|
||||||
dbremove.append(package)
|
dbremove.append(package)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 2
|
# 2
|
||||||
|
print "TYPE 2"
|
||||||
if (package.new.file == None):
|
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 + "!"
|
errstr = "No new package supplied for " + package.name + " " + package.new.version + "!"
|
||||||
if (switches.get("--complete") == True):
|
|
||||||
error(errstr)
|
error(errstr)
|
||||||
else:
|
|
||||||
warning("warning: " + errstr)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 3
|
# 3
|
||||||
|
print "TYPE 3"
|
||||||
if (package.old == None):
|
if (package.old == None):
|
||||||
copy.append(package.new.file)
|
copy.append(package.new.file)
|
||||||
dbmodify.append(package)
|
dbmodify.append(package)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 4
|
# 4
|
||||||
if (package.old.version < package.new.version):
|
print "TYPE 4"
|
||||||
delete.append(package.old.file)
|
|
||||||
copy.append(package.new.file)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 5
|
|
||||||
if (package.old.version == package.new.version):
|
if (package.old.version == package.new.version):
|
||||||
if (switches.get("--paranoid") == True):
|
if (switches.get("--paranoid") == True):
|
||||||
if not (areFilesIdentical(package.old.file, package.new.file)):
|
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:")
|
package.new.file + "' is different than the old one:")
|
||||||
if (switches.get("--delete") == True):
|
if (switches.get("--delete") == True):
|
||||||
warning(" Deleting the new file.")
|
warning(" Deleting the new file.")
|
||||||
|
delete.append(package.new.file)
|
||||||
else:
|
else:
|
||||||
warning(" Ignoring the new file.")
|
warning(" Ignoring the new file.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 6
|
# 5
|
||||||
|
print "TYPE 5"
|
||||||
delete.append(package.old.file)
|
delete.append(package.old.file)
|
||||||
copy.append(package.new.file)
|
copy.append(package.new.file)
|
||||||
dbmodify.append(package)
|
dbmodify.append(package)
|
||||||
|
|
Loading…
Add table
Reference in a new issue