~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/scripts/publishdistro.py

  • Committer: Francis J. Lacoste
  • Date: 2011-04-27 21:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12971.
  • Revision ID: francis.lacoste@canonical.com-20110427214003-iiqhcyyswppyqjsx
Change the default timeout to production value, improved options documentation and use only one bin above timeout value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Publisher script functions."""
8
8
    'run_publisher',
9
9
    ]
10
10
 
 
11
import gc
 
12
 
11
13
from zope.component import getUtility
12
14
 
 
15
from canonical.database.sqlbase import (
 
16
    clear_current_connection_cache,
 
17
    flush_database_updates,
 
18
    )
13
19
from canonical.launchpad.scripts import (
14
20
    logger,
15
21
    logger_options,
47
53
 
48
54
    parser.add_option("-A", "--careful-apt", action="store_true",
49
55
                      dest="careful_apt", metavar="", default=False,
50
 
                      help="Make index generation (e.g. apt-ftparchive) careful.")
 
56
                      help="Make the apt-ftparchive run careful.")
51
57
 
52
58
    parser.add_option("-d", "--distribution",
53
59
                      dest="distribution", metavar="DISTRO", default="ubuntu",
97
103
            return "Careful"
98
104
        return "Normal"
99
105
 
 
106
    def try_and_commit(description, func, *args):
 
107
        try:
 
108
            func(*args)
 
109
            log.debug("Committing.")
 
110
            flush_database_updates()
 
111
            txn.commit()
 
112
            log.debug("Flushing caches.")
 
113
            clear_current_connection_cache()
 
114
            gc.collect()
 
115
        except:
 
116
            log.exception("Unexpected exception while %s" % description)
 
117
            txn.abort()
 
118
            raise
 
119
 
100
120
    exclusive_options = (
101
121
        options.partner, options.ppa, options.private_ppa,
102
122
        options.primary_debug, options.copy_archive)
110
130
    log.debug("  Distribution: %s" % options.distribution)
111
131
    log.debug("    Publishing: %s" % careful_msg(options.careful_publishing))
112
132
    log.debug("    Domination: %s" % careful_msg(options.careful_domination))
113
 
    if num_exclusive == 0:
 
133
    if num_exclusive == 0 :
114
134
        log.debug("Apt-FTPArchive: %s" % careful_msg(options.careful_apt))
115
135
    else:
116
136
        log.debug("      Indexing: %s" % careful_msg(options.careful_apt))
169
189
    # Consider only archives that have their "to be published" flag turned on
170
190
    # or are pending deletion.
171
191
    archives = [
172
 
        archive for archive in archives
 
192
        archive for archive in archives 
173
193
        if archive.publish or archive.status == ArchiveStatus.DELETING]
174
194
 
175
195
    for archive in archives:
182
202
        else:
183
203
            log.info("Processing %s" % archive.archive_url)
184
204
            publisher = getPublisher(archive, allowed_suites, log)
185
 
 
 
205
        
186
206
        # Do we need to delete the archive or publish it?
187
207
        if archive.status == ArchiveStatus.DELETING:
188
208
            if archive.purpose == ArchivePurpose.PPA:
189
 
                publisher.deleteArchive()
190
 
                txn.commit()
 
209
                try_and_commit("deleting archive", publisher.deleteArchive)
191
210
            else:
192
211
                # Other types of archives do not currently support deletion.
193
212
                log.warning(
194
213
                    "Deletion of %s skipped: operation not supported on %s"
195
214
                    % archive.displayname)
196
215
        else:
197
 
            publisher.A_publish(options.careful or options.careful_publishing)
198
 
            txn.commit()
199
 
 
 
216
            try_and_commit("publishing", publisher.A_publish,
 
217
                           options.careful or options.careful_publishing)
200
218
            # Flag dirty pockets for any outstanding deletions.
201
219
            publisher.A2_markPocketsWithDeletionsDirty()
202
 
            publisher.B_dominate(
203
 
                options.careful or options.careful_domination)
204
 
            txn.commit()
 
220
            try_and_commit("dominating", publisher.B_dominate,
 
221
                           options.careful or options.careful_domination)
205
222
 
206
223
            # The primary and copy archives use apt-ftparchive to generate the
207
224
            # indexes, everything else uses the newer internal LP code.
208
225
            if archive.purpose in (ArchivePurpose.PRIMARY, ArchivePurpose.COPY):
209
 
                publisher.C_doFTPArchive(
210
 
                    options.careful or options.careful_apt)
 
226
                try_and_commit("doing apt-ftparchive", publisher.C_doFTPArchive,
 
227
                               options.careful or options.careful_apt)
211
228
            else:
212
 
                publisher.C_writeIndexes(
213
 
                    options.careful or options.careful_apt)
214
 
            txn.commit()
 
229
                try_and_commit("building indexes", publisher.C_writeIndexes,
 
230
                               options.careful or options.careful_apt)
215
231
 
216
 
            publisher.D_writeReleaseFiles(
217
 
                options.careful or options.careful_apt)
218
 
            txn.commit()
 
232
            try_and_commit("doing release files", publisher.D_writeReleaseFiles,
 
233
                           options.careful or options.careful_apt)
219
234
 
220
235
    log.debug("Ciao")