mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Rework tupkgupdate scripts.
Most work is done on tupkgupdate. Fix some indentation problems. Add some whitespace for style points. Add a new --config switch to specify a config file path. Add a new usage() function that documents the switches more clearly. Delete all gensync code. Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
parent
d210584afd
commit
b513130f3a
3 changed files with 86 additions and 54 deletions
|
@ -1,23 +1,21 @@
|
||||||
#!/usr/bin/python -O
|
#!/usr/bin/python -O
|
||||||
|
|
||||||
import re, os, sys, pacman, getopt
|
import re
|
||||||
import MySQLdb, MySQLdb.connections
|
import os
|
||||||
|
import sys
|
||||||
|
import pacman
|
||||||
|
import getopt
|
||||||
|
import MySQLdb
|
||||||
|
import MySQLdb.connections
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# Deal with configuration
|
# Deal with configuration
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
conffile = '/home/aur/tupkgs.conf'
|
conffile = '/etc/tupkgs.conf'
|
||||||
|
|
||||||
if not os.path.isfile(conffile):
|
|
||||||
print "Error: cannot access config file ("+conffile+")"
|
|
||||||
usage(argv[0])
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(conffile)
|
|
||||||
config_use_db = config.has_section('mysql')
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
|
@ -45,12 +43,14 @@ class PackageDatabase:
|
||||||
self.password = password
|
self.password = password
|
||||||
self.dbname = dbname
|
self.dbname = dbname
|
||||||
self.connection = MySQLdb.connect(host=host, user=user, passwd=password, db=dbname)
|
self.connection = MySQLdb.connect(host=host, user=user, passwd=password, db=dbname)
|
||||||
|
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
try:
|
try:
|
||||||
self.connection.ping()
|
self.connection.ping()
|
||||||
except MySQLdb.OperationalError:
|
except MySQLdb.OperationalError:
|
||||||
self.connection = MySQLdb.connect(host=self.host, user=self.user, passwd=self.password, db=self.dbname)
|
self.connection = MySQLdb.connect(host=self.host, user=self.user, passwd=self.password, db=self.dbname)
|
||||||
return self.connection.cursor()
|
return self.connection.cursor()
|
||||||
|
|
||||||
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()
|
||||||
|
@ -60,12 +60,14 @@ class PackageDatabase:
|
||||||
row = q.fetchone()
|
row = q.fetchone()
|
||||||
return row[0]
|
return row[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getCategoryID(self, package):
|
def getCategoryID(self, package):
|
||||||
category_id = self.lookupCategory(package.category)
|
category_id = self.lookupCategory(package.category)
|
||||||
if (category_id == None):
|
if (category_id == None):
|
||||||
category_id = 1
|
category_id = 1
|
||||||
warning("DB: Got category ID '" + str(category_id) + "' for package '" + package.name + "'")
|
warning("DB: Got category ID '" + str(category_id) + "' for package '" + package.name + "'")
|
||||||
return category_id
|
return category_id
|
||||||
|
|
||||||
def insert(self, package, locationId):
|
def insert(self, package, locationId):
|
||||||
warning("DB: Inserting package: " + package.name)
|
warning("DB: Inserting package: " + package.name)
|
||||||
global repo_dir
|
global repo_dir
|
||||||
|
@ -83,6 +85,7 @@ class PackageDatabase:
|
||||||
MySQLdb.escape_string(str(package.url)) + "')")
|
MySQLdb.escape_string(str(package.url)) + "')")
|
||||||
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))
|
warning("DB: Updating package: " + package.name + " with id " + str(id))
|
||||||
global repo_dir
|
global repo_dir
|
||||||
|
@ -95,7 +98,7 @@ class PackageDatabase:
|
||||||
os.path.join(repo_dir, os.path.basename(package.new.file))) + "', " +
|
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)) + "', " +
|
||||||
"DummyPkg = 0, " +
|
"DummyPkg = 0, " +
|
||||||
"SubmittedTS = UNIX_TIMESTAMP(), " +
|
"SubmittedTS = UNIX_TIMESTAMP(), " +
|
||||||
"URL = '" + MySQLdb.escape_string(str(package.url)) + "' " +
|
"URL = '" + MySQLdb.escape_string(str(package.url)) + "' " +
|
||||||
"WHERE ID = " + str(id))
|
"WHERE ID = " + str(id))
|
||||||
else:
|
else:
|
||||||
|
@ -109,31 +112,37 @@ class PackageDatabase:
|
||||||
"URL = '" + MySQLdb.escape_string(str(package.url)) + "' " +
|
"URL = '" + MySQLdb.escape_string(str(package.url)) + "' " +
|
||||||
"WHERE ID = " + str(id))
|
"WHERE ID = " + str(id))
|
||||||
self.insertNewInfo(package, id, locationId)
|
self.insertNewInfo(package, id, locationId)
|
||||||
# we must lastly check to see if this is a move of a package from
|
|
||||||
# unsupported to community, because we'd have to reset maintainer and location
|
# Check to see if this is a move of a package from unsupported
|
||||||
|
# to community, because we have to reset maintainer and location.
|
||||||
|
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
q.execute("SELECT LocationID FROM Packages WHERE ID = " + str(id))
|
q.execute("SELECT LocationID FROM Packages WHERE ID = " + str(id))
|
||||||
if (q.rowcount != 0):
|
if (q.rowcount != 0):
|
||||||
row = q.fetchone()
|
row = q.fetchone()
|
||||||
if (row[0] != 3):
|
if (row[0] != 3):
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
q.execute("UPDATE Packages SET LocationID = 3, MaintainerUID = null WHERE ID = " + str(id))
|
q.execute("UPDATE Packages SET LocationID = 3, MaintainerUID = null WHERE ID = " + str(id))
|
||||||
|
|
||||||
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))
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
q.execute("DELETE FROM Packages WHERE " +
|
q.execute("DELETE FROM Packages WHERE " +
|
||||||
"LocationID = " + str(locationId) + " AND ID = " + str(id))
|
"LocationID = " + str(locationId) + " AND ID = " + str(id))
|
||||||
|
|
||||||
def clearOldInfo(self, id):
|
def clearOldInfo(self, id):
|
||||||
warning("DB: Clearing old info for package with id : " + str(id))
|
warning("DB: Clearing old info for package with id : " + str(id))
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
q.execute("DELETE FROM PackageContents WHERE PackageID = " + str(id))
|
q.execute("DELETE FROM PackageContents WHERE PackageID = " + str(id))
|
||||||
q.execute("DELETE FROM PackageDepends WHERE PackageID = " + str(id))
|
q.execute("DELETE FROM PackageDepends WHERE PackageID = " + str(id))
|
||||||
q.execute("DELETE FROM PackageSources WHERE PackageID = " + str(id))
|
q.execute("DELETE FROM PackageSources WHERE PackageID = " + str(id))
|
||||||
|
|
||||||
def lookupOrDummy(self, packagename):
|
def lookupOrDummy(self, packagename):
|
||||||
retval = self.lookup(packagename)
|
retval = self.lookup(packagename)
|
||||||
if (retval != None):
|
if (retval != None):
|
||||||
return retval
|
return retval
|
||||||
return self.createDummy(packagename)
|
return self.createDummy(packagename)
|
||||||
|
|
||||||
def lookupCategory(self, categoryname):
|
def lookupCategory(self, categoryname):
|
||||||
warning("DB: Looking up category: " + categoryname)
|
warning("DB: Looking up category: " + categoryname)
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
|
@ -142,6 +151,7 @@ class PackageDatabase:
|
||||||
row = q.fetchone()
|
row = q.fetchone()
|
||||||
return row[0]
|
return row[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def createDummy(self, packagename):
|
def createDummy(self, packagename):
|
||||||
warning("DB: Creating dummy package for: " + packagename)
|
warning("DB: Creating dummy package for: " + packagename)
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
|
@ -151,10 +161,11 @@ class PackageDatabase:
|
||||||
MySQLdb.escape_string(packagename) + "', '" +
|
MySQLdb.escape_string(packagename) + "', '" +
|
||||||
MySQLdb.escape_string("A dummy package") + "', 1, 1)")
|
MySQLdb.escape_string("A dummy package") + "', 1, 1)")
|
||||||
return self.lookup(packagename)
|
return self.lookup(packagename)
|
||||||
|
|
||||||
def insertNewInfo(self, package, id, locationId):
|
def insertNewInfo(self, package, id, locationId):
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
|
|
||||||
# first delete the old; this is never bad
|
# First delete the old.
|
||||||
self.clearOldInfo(id)
|
self.clearOldInfo(id)
|
||||||
|
|
||||||
warning("DB: Inserting new package info for " + package.name +
|
warning("DB: Inserting new package info for " + package.name +
|
||||||
|
@ -164,11 +175,13 @@ class PackageDatabase:
|
||||||
for source in package.sources:
|
for source in package.sources:
|
||||||
q.execute("INSERT INTO PackageSources (PackageID, Source) " +
|
q.execute("INSERT INTO PackageSources (PackageID, Source) " +
|
||||||
"VALUES (" + str(id) + ", '" + MySQLdb.escape_string(source) + "')")
|
"VALUES (" + str(id) + ", '" + MySQLdb.escape_string(source) + "')")
|
||||||
|
|
||||||
# PackageDepends
|
# PackageDepends
|
||||||
for dep in package.depends:
|
for dep in package.depends:
|
||||||
depid = self.lookupOrDummy(dep)
|
depid = self.lookupOrDummy(dep)
|
||||||
q.execute("INSERT INTO PackageDepends (PackageID, DepPkgID) " +
|
q.execute("INSERT INTO PackageDepends (PackageID, DepPkgID) " +
|
||||||
"VALUES (" + str(id) + ", " + str(depid) + ")")
|
"VALUES (" + str(id) + ", " + str(depid) + ")")
|
||||||
|
|
||||||
def isdummy(self, packagename):
|
def isdummy(self, packagename):
|
||||||
warning("DB: Looking up package: " + packagename)
|
warning("DB: Looking up package: " + packagename)
|
||||||
q = self.cursor()
|
q = self.cursor()
|
||||||
|
@ -300,12 +313,6 @@ def deleteFile(filename):
|
||||||
command = "rm '" + filename + "'"
|
command = "rm '" + filename + "'"
|
||||||
return execute(command)
|
return execute(command)
|
||||||
|
|
||||||
def runGensync(repo, pkgbuild):
|
|
||||||
#target = os.path.join(repo, os.path.basename(repo) + ".db.tar.gz")
|
|
||||||
target = os.path.join(repo, "community.db.tar.gz")
|
|
||||||
command = "gensync '" + pkgbuild + "' '" + target + "'"
|
|
||||||
return execute(command)
|
|
||||||
|
|
||||||
def runRepoAdd(repo, package):
|
def runRepoAdd(repo, package):
|
||||||
global havefakeroot
|
global havefakeroot
|
||||||
targetDB = os.path.join(repo, "community.db.tar.gz")
|
targetDB = os.path.join(repo, "community.db.tar.gz")
|
||||||
|
@ -338,26 +345,50 @@ def error(string):
|
||||||
warning(string)
|
warning(string)
|
||||||
had_error = 1
|
had_error = 1
|
||||||
|
|
||||||
|
def usage(name):
|
||||||
|
print "Usage: %s [options] <repo_dir> <pkgbuild_tree> <build_tree>" % name
|
||||||
|
print "Options:"
|
||||||
|
print " -c, --config Specify a path to the config file."
|
||||||
|
print " -n Don't actually perform any action on the repo."
|
||||||
|
print " --delete Delete duplicate and temporary pkgs."
|
||||||
|
print " --paranoid Warn about duplicate pkgs that aren't identical via `cmp`."
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# MAIN
|
# MAIN
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
# ARGUMENTS
|
# ARGUMENTS
|
||||||
#
|
# See usage() for specifying arguments.
|
||||||
# tupkgupdate [-n] [--delete] [--paranoid] <repo_dir> <pkgbuild_dir> <build_dir>
|
|
||||||
|
try:
|
||||||
|
optlist, args = getopt.getopt(sys.argv[1:], 'c:n',
|
||||||
|
['config=', 'delete', 'paranoid'])
|
||||||
|
except getopt.GetoptError:
|
||||||
|
usage(sys.argv[0])
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# First call getopt
|
|
||||||
switch_list,args_proper = getopt.getopt(sys.argv[1:], 'n',
|
|
||||||
[ "delete", "paranoid" ])
|
|
||||||
switches = {}
|
switches = {}
|
||||||
for switch in switch_list:
|
for opt in optlist:
|
||||||
switches[switch[0]] = 1
|
switches[opt[0]] = 1
|
||||||
|
|
||||||
# Then handle the remaining arguments
|
# Check for required arguments.
|
||||||
if (len(args_proper) < 3):
|
if (len(args) < 3):
|
||||||
print >>sys.stderr, "syntax: tupkgupdate [-n] [--delete] [--paranoid] <repo_dir> <pkgbuild_tree> <build_tree>"
|
usage(sys.argv[0])
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
for opt, value in optlist:
|
||||||
|
if opt in ('-c', '--config'):
|
||||||
|
conffile = value
|
||||||
|
|
||||||
|
repo_dir, pkgbuild_dir, build_dir = args
|
||||||
|
|
||||||
|
if not os.path.isfile(conffile):
|
||||||
|
print "Error: cannot access config file (%s)" % conffile
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
config.read(conffile)
|
||||||
|
config_use_db = config.has_section('mysql')
|
||||||
|
|
||||||
# Make sure we can use fakeroot, warn if not
|
# Make sure we can use fakeroot, warn if not
|
||||||
havefakeroot = False
|
havefakeroot = False
|
||||||
if os.access('/usr/bin/fakeroot', os.X_OK):
|
if os.access('/usr/bin/fakeroot', os.X_OK):
|
||||||
|
@ -365,8 +396,6 @@ if os.access('/usr/bin/fakeroot', os.X_OK):
|
||||||
else:
|
else:
|
||||||
warning("Not using fakeroot for repo db generation")
|
warning("Not using fakeroot for repo db generation")
|
||||||
|
|
||||||
repo_dir, pkgbuild_dir, build_dir = args_proper
|
|
||||||
|
|
||||||
# Open the database if we need it so we find out now if we can't!
|
# Open the database if we need it so we find out now if we can't!
|
||||||
if config_use_db:
|
if config_use_db:
|
||||||
db = PackageDatabase(config.get('mysql', 'host'),
|
db = PackageDatabase(config.get('mysql', 'host'),
|
||||||
|
@ -513,10 +542,10 @@ for package in packages.values():
|
||||||
warning("New package file with identical version '" +
|
warning("New package file with identical version '" +
|
||||||
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)
|
delete.append(package.new.file)
|
||||||
else:
|
else:
|
||||||
warning(" Ignoring the new file.")
|
warning(" Ignoring the new file.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 5
|
# 5
|
||||||
|
@ -556,9 +585,11 @@ for file in copy:
|
||||||
if (retval != 0):
|
if (retval != 0):
|
||||||
error("Could not copy file to repo: '" + file + "'")
|
error("Could not copy file to repo: '" + file + "'")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Delete (second, for safety's sake)
|
# Delete (second, for safety's sake)
|
||||||
for file in delete:
|
for file in delete:
|
||||||
deleteFile(file)
|
deleteFile(file)
|
||||||
|
|
||||||
# Now that we've copied new files and deleted, we should delete the source
|
# Now that we've copied new files and deleted, we should delete the source
|
||||||
# files, if we're supposed to
|
# files, if we're supposed to
|
||||||
if (switches.get("--delete") == True):
|
if (switches.get("--delete") == True):
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
#!/usr/bin/python -O
|
#!/usr/bin/python -O
|
||||||
|
|
||||||
import re, os, sys, pacman, getopt, glob
|
import re
|
||||||
import MySQLdb, MySQLdb.connections
|
import os
|
||||||
|
import sys
|
||||||
|
import pacman
|
||||||
|
import getopt
|
||||||
|
import glob
|
||||||
|
import MySQLdb
|
||||||
|
import MySQLdb.connections
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# Deal with configuration
|
# Deal with configuration
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
conffile = '/home/aur/tupkgs.conf'
|
conffile = '/etc/tupkgs.conf'
|
||||||
|
|
||||||
if not os.path.isfile(conffile):
|
if not os.path.isfile(conffile):
|
||||||
print "Error: cannot access config file ("+conffile+")"
|
print "Error: cannot access config file ("+conffile+")"
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
#!/usr/bin/python -O
|
#!/usr/bin/python -O
|
||||||
|
|
||||||
import re, os, sys, pacman, getopt
|
import re
|
||||||
import MySQLdb, MySQLdb.connections
|
import os
|
||||||
|
import sys
|
||||||
|
import pacman
|
||||||
|
import getopt
|
||||||
|
import MySQLdb
|
||||||
|
import MySQLdb.connections
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# Deal with configuration
|
# Deal with configuration
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
conffile = '/home/aur/tupkgs64.conf'
|
conffile = '/etc/tupkgs64.conf'
|
||||||
|
|
||||||
if not os.path.isfile(conffile):
|
if not os.path.isfile(conffile):
|
||||||
print "Error: cannot access config file ("+conffile+")"
|
print "Error: cannot access config file ("+conffile+")"
|
||||||
|
@ -299,12 +304,6 @@ def deleteFile(filename):
|
||||||
command = "rm '" + filename + "'"
|
command = "rm '" + filename + "'"
|
||||||
return execute(command)
|
return execute(command)
|
||||||
|
|
||||||
def runGensync(repo, pkgbuild):
|
|
||||||
#target = os.path.join(repo, os.path.basename(repo) + ".db.tar.gz")
|
|
||||||
target = os.path.join(repo, "community.db.tar.gz")
|
|
||||||
command = "gensync '" + pkgbuild + "' '" + target + "'"
|
|
||||||
return execute(command)
|
|
||||||
|
|
||||||
def runRepoAdd(repo, package):
|
def runRepoAdd(repo, package):
|
||||||
global havefakeroot
|
global havefakeroot
|
||||||
targetDB = os.path.join(repo, "community.db.tar.gz")
|
targetDB = os.path.join(repo, "community.db.tar.gz")
|
||||||
|
@ -554,20 +553,16 @@ for file in copy:
|
||||||
if (retval != 0):
|
if (retval != 0):
|
||||||
error("Could not copy file to repo: '" + file + "'")
|
error("Could not copy file to repo: '" + file + "'")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Delete (second, for safety's sake)
|
# Delete (second, for safety's sake)
|
||||||
for file in delete:
|
for file in delete:
|
||||||
deleteFile(file)
|
deleteFile(file)
|
||||||
|
|
||||||
# Now that we've copied new files and deleted, we should delete the source
|
# Now that we've copied new files and deleted, we should delete the source
|
||||||
# files, if we're supposed to
|
# files, if we're supposed to
|
||||||
if (switches.get("--delete") == True):
|
if (switches.get("--delete") == True):
|
||||||
for file in copy:
|
for file in copy:
|
||||||
deleteFile(file)
|
deleteFile(file)
|
||||||
# Run gensync to build the repo index
|
|
||||||
#if (len(copy) + len(delete) > 0):
|
|
||||||
# retval = runGensync(repo_dir, pkgbuild_dir)
|
|
||||||
# if (retval != 0):
|
|
||||||
# error("Gensync returned an error!")
|
|
||||||
# sys.exit(-1)
|
|
||||||
|
|
||||||
# Run updatesync where it is needed
|
# Run updatesync where it is needed
|
||||||
for package in dbremove:
|
for package in dbremove:
|
||||||
|
|
Loading…
Add table
Reference in a new issue