~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/arch/infoImporter.py

  • Committer: Robert Collins
  • Date: 2005-10-31 18:29:12 UTC
  • mfrom: (1102.1.126)
  • mto: (1102.1.138) (63.1.155)
  • mto: This revision was merged to the branch mainline in revision 2836.
  • Revision ID: robertc@robertcollins.net-20051031182912-5b96cbfc568d7a46
Merge ddaa and my branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""A script to take one or more info files, and import them into the database.
2
 
 
3
 
It will create ArchArchive and Branch entries as needed.
4
 
"""
5
 
 
6
 
#
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
9
 
# History (tm).
10
 
#
11
 
 
12
 
 
13
 
import sys
14
 
 
15
 
from canonical.database.sqlbase import quote
16
 
from canonical.launchpad.database import Product, ArchArchive, Person, \
17
 
        SourceSource
18
 
from canonical.lp import dbschema
19
 
import canonical.lp
20
 
 
21
 
from sqlobject import ForeignKey, IntCol, StringCol, DateTimeCol, BoolCol, \
22
 
                      EnumCol
23
 
 
24
 
import importd
25
 
import importd.Job
26
 
 
27
 
import logging
28
 
 
29
 
def make_lifeless():
30
 
    query = Person.select(Person.q.displayname == 'Robert Collins')
31
 
    assert query.count() == 1
32
 
    return query[0]
33
 
 
34
 
def make_unassigned_product():
35
 
    query = Product.select(Product.q.name == 'unassigned')
36
 
    assert query.count() == 1
37
 
    return query[0]
38
 
 
39
 
def importInfoFile(infofile):
40
 
    import info2job
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)
47
 
        lastsynced=None
48
 
        if SourceSource.select(SourceSource.q.name == jobname).count() != 0:
49
 
            continue
50
 
        if job.TYPE == 'sync':
51
 
            lastsynced='NOW'
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)
56
 
            try:
57
 
                archive = results[0]
58
 
            except IndexError:
59
 
                archive = None
60
 
            print 'importInfoFile: [%s] archive = %s' % (job.RCS, archive)
61
 
 
62
 
            # Ditto Branch
63
 
            if 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)))
71
 
#                 try:
72
 
#                     branch = results[0]
73
 
#                 except IndexError:
74
 
#                     branch = None
75
 
            else:
76
 
                branch = None
77
 
 
78
 
            summary = info.get('summary', '')
79
 
            kwargs = {
80
 
                'name': jobname,
81
 
                'title': info.get('source',jobname),
82
 
                'description': summary,
83
 
                'sourcepackage': None, # FIXME!
84
 
                'branch': branch,
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,
92
 
                'owner': lifeless,
93
 
                'product': unassigned,
94
 
                }
95
 
 
96
 
            if job.RCS == 'cvs':
97
 
                ss = SourceSource(
98
 
                        rcstype=dbschema.RevisionControlSystems.CVS,
99
 
                        cvsroot=job.repository,
100
 
                        cvsmodule=job.module,
101
 
                        cvstarfileurl=info.get("cvstarfile") or None,
102
 
                        cvsbranch=job.sourceBranch(),
103
 
                        **kwargs)
104
 
            if job.RCS == 'svn':
105
 
                ss = SourceSource(
106
 
                    rcstype=dbschema.RevisionControlSystems.SVN,
107
 
                    svnrepository=job.svnrepository,
108
 
                    **kwargs)
109
 
        elif job.RCS == "package":
110
 
            ss = SourceSource(
111
 
                    rcstype=dbschema.RevisionControlSystems.PACKAGE,
112
 
                    name=jobname,
113
 
                    title="",
114
 
                    description="",
115
 
                    newarchive="",
116
 
                    newbranchcategory="",
117
 
                    newbranchbranch="",
118
 
                    newbranchversion="",
119
 
                    owner=lifeless,
120
 
                    package_distro=info["packagedistro"],
121
 
                    package_files_collapsed=" ".join(info["packagefile"])
122
 
                    )
123
 
        else:
124
 
            #raise ValueError, 'Unimplemented job RCS: ' + repr(job.RCS)
125
 
            logging.warning('Unimplemented job RCS: ' + repr(job.RCS))
126
 
            continue
127
 
 
128
 
 
129
 
def filterRunner(func, filelist):
130
 
    txnManager = canonical.lp.initZopeless()
131
 
    ok = bad = 0
132
 
    for filename in filelist:
133
 
        try:
134
 
            func(filename)
135
 
        except (SystemExit, KeyboardInterrupt):
136
 
            raise
137
 
        except Exception, e:
138
 
            sys.excepthook(*sys.exc_info())
139
 
            sys.exc_clear()
140
 
            logging.warning('Failure processing: %s' % filename)
141
 
            bad += 1
142
 
        else:
143
 
            ok += 1
144
 
    txnManager.commit()
145
 
    print '%d ok, %d failed' % (ok, bad)
146
 
 
147
 
 
148
 
def main(filelist):
149
 
    filterRunner(importInfoFile, filelist)
150
 
 
151
 
 
152
 
if __name__ == '__main__':
153
 
    import sys
154
 
    if len(sys.argv) < 2:
155
 
        print "Usage: %s <info files>" % (sys.argv[0],)
156
 
    main(sys.argv[1:])
157
 
 
158