From 55687e582eb4fa20a8dae392650ad84ebd650de7 Mon Sep 17 00:00:00 2001 From: Filip Valder Date: Wed, 16 Nov 2016 13:51:26 +0100 Subject: [PATCH] lint --- module_build_service/utils.py | 39 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 53c7fd66..b1d66f27 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -20,9 +20,8 @@ # # Written by Ralph Bean # Matt Prahl + """ Utility functions for module_build_service. """ -from flask import request, url_for -from datetime import datetime import re import functools import time @@ -30,13 +29,17 @@ import shutil import tempfile import os import modulemd + +from flask import request, url_for +from datetime import datetime + from module_build_service import log, models from module_build_service.errors import ValidationError, UnprocessableEntity -from module_build_service import app, conf, db, log -from module_build_service.errors import ( - ValidationError, Unauthorized, UnprocessableEntity, Conflict, NotFound) +from module_build_service import conf, db +from module_build_service.errors import (Unauthorized, Conflict) from multiprocessing.dummy import Pool as ThreadPool + def retry(timeout=120, interval=30, wait_on=Exception): """ A decorator that allows to retry a section of code... ...until success or timeout. @@ -64,7 +67,7 @@ def start_next_build_batch(config, module, session, builder, components=None): import koji # Placed here to avoid py2/py3 conflicts... if any([c.state == koji.BUILD_STATES['BUILDING'] - for c in module.component_builds ]): + for c in module.component_builds]): raise ValueError("Cannot start a batch when another is in flight.") # The user can either pass in a list of components to 'seed' the batch, or @@ -148,7 +151,7 @@ def filter_module_builds(flask_request): # Filter the query based on date request parameters for item in ('submitted', 'modified', 'completed'): for context in ('before', 'after'): - request_arg = '%s_%s' % (item, context) # i.e. submitted_before + request_arg = '%s_%s' % (item, context) # i.e. submitted_before iso_datetime_arg = request.args.get(request_arg, None) if iso_datetime_arg: @@ -171,6 +174,7 @@ def filter_module_builds(flask_request): per_page = flask_request.args.get('per_page', 10, type=int) return query.paginate(page, per_page, False) + def submit_module_build(username, url): # Import it here, because SCM uses utils methods # and fails to import them because of dep-chain. @@ -217,24 +221,24 @@ def submit_module_build(username, url): mmd.version = int(scm.version) module = models.ModuleBuild.query.filter_by(name=mmd.name, - stream=mmd.stream, - version=mmd.version).first() + stream=mmd.stream, + version=mmd.version).first() if module: log.debug('Checking whether module build already exist.') - # TODO: make this configurable, we might want to allow - # resubmitting any stuck build on DEV no matter the state + # TODO: make this configurable, we might want to allow + # resubmitting any stuck build on DEV no matter the state if module.state not in (models.BUILD_STATES['failed'],): log.error('Module (state=%s) already exists. ' - 'Only new or failed builds are allowed.' - % module.state) + 'Only new or failed builds are allowed.' + % module.state) raise Conflict('Module (state=%s) already exists. ' - 'Only new or failed builds are allowed.' - % module.state) + 'Only new or failed builds are allowed.' + % module.state) log.debug('Resuming existing module build %r' % module) module.username = username module.transition(conf, models.BUILD_STATES["init"]) log.info("Resumed existing module build in previous state %s" - % module.state) + % module.state) else: log.debug('Creating new module build') module = models.ModuleBuild.create( @@ -296,8 +300,7 @@ def submit_module_build(username, url): existing_build = models.ComponentBuild.query.filter_by( module_id=module.id, package=pkgname).first() - if (existing_build - and existing_build.state != models.BUILD_STATES['done']): + if (existing_build and existing_build.state != models.BUILD_STATES['done']): existing_build.state = models.BUILD_STATES['init'] db.session.add(existing_build) else: