~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to upload_jenkins_job.py

  • Committer: Aaron Bentley
  • Date: 2016-04-24 16:09:49 UTC
  • mto: This revision was merged to the branch mainline in revision 1372.
  • Revision ID: aaron.bentley@canonical.com-20160424160949-6x1jdnkkpkcd820m
Rename create_model to add_model.

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
    Uploads the result of a Jenkins job to S3.
176
176
    """
177
177
 
178
 
    def __init__(self, s3, jenkins_build, unique_id=None, no_prefixes=False,
179
 
                 artifact_file_ext=None):
 
178
    def __init__(self, s3, jenkins_build, unique_id=None, no_prefixes=False):
180
179
        self.s3 = s3
181
180
        self.jenkins_build = jenkins_build
182
181
        self.unique_id = unique_id
183
182
        self.no_prefixes = no_prefixes
184
 
        self.artifact_file_ext = artifact_file_ext
185
183
 
186
184
    @classmethod
187
185
    def factory(cls, credentials, jenkins_job, build_number, bucket,
188
 
                directory, unique_id=None, no_prefixes=False,
189
 
                artifact_file_ext=None):
 
186
                directory, unique_id=None, no_prefixes=False):
190
187
        """
191
188
        Creates S3Uploader.
192
189
        :param credentials: Jenkins credential
194
191
        :param build_number: Jenkins build number
195
192
        :param bucket: S3 bucket name
196
193
        :param directory: S3 directory name
197
 
        :param artifact_file_ext: List of artifact file extentions. If set,
198
 
        only artifact with these ejections will be uploaded.
199
194
        :rtype: S3Uploader
200
195
        """
201
196
        s3 = S3.factory(bucket, directory)
204
199
            credentials=credentials, job_name=jenkins_job,
205
200
            build_number=build_number)
206
201
        return cls(s3, jenkins_build,
207
 
                   unique_id=unique_id, no_prefixes=no_prefixes,
208
 
                   artifact_file_ext=artifact_file_ext)
 
202
                   unique_id=unique_id, no_prefixes=no_prefixes)
209
203
 
210
204
    def upload(self):
211
205
        """Uploads Jenkins job results, console logs and artifacts to S3.
286
280
 
287
281
    def upload_artifacts(self):
288
282
        for filename, content in self.jenkins_build.artifacts():
289
 
            if self.artifact_file_ext:
290
 
                if os.path.splitext(filename)[1] not in self.artifact_file_ext:
291
 
                    continue
292
283
            filename = self._create_filename(filename)
293
284
            headers = self.make_headers(filename)
294
285
            self.s3.store(filename, content, headers=headers)
338
329
    parser.add_argument(
339
330
        '--no-prefixes', action='store_true', default=False,
340
331
        help='Do not add prefixes to file names; the s3_directory is unique.')
341
 
    parser.add_argument(
342
 
        '--artifact-file-ext', nargs='+',
343
 
        help='Artifacts include file extentions. If set, only files with '
344
 
             'these extentions will be uploaded.')
345
332
    add_credential_args(parser)
346
333
    args = parser.parse_args(argv)
347
334
    args.all = False
363
350
    uploader = S3Uploader.factory(
364
351
        cred, args.jenkins_job, args.build_number, args.s3_bucket,
365
352
        args.s3_directory, unique_id=args.unique_id,
366
 
        no_prefixes=args.no_prefixes, artifact_file_ext=args.artifact_file_ext)
 
353
        no_prefixes=args.no_prefixes)
367
354
    if args.build_number:
368
355
        print('Uploading build number {:d}.'.format(args.build_number))
369
356
        uploader.upload()