Skip to content

Commit

Permalink
PEP-8 bodhi.server.
Browse files Browse the repository at this point in the history
Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
  • Loading branch information
bowlofeggs committed Jan 18, 2017
1 parent ffa4699 commit de6f1fd
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 116 deletions.
41 changes: 16 additions & 25 deletions bodhi/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from collections import defaultdict
import logging

from cornice.validators import DEFAULT_FILTERS
from dogpile.cache import make_region
from munch import munchify
from sqlalchemy import engine_from_config
from sqlalchemy.orm import scoped_session, sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension

from pyramid.settings import asbool
from pyramid.security import unauthenticated_userid
from pyramid.config import Configurator
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.renderers import JSONP
from pyramid.config import Configurator
from pyramid.exceptions import HTTPForbidden
from pyramid.renderers import JSONP
from pyramid.security import unauthenticated_userid
from pyramid.settings import asbool
from sqlalchemy import engine_from_config
from sqlalchemy.orm import scoped_session, sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension

from . import buildsys
from bodhi.server import buildsys, ffmarkdown

import logging

log = logging.getLogger(__name__)


# TODO -- someday move this externally to "fedora_flavored_markdown"
from bodhi.server import ffmarkdown
ffmarkdown.inject()


Expand All @@ -56,14 +56,8 @@ def get_db_session_for_request(request=None):
session = Sess()

def cleanup(request):
## No need to do rollback/commit ourselves. the zope transaction
## manager takes care of that for us...
#if request.exception is not None:
# session.rollback()
#else:
# session.commit()
## However, we may still want to explicitly close the session we opened
#log.debug("Closing session at the end of a request.")
# No need to do rollback/commit ourselves. the zope transaction manager takes care of that
# for us. However, we want to explicitly close the session we opened
session.close()

request.add_finished_callback(cleanup)
Expand Down Expand Up @@ -109,6 +103,7 @@ def get_releases(request):
from bodhi.server.models import Release
return Release.all_releases(request.db)


#
# Cornice filters
#
Expand All @@ -119,7 +114,6 @@ def exception_filter(response, request):
log.exception('Unhandled exception raised: %r' % response)
return response

from cornice.validators import DEFAULT_FILTERS
DEFAULT_FILTERS.insert(0, exception_filter)


Expand Down Expand Up @@ -182,10 +176,8 @@ def main(global_config, testing=None, session=None, **settings):
config.testing_securitypolicy(userid=testing, permissive=True)
else:
config.set_authentication_policy(AuthTktAuthenticationPolicy(
settings['authtkt.secret'],
callback=groupfinder,
secure=asbool(settings['authtkt.secure']),
hashalg='sha512'))
settings['authtkt.secret'], callback=groupfinder,
secure=asbool(settings['authtkt.secure']), hashalg='sha512'))
config.set_authorization_policy(ACLAuthorizationPolicy())

# Frontpage
Expand Down Expand Up @@ -224,6 +216,5 @@ def main(global_config, testing=None, session=None, **settings):
config.scan('bodhi.server.views')
config.scan('bodhi.server.services')
config.scan('bodhi.server.captcha')
config.scan('bodhi.server.events')

return config.make_wsgi_app()
45 changes: 23 additions & 22 deletions bodhi/server/buildsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import time
import logging
import time

from os.path import join, expanduser
import koji

log = logging.getLogger('bodhi')

log = logging.getLogger('bodhi')
_buildsystem = None

try:
import koji
except ImportError:
log.warn("Could not import 'koji'")

# URL of the koji hub
_koji_hub = None

Expand Down Expand Up @@ -198,20 +192,22 @@ def listBuildRPMs(self, id, *args, **kw):

def listTags(self, build, *args, **kw):
if 'el5' in build:
result = [{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True,
'name': 'dist-5E-epel-testing-candidate', 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True,
'name': 'dist-5E-epel-testing-candidate', 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True,
'name': 'dist-5E-epel', 'perm': None, 'perm_id': None}]
result = [
{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True,
'name': 'dist-5E-epel-testing-candidate', 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True,
'name': 'dist-5E-epel-testing-candidate', 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True, 'name': 'dist-5E-epel',
'perm': None, 'perm_id': None}]
else:
release = build.split('.')[-1].replace('fc', 'f')
result = [{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True,
'name': '%s-updates-candidate' % release, 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True,
'name': '%s' % release, 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True,
'name': '%s-updates-testing' % release, 'perm': None, 'perm_id': None}]
result = [
{'arches': 'i386 x86_64 ppc ppc64', 'id': 10, 'locked': True,
'name': '%s-updates-candidate' % release, 'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True, 'name': '%s' % release,
'perm': None, 'perm_id': None},
{'arches': 'i386 x86_64 ppc ppc64', 'id': 5, 'locked': True,
'name': '%s-updates-testing' % release, 'perm': None, 'perm_id': None}]
if build in DevBuildsys.__tagged__:
for tag in DevBuildsys.__tagged__[build]:
result += [{'name': tag}]
Expand Down Expand Up @@ -346,7 +342,12 @@ def setup_buildsystem(settings):

if buildsys == 'koji':
log.debug('Using Koji Buildsystem')
_buildsystem = lambda: koji_login(config=settings)

def get_koji_login():
"""Call koji_login with settings and return the result."""
return koji_login(config=settings)

_buildsystem = get_koji_login
elif buildsys in ('dev', 'dummy', None):
log.debug('Using DevBuildsys')
_buildsystem = DevBuildsys
Expand Down
26 changes: 0 additions & 26 deletions bodhi/server/events.py

This file was deleted.

1 change: 1 addition & 0 deletions bodhi/server/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


class BodhiException(Exception):
pass

Expand Down
3 changes: 1 addition & 2 deletions bodhi/server/ffmarkdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def bug_url(tracker, idx):
'php': "https://bugs.php.net/bug.php?id=%s",
'python': "https://bugs.python.org/issue%s",
'rh': "https://bugzilla.redhat.com/show_bug.cgi?id=%s",
'rhbz': "https://bugzilla.redhat.com/show_bug.cgi?id=%s",
}[tracker.lower()] % idx
'rhbz': "https://bugzilla.redhat.com/show_bug.cgi?id=%s"}[tracker.lower()] % idx

except KeyError:
return None
Expand Down
14 changes: 7 additions & 7 deletions bodhi/server/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

from textwrap import wrap
import smtplib

from textwrap import wrap
from kitchen.text.converters import to_unicode, to_bytes
from kitchen.iterutils import iterate
from kitchen.text.converters import to_unicode, to_bytes

from bodhi.server import log
from bodhi.server.config import config
from bodhi.server.util import get_rpm_header

from . import log
from .util import get_rpm_header
from .config import config

#
# All of the email messages that bodhi is going to be sending around.
Expand Down Expand Up @@ -502,7 +502,7 @@ def send(to, msg_type, update, sender=None, agent=None):

subject_template = '[Fedora Update] %s[%s] %s'
for person in iterate(to):
subject = subject_template % (critpath, msg_type, update.title)
subject = subject_template % (critpath, msg_type, update.title)
fields = MESSAGES[msg_type]['fields'](agent, update)
body = MESSAGES[msg_type]['body'] % fields
send_mail(sender, person, subject, body, headers=headers)
Expand Down
19 changes: 9 additions & 10 deletions bodhi/server/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

__version__ = '2.0'

import os
import logging
import os
import shutil
import tempfile

from urlgrabber.grabber import urlgrab
from kitchen.text.converters import to_bytes

from urlgrabber.grabber import urlgrab
import createrepo_c as cr

from bodhi.server.buildsys import get_session
from bodhi.server.config import config
from bodhi.server.models import Build, UpdateStatus, UpdateRequest, UpdateSuggestion
from bodhi.server.buildsys import get_session


__version__ = '2.0'
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -250,9 +248,10 @@ def add_update(self, update):
else:
arch = rpm['arch']

pkg.src = os.path.join(config.get('file_url'), update.status is
UpdateStatus.testing and 'testing' or '',
str(update.release.version), arch, filename[0], filename)
pkg.src = os.path.join(
config.get('file_url'),
update.status is UpdateStatus.testing and 'testing' or '',
str(update.release.version), arch, filename[0], filename)

col.append(pkg)

Expand Down
8 changes: 3 additions & 5 deletions bodhi/server/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import copy

import transaction
import socket

import fedmsg
import fedmsg.config
import fedmsg.encoding

import socket
import transaction

import bodhi.server
import bodhi.server.config
Expand Down Expand Up @@ -97,7 +95,7 @@ def __init__(self):

def get_current_data_manager(self):
current_transaction_manager = transaction.get()
if not current_transaction_manager in self:
if current_transaction_manager not in self:
current_data_manager = FedmsgDataManager()
self.add(current_transaction_manager, current_data_manager)
current_transaction_manager.join(current_data_manager)
Expand Down
16 changes: 8 additions & 8 deletions bodhi/server/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
The tool for triggering updates pushes.
The CLI tool for triggering update pushes.
"""

import click
from collections import defaultdict
from datetime import datetime
import json
import glob
import json

from collections import defaultdict
from sqlalchemy.sql import or_
import click

import bodhi.server.notifications
from bodhi.server.models import Build, get_db_factory, Release, ReleaseState, Update, UpdateRequest
import bodhi.server.notifications


@click.command()
Expand Down Expand Up @@ -69,7 +68,7 @@ def push(username, cert_prefix, **kwargs):
continue

for update in lockfiles[lockfile]:
update = session.query(Update).filter(Update.title==update).first()
update = session.query(Update).filter(Update.title == update).first()
updates.append(update)
else:
# Accept both comma and space separated request list
Expand All @@ -80,7 +79,8 @@ def push(username, cert_prefix, **kwargs):

if kwargs.get('builds'):
query = query.join(Update.builds)
query = query.filter(or_(*[Build.nvr==build for build in kwargs['builds'].split(',')]))
query = query.filter(
or_(*[Build.nvr == build for build in kwargs['builds'].split(',')]))

query = _filter_releases(session, query, kwargs.get('releases'))

Expand Down
12 changes: 5 additions & 7 deletions bodhi/server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import colander

from bodhi.server import util
from bodhi.server.models import (UpdateRequest, UpdateSeverity, UpdateStatus,
UpdateSuggestion, UpdateType, ReleaseState)
from bodhi.server.models import (ReleaseState, UpdateRequest, UpdateSeverity, UpdateStatus,
UpdateSuggestion, UpdateType)
from bodhi.server.validators import validate_csrf_token


Expand Down Expand Up @@ -79,6 +79,7 @@ class BugFeedback(colander.MappingSchema):
missing=0,
)


class BugFeedbacks(colander.SequenceSchema):
bug_feedback = BugFeedback()

Expand All @@ -91,6 +92,7 @@ class TestcaseFeedback(colander.MappingSchema):
missing=0,
)


class TestcaseFeedbacks(colander.SequenceSchema):
testcase_feedback = TestcaseFeedback()

Expand Down Expand Up @@ -128,11 +130,7 @@ class SaveUpdateSchema(CSRFProtectedSchema, colander.MappingSchema):
builds = Builds(colander.Sequence(accept_scalar=True),
preparer=[util.splitter])

bugs = Bugs(
colander.Sequence(accept_scalar=True),
missing=None,
preparer=[util.splitter]
)
bugs = Bugs(colander.Sequence(accept_scalar=True), missing=None, preparer=[util.splitter])

close_bugs = colander.SchemaNode(
colander.Boolean(),
Expand Down

0 comments on commit de6f1fd

Please sign in to comment.