1
"""A script to take one or more info files, and import them into the database.
3
It will create ArchArchive and Branch entries as needed.
7
# NB Mark Shuttleworth 10/04/05: this code is defunct, it should never
8
# be imported because it depends on the old SourceSource table which is
15
from canonical.database.sqlbase import quote
16
from canonical.launchpad.database import Product, ArchArchive, Person, \
18
from canonical.lp import dbschema
21
from sqlobject import ForeignKey, IntCol, StringCol, DateTimeCol, BoolCol, \
30
query = Person.select(Person.q.displayname == 'Robert Collins')
31
assert query.count() == 1
34
def make_unassigned_product():
35
query = Product.select(Product.q.name == 'unassigned')
36
assert query.count() == 1
39
def importInfoFile(infofile):
41
info = info2job.read_info(infofile, logging)
42
lifeless = make_lifeless()
43
unassigned = make_unassigned_product()
44
for job in info2job.iter_jobs(info, logging):
45
print 'importInfoFile: job =', job
46
jobname = info2job.jobfile_name(info, job)
48
if SourceSource.select(SourceSource.q.name == jobname).count() != 0:
50
if job.TYPE == 'sync':
52
if job.RCS in ('cvs', 'svn'):
53
# Find the right database ID for archive in job.archivename. If it
54
# doesn't exist in the database yet, use NULL
55
results = ArchArchive.select(ArchArchive.q.name == job.archivename)
60
print 'importInfoFile: [%s] archive = %s' % (job.RCS, archive)
64
branch = None ### FIXME ###
65
### Note that branch name can be emtpy
66
# results = Branch.select(
67
# "id=%d" % mapper._getDBBranchId(version)))
68
# "archive=%s AND category=%s AND branch=%s"
69
# % (quote(archive.id), quote(job.category),
70
# quote(job.branchto)))
78
summary = info.get('summary', '')
81
'title': info.get('source',jobname),
82
'description': summary,
83
'sourcepackage': None, # FIXME!
85
'lastsynced': lastsynced,
86
'hosted': info.get('hosted') or None,
87
'upstreamname': info.get('upstreamname') or None,
88
'newarchive': job.archivename,
89
'newbranchcategory': job.category,
90
'newbranchbranch': job.branchto,
91
'newbranchversion': job.archversion,
93
'product': unassigned,
98
rcstype=dbschema.RevisionControlSystems.CVS,
99
cvsroot=job.repository,
100
cvsmodule=job.module,
101
cvstarfileurl=info.get("cvstarfile") or None,
102
cvsbranch=job.sourceBranch(),
106
rcstype=dbschema.RevisionControlSystems.SVN,
107
svnrepository=job.svnrepository,
109
elif job.RCS == "package":
111
rcstype=dbschema.RevisionControlSystems.PACKAGE,
116
newbranchcategory="",
120
package_distro=info["packagedistro"],
121
package_files_collapsed=" ".join(info["packagefile"])
124
#raise ValueError, 'Unimplemented job RCS: ' + repr(job.RCS)
125
logging.warning('Unimplemented job RCS: ' + repr(job.RCS))
129
def filterRunner(func, filelist):
130
txnManager = canonical.lp.initZopeless()
132
for filename in filelist:
135
except (SystemExit, KeyboardInterrupt):
138
sys.excepthook(*sys.exc_info())
140
logging.warning('Failure processing: %s' % filename)
145
print '%d ok, %d failed' % (ok, bad)
149
filterRunner(importInfoFile, filelist)
152
if __name__ == '__main__':
154
if len(sys.argv) < 2:
155
print "Usage: %s <info files>" % (sys.argv[0],)