~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/arch/infoUpdater.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
 
# Copyright 2004 Canonical Ltd.  All rights reserved.
2
 
#
3
 
# arch-tag: 5ce06dae-6ab3-4397-8ff2-e7fec441857f
4
 
 
5
 
__author__ = "David Allouche <david@canonical.com>"
6
 
__copyright__ = "Copyright (C) 2004 Canonical Ltd."
7
 
__metaclass__ = type
8
 
 
9
 
from canonical.arch import infoImporter
10
 
import logging
11
 
from canonical.launchpad.database import Product
12
 
from canonical.launchpad.database import ArchArchive
13
 
from canonical.launchpad.database import Person
14
 
from canonical.launchpad.database import SourceSource
15
 
from canonical.database import sqlbase
16
 
 
17
 
 
18
 
def repositoryIsTar(cvsroot):
19
 
    for suffix in ("tar.gz", "tgz", "tar.bz2"):
20
 
        if cvsroot.endswith(suffix):
21
 
            return True
22
 
    else:
23
 
        return False
24
 
 
25
 
 
26
 
def isDownloadableUrl(url):
27
 
    for prefix in ('file://', 'http://', 'https://', 'ftp://'):
28
 
        if url.startswith(prefix):
29
 
            return True
30
 
    else:
31
 
        return False
32
 
 
33
 
 
34
 
def updateCvsrootFromInfoFile(infofile):
35
 
    unassigned = infoImporter.make_unassigned_product()
36
 
    print "** processing info file %r" % infofile
37
 
    import info2job
38
 
    info = info2job.read_info(infofile, logging)
39
 
    jobs = info2job.iter_jobs(info, logging)
40
 
    for job in jobs:
41
 
        jobname = info2job.jobfile_name(info, job)
42
 
        print "* processing job %r" % jobname
43
 
        cvsroot = info.get("cvsroot")
44
 
        if cvsroot is None: continue
45
 
        query = "name=%s AND product=%s" % (
46
 
            sqlbase.quote(jobname), unassigned.id)
47
 
        for source in  SourceSource.select(query):
48
 
            print 'updateCvsroot: cvsroot ==', source.cvsroot
49
 
            if not isDownloadableUrl(source.cvsroot): continue
50
 
            if source.cvsroot == cvsroot: continue
51
 
            print 'updateCvsroot: cvsroot <=', cvsroot
52
 
            source.cvsroot = cvsroot
53
 
 
54
 
 
55
 
def updateNameSeparator(infofile, old, new):
56
 
    unassigned = infoImporter.make_unassigned_product()
57
 
    print "** processing info file %r" % infofile
58
 
    import info2job
59
 
    info = info2job.read_info(infofile, logging)
60
 
    jobs = info2job.iter_jobs(info, logging)
61
 
    for job in jobs:
62
 
        jobname = info2job.jobfile_name(info, job, sep=old)
63
 
        print "* processing job %r" % jobname
64
 
        cvsroot = info.get("cvsroot")
65
 
        if cvsroot is None: continue
66
 
        query = "name=%s AND product=%s" % (
67
 
            sqlbase.quote(jobname), unassigned.id)
68
 
        for source in  SourceSource.select(query):
69
 
            oldname = jobname
70
 
            newname = info2job.jobfile_name(info, job, sep=new)
71
 
            if source.name == newname: continue
72
 
            print "updateName: %r => %r" % (oldname, newname)
73
 
            source.name = newname
74
 
 
75
 
 
76
 
def main(filelist):
77
 
    infoImporter.filterRunner(updateCvsrootFromInfoFile, filelist)
78
 
 
79
 
    
80
 
if __name__ == '__main__':
81
 
    import sys
82
 
    if len(sys.argv) < 2:
83
 
        print "Usage: %s <info files>" % (sys.argv[0],)
84
 
    main(sys.argv[1:])
85