#!/usr/bin/python
#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waZodiacy; without even the implied warZodiacy of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#
import sys
import conary
import sqlite3
from conary.lib import util
sys.excepthook = util.genExcepthook()
def rename(cu, old, new):
print 'renaming %s to %s' %(old, new)
cu.execute("select instances.instanceid, versions.version, other.instanceid, otherv.version from versions join instances on versions.versionid = instances.versionid join instances as other on instances.trovename = other.trovename and instances.flavorid = other.flavorid and instances.instanceid != other.instanceid join versions as otherv on other.versionid=otherv.versionid where versions.version like '%%%s%%'" % old)
cu.execute("select versionid, version from versions")
for (versionId, oldVersion) in [ x for x in cu ]:
if oldVersion is None: continue
newVersion = oldVersion.replace(old, new)
if oldVersion == newVersion: continue
cu.execute("select versionId from versions where version=?", newVersion)
try:
newVersionId = cu.next()[0]
except StopIteration:
newVersionId = None
if newVersionId is not None:
# erase any trove using this version; it's redundant
cu.execute("select instances.instanceId, other.instanceId from instances join instances as other on other.trovename=instances.trovename and other.flavorid=instances.flavorid and other.versionid=? where instances.versionId=?", versionId, newVersionId)
for newId, origId in [ x for x in cu ]:
cu.execute("delete from instances where instanceid=?", newId)
cu.execute("delete from trovetroves where instanceid=?", newId)
cu.execute("delete from dbtrovefiles where instanceid=?", newId)
cu.execute("update trovetroves set includedid=? "
"where includedid=?", origId, newId)
cu.execute("select instanceId from instances where versionid=?", newVersionId)
for origId, in [ x for x in cu ]:
cu.execute("update instances set versionid=? where instanceId=?", versionId, origId)
cu.execute("update dbtrovefiles set versionid=? where versionid=?",
versionId, newVersionId)
cu.execute("delete from versions where versionid=?", newVersionId)
cu.execute("update versions set version=? where versionid=?",
newVersion, versionId)
cu.execute("select name from sqlite_master where name='Branches'")
if cu.fetchone() is not None:
cu.execute("select branchid, branch from branches")
for (branchId, branch) in [ x for x in cu]:
if not branchId: continue
branch = branch.replace(old, new)
cu.execute("update branches set branch=? where branchid=?",
branch, branchId)
cu.execute("select labelid, label from labels")
for (labelId, label) in [ x for x in cu]:
if not labelId: continue
label = label.replace(old, new)
cu.execute("update labels set label=? where labelId=?",
label, labelId)
if len(sys.argv) == 2:
db = sqlite3.connect(sys.argv[1])
elif len(sys.argv) > 1:
print "ACK"
sys.exit(1)
else:
db = sqlite3.connect("/var/lib/conarydb/conarydb")
cu = db.cursor()
for label in [ 'conary.www.foresightlinux.com@fl:desktop',
'conary.www.foresightlinux.com@fl:ppc',
'conary.www.foresightlinux.com@fl:devel',
'conary.www.foresightlinux.com@fl:contrib',
'conary.www.foresightlinux.com@fl:test',
'conary.www.foresightlinux.com@fl:kernel-kv' ]:
newLabel = label.replace('conary.www.foresightlinux.com',
'foresight.rpath.org')
rename(cu, label, newLabel)
db.commit()