59
59
from lp.archiveuploader.nascentupload import (
60
60
NascentUpload, FatalUploadError, EarlyReturnUploadError)
61
61
from lp.archiveuploader.uploadpolicy import (
62
findPolicyByOptions, UploadPolicyError)
63
63
from lp.soyuz.interfaces.archive import IArchiveSet, NoSuchPPA
64
64
from lp.registry.interfaces.distribution import IDistributionSet
65
65
from lp.registry.interfaces.person import IPersonSet
108
108
class UploadProcessor:
109
109
"""Responsible for processing uploads. See module docstring."""
111
def __init__(self, options, ztm, log):
112
self.options = options
111
def __init__(self, base_fsroot, dry_run, no_mails, keep, policy_for_distro,
113
"""Create a new upload processor.
115
:param base_fsroot: Root path for queue to use
116
:param dry_run: Run but don't commit changes to database
117
:param no_mails: Don't send out any emails
118
:param keep: Leave the files in place, don't move them away
119
:param policy_for_distro: callback to obtain Policy object for a
121
:param ztm: Database transaction to use
122
:param log: Logger to use for reporting
124
self.base_fsroot = base_fsroot
125
self.dry_run = dry_run
127
self.last_processed_upload = None
129
self.no_mails = no_mails
130
self._getPolicyForDistro = policy_for_distro
115
self.last_processed_upload = None
117
def processUploadQueue(self):
133
def processUploadQueue(self, leaf_name=None):
118
134
"""Search for uploads, and process them.
120
Uploads are searched for in the 'incoming' directory inside the
136
Uploads are searched for in the 'incoming' directory inside the
123
139
This method also creates the 'incoming', 'accepted', 'rejected', and
124
140
'failed' directories inside the base_fsroot if they don't yet exist.
127
144
self.log.debug("Beginning processing")
129
146
for subdir in ["incoming", "accepted", "rejected", "failed"]:
130
full_subdir = os.path.join(self.options.base_fsroot, subdir)
147
full_subdir = os.path.join(self.base_fsroot, subdir)
131
148
if not os.path.exists(full_subdir):
132
149
self.log.debug("Creating directory %s" % full_subdir)
133
150
os.mkdir(full_subdir)
135
fsroot = os.path.join(self.options.base_fsroot, "incoming")
152
fsroot = os.path.join(self.base_fsroot, "incoming")
136
153
uploads_to_process = self.locateDirectories(fsroot)
137
154
self.log.debug("Checked in %s, found %s"
138
155
% (fsroot, uploads_to_process))
139
156
for upload in uploads_to_process:
140
157
self.log.debug("Considering upload %s" % upload)
141
self.processUpload(fsroot, upload)
158
self.processUpload(fsroot, upload, leaf_name)
144
161
self.log.debug("Rolling back any remaining transactions.")
147
def processUpload(self, fsroot, upload):
164
def processUpload(self, fsroot, upload, leaf_name=None):
148
165
"""Process an upload's changes files, and move it to a new directory.
150
167
The destination directory depends on the result of the processing
152
169
is 'failed', otherwise it is the worst of the results from the
153
170
individual changes files, in order 'failed', 'rejected', 'accepted'.
155
If the leafname option is set but its value is not the same as the
172
If the leaf_name option is set but its value is not the same as the
156
173
name of the upload directory, skip it entirely.
159
if (self.options.leafname is not None and
160
upload != self.options.leafname):
176
if (leaf_name is not None and
177
upload != leaf_name):
161
178
self.log.debug("Skipping %s -- does not match %s" % (
162
upload, self.options.leafname))
165
182
upload_path = os.path.join(fsroot, upload)
433
449
This includes moving the given upload directory and moving the
434
450
matching .distro file, if it exists.
436
if self.options.keep or self.options.dryrun:
452
if self.keep or self.dry_run:
437
453
self.log.debug("Keeping contents untouched")
440
456
pathname = os.path.basename(upload)
442
458
target_path = os.path.join(
443
self.options.base_fsroot, subdir_name, pathname)
459
self.base_fsroot, subdir_name, pathname)
444
460
self.log.debug("Moving upload directory %s to %s" %
445
461
(upload, target_path))
446
462
shutil.move(upload, target_path)
448
464
distro_filename = upload + ".distro"
449
465
if os.path.isfile(distro_filename):
450
target_path = os.path.join(self.options.base_fsroot, subdir_name,
466
target_path = os.path.join(self.base_fsroot, subdir_name,
451
467
os.path.basename(distro_filename))
452
468
self.log.debug("Moving distro file %s to %s" % (distro_filename,