PEP / Flakes fixes

This commit is contained in:
Endre Karlson 2013-03-14 21:13:31 +00:00
parent 9d56d22814
commit 11f2318645
24 changed files with 91 additions and 83 deletions

View File

@ -22,7 +22,8 @@ API_SERVICE_OPTS = [
cfg.IntOpt('api_port', default=9091,
help='The port for the billing API server'),
cfg.IntOpt('api_listen', default='0.0.0.0', help='Bind to address'),
cfg.StrOpt('storage_driver', default='sqlalchemy', help='Storage driver to use'),
cfg.StrOpt('storage_driver', default='sqlalchemy',
help='Storage driver to use'),
]
cfg.CONF.register_opts(API_SERVICE_OPTS, 'service:api')

View File

@ -92,4 +92,3 @@ class ModelBase(Base):
Return a class of this object from values in the from_db
"""
return cls(**values)

View File

@ -3,11 +3,9 @@ from oslo.config import cfg
from billingstack import storage
from billingstack.central.rpcapi import CentralAPI
from billingstack.openstack.common import log
from billingstack.openstack.common.context import RequestContext
class NoAuthHook(hooks.PecanHook):
"""
Simple auth - all requests will be is_admin=True
@ -39,4 +37,4 @@ class DBHook(hooks.PecanHook):
class RPCHook(hooks.PecanHook):
def before(self, state):
state.request.central_api = CentralAPI()
state.request.central_api = CentralAPI()

View File

@ -16,13 +16,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from pecan import expose, redirect
from webob.exc import status_map
from pecan import expose
from . import v1
class RootController(object):
class RootController(object):
v1 = v1.V1Controller()
@expose(generic=True, template='index.html')

View File

@ -1 +1 @@
from .controllers import V1Controller
from .controllers import V1Controller

View File

@ -1,4 +1,4 @@
from wsme.types import text, Unset, DictType
from wsme.types import text, DictType
from billingstack.api.base import ModelBase, property_type
@ -36,6 +36,7 @@ class Currency(Base):
name = text
title = text
class Language(Base):
id = text
name = text
@ -115,7 +116,8 @@ class Merchant(Account):
class Customer(Account):
def __init__(self, **kw):
kw['contact_info'] = [ContactInfo(**i) for i in kw.get('contact_info', {})]
infos = kw.get('contact_info', {})
kw['contact_info'] = [ContactInfo(**i) for i in infos]
super(Customer, self).__init__(**kw)
merchant_id = text

View File

@ -3,9 +3,8 @@ from oslo.config import cfg
from billingstack.openstack.common.rpc import proxy
rpcapi_opts = [
cfg.StrOpt('central_topic',
default='central',
help='the topic central nodes listen on')
cfg.StrOpt('central_topic', default='central',
help='the topic central nodes listen on')
]
cfg.CONF.register_opts(rpcapi_opts)
@ -24,7 +23,8 @@ class CentralAPI(proxy.RpcProxy):
return self.call(ctxt, self.make_msg('currency_add', values=values))
def currency_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('currency_list', criterion=criterion))
return self.call(ctxt, self.make_msg('currency_list',
criterion=criterion))
def currency_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('currency_get',
@ -43,14 +43,15 @@ class CentralAPI(proxy.RpcProxy):
return self.call(ctxt, self.make_msg('language_add', values=values))
def language_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('language_list', criterion=criterion))
return self.call(ctxt, self.make_msg('language_list',
criterion=criterion))
def language_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('language_get', id_=id_))
def language_update(self, ctxt, id_, values):
return self.call(ctxt, self.make_msg('language_update',
language_id, values))
id_, values))
def language_delete(self, ctxt, id_):
return self.call(ctxt, self.make_msg('language_delete', id_=id_))
@ -87,13 +88,14 @@ class CentralAPI(proxy.RpcProxy):
return self.call(ctxt, self.make_msg('pg_method_list', id_=id_))
# PGC
def pg_config_add(self, ctxt, merchant_id, provider_id, values):
def pg_config_add(self, ctxt, merchant_id, provider_id, values):
return self.call(ctxt, self.make_msg('pg_config_add',
merchant_id=merchant_id, provider_id=provider_id,
values=values))
def pg_config_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('pg_config_list', criterion=criterion))
return self.call(ctxt, self.make_msg('pg_config_list',
criterion=criterion))
def pg_config_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('pg_config_get', id_=id_))
@ -130,7 +132,8 @@ class CentralAPI(proxy.RpcProxy):
return self.call(ctxt, self.make_msg('merchant_add', values=values))
def merchant_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('merchant_list', criterion=criterion))
return self.call(ctxt, self.make_msg('merchant_list',
criterion=criterion))
def merchant_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('merchant_get', id_=id_))
@ -149,7 +152,8 @@ class CentralAPI(proxy.RpcProxy):
merchant_id=merchant_id, values=values))
def customer_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('customer_list', criterion=criterion))
return self.call(ctxt, self.make_msg('customer_list',
criterion=criterion))
def customer_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('customer_get', id_=id_))
@ -185,7 +189,8 @@ class CentralAPI(proxy.RpcProxy):
merchant_id=merchant_id, values=values))
def product_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('product_list', criterion=criterion))
return self.call(ctxt, self.make_msg('product_list',
criterion=criterion))
def product_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('product_get', id_=id_))
@ -202,7 +207,8 @@ class CentralAPI(proxy.RpcProxy):
return self.call(ctxt, self.make_msg('plan_item_add', values=values))
def plan_item_list(self, ctxt, criterion=None):
return self.call(ctxt, self.make_msg('plan_item_list', criterion=criterion))
return self.call(ctxt, self.make_msg('plan_item_list',
criterion=criterion))
def plan_item_get(self, ctxt, id_):
return self.call(ctxt, self.make_msg('plan_item_get', id_=id_))
@ -230,4 +236,4 @@ class CentralAPI(proxy.RpcProxy):
values=values))
def plan_delete(self, ctxt, id_):
return self.call(ctxt, self.make_msg('plan_delete', id_=id_))
return self.call(ctxt, self.make_msg('plan_delete', id_=id_))

View File

@ -1,13 +1,8 @@
import functools
import re
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common import rpc
from billingstack.openstack.common.rpc import service as rpc_service
from stevedore.named import NamedExtensionManager
from billingstack import exceptions
from billingstack import storage
from billingstack import utils
cfg.CONF.import_opt('host', 'billingstack.netconf')

View File

@ -51,4 +51,3 @@ class Duplicate(Base):
class NotFound(Base):
pass

View File

@ -21,7 +21,8 @@ API_SERVICE_OPTS = [
cfg.IntOpt('api_port', default=9092,
help='The port for the BS Identity API server'),
cfg.IntOpt('api_listen', default='0.0.0.0', help='Bind to address'),
cfg.StrOpt('storage_driver', default='sqlalchemy', help='Storage driver to use'),
cfg.StrOpt('storage_driver', default='sqlalchemy',
help='Storage driver to use'),
]
cfg.CONF.register_opts(API_SERVICE_OPTS, 'service:identity_api')
cfg.CONF.register_opts(API_SERVICE_OPTS, 'service:identity_api')

View File

@ -58,4 +58,4 @@ def setup_app(pecan_config=None, extra_hooks=None):
True),
)
return app
return app

View File

@ -1,5 +1,4 @@
from oslo.config import cfg
from pecan import hooks, request, expose, rest
from pecan import request, expose, rest
import wsmeext.pecan as wsme_pecan
from wsme.types import text, wsattr
@ -115,7 +114,8 @@ class AccountController(RestBase):
@expose()
def _lookup(self, *remainder):
if remainder[0] == 'users' and remainder[2] == 'roles':
return AccountRolesController(self.id_, remainder[1], remainder[3]), ()
return AccountRolesController(self.id_, remainder[1],
remainder[3]), ()
return super(AccountController, self)._lookup(remainder)
@wsme_pecan.wsexpose(Account)
@ -213,4 +213,4 @@ class V1Controller(RestBase):
class RootController(RestBase):
v1 = V1Controller()
v1 = V1Controller()

View File

@ -18,7 +18,8 @@ class IdentityPlugin(Plugin):
**kw):
return super(IdentityPlugin, self).get_plugin(name, **kw)
def authenticate(self, context, user_id=None, password=None, account_id=None):
def authenticate(self, context, user_id=None, password=None,
account_id=None):
"""
Authenticate a User

View File

@ -1,9 +1,7 @@
import copy
import datetime
from oslo.config import cfg
from billingstack import utils
from billingstack.identity import cms
from billingstack.openstack.common import timeutils
from billingstack.plugin import Plugin
@ -80,5 +78,3 @@ class TokenPlugin(Plugin):
List out revoked Tokens.
"""
raise NotImplementedError

View File

@ -3,8 +3,10 @@ import memcache
from oslo.config import cfg
from billingstack import exceptions
from billingstack.openstack.common.gettextutils import _
from billingstack.identity.token_base import TokenPlugin
from billingstack.identity.token_base import default_expire_time, unique_id
from billingstack.identity.token_base import default_expire_time, unique_id
from billingstack.openstack.common import jsonutils
from billingstack import utils
@ -123,4 +125,4 @@ class MemcachePlugin(TokenPlugin):
list_json = self.client.get(self.revocation_key)
if list_json:
return jsonutils.loads('[%s]' % list_json)
return []
return []

View File

@ -22,10 +22,15 @@ from billingstack.storage import get_connection
LOG = log.getLogger(__name__)
cfg.CONF.import_opt('storage_driver', 'billingstack.central',
group='service:central')
cfg.CONF.import_opt('database_connection', 'billingstack.storage.impl_sqlalchemy',
group='storage:sqlalchemy')
cfg.CONF.import_opt(
'storage_driver',
'billingstack.central',
group='service:central')
cfg.CONF.import_opt(
'database_connection',
'billingstack.storage.impl_sqlalchemy',
group='storage:sqlalchemy')
class DatabaseCommand(Command):

View File

@ -19,7 +19,7 @@ class ProvidersList(DatabaseCommand, ListCommand):
data = self.conn.pg_provider_list(context)
for p in data:
p['methods'] = ", ".join(
[":".join([m[k] for k in ['type', 'name']])\
for m in p['methods']])
keys = ['type', 'name']
methods = [":".join([m[k] for k in keys]) for m in p['methods']]
p['methods'] = ", ".join(methods)
return data

View File

@ -155,7 +155,8 @@ class HelpersMixin(object):
def _kv_rows(self, rows, key='name', func=lambda i: i):
"""
Return a Key, Value dict where the "key" will be the key and the row as value
Return a Key, Value dict where the "key" will be the key and the row
as value
"""
data = {}
for row in rows:
@ -165,4 +166,3 @@ class HelpersMixin(object):
data_key = row[key]
data[data_key] = func(row)
return data

View File

@ -137,4 +137,4 @@ class PropertyMixin(object):
def value(self, value):
data_type = type(value).__name__
self.data_type = data_type
self._value = value
self._value = value

View File

@ -48,7 +48,8 @@ class Connection(base.Connection, api.HelpersMixin):
def base(self):
return models.BASE
def set_properties(self, obj, properties, cls=None, rel_attr='properties', purge=False):
def set_properties(self, obj, properties, cls=None, rel_attr='properties',
purge=False):
"""
Set's a dict with key values on a relation on the row
@ -242,8 +243,8 @@ class Connection(base.Connection, api.HelpersMixin):
try:
all_methods[method_key].providers.append(provider)
except KeyError:
msg = 'Provider %s tried to associate to non-existing method %s' \
% (provider.name, method_key)
msg = 'Provider %s tried to associate to non-existing'\
'method %s' % (provider.name, method_key)
LOG.error(msg)
raise exceptions.ConfigurationError(msg)
@ -387,7 +388,8 @@ class Connection(base.Connection, api.HelpersMixin):
def _product(self, row):
product = dict(row)
product['properties'] = self._kv_rows(row.properties, func=lambda i: i['value'])
product['properties'] = self._kv_rows(row.properties,
func=lambda i: i['value'])
return product
def product_add(self, ctxt, merchant_id, values):
@ -479,7 +481,8 @@ class Connection(base.Connection, api.HelpersMixin):
def _plan(self, row):
plan = dict(row)
plan['properties'] = self._kv_rows(row.properties, func=lambda i: i['value'])
plan['properties'] = self._kv_rows(row.properties,
func=lambda i: i['value'])
plan['plan_items'] = map(dict, row.plan_items) if row.plan_items\
else []
return plan

View File

@ -23,7 +23,6 @@ from alembic import context
from sqlalchemy import create_engine, pool
from billingstack.storage.impl_sqlalchemy.models import ModelBase
from billingstack.openstack.common import importutils
# this is the Alembic Config object, which provides
@ -51,7 +50,8 @@ def run_migrations_offline():
script output.
"""
context.configure(url=billingstack_config['storage:sqlalchemy'].database_connection)
context.configure(url=billingstack_config['storage:sqlalchemy']
.database_connection)
with context.begin_transaction():
context.run_migrations(options=build_options())

View File

@ -17,7 +17,6 @@
# @author: Mark McClain, DreamHost
# Copied: Quantum
import os
import sys
from alembic import command as alembic_command
from alembic import config as alembic_config
@ -115,8 +114,9 @@ def main():
config = alembic_config.Config(
os.path.join(os.path.dirname(__file__), 'alembic.ini')
)
config.set_main_option('script_location',
'billingstack.storage.impl_sqlalchemy.migration:alembic_migrations')
config.set_main_option(
'script_location',
'billingstack.storage.impl_sqlalchemy.migration:alembic_migrations')
# attach the Quantum conf to the Alembic conf
config.billingstack_config = CONF

View File

@ -11,20 +11,17 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import re
from sqlalchemy import Column, Table, ForeignKey, UniqueConstraint
from sqlalchemy import Integer, Float, Enum, Boolean
from sqlalchemy import DateTime, Unicode, UnicodeText
from sqlalchemy import Integer, Float
from sqlalchemy import DateTime, Unicode
from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from billingstack import utils
from billingstack.openstack.common import log as logging
from billingstack.sqlalchemy.types import JSON, UUID
from billingstack.sqlalchemy.model_base import (ModelBase, BaseMixin,
PropertyMixin)
from billingstack.sqlalchemy.model_base import (
ModelBase, BaseMixin, PropertyMixin)
LOG = logging.getLogger(__name__)
@ -48,7 +45,8 @@ class Language(BASE):
title = Column(Unicode(100), nullable=False)
pg_provider_methods = Table('pg_provider_methods', BASE.metadata,
pg_provider_methods = Table(
'pg_provider_methods', BASE.metadata,
Column('provider_id', UUID, ForeignKey('pg_provider.id')),
Column('method_id', UUID, ForeignKey('pg_method.id')))
@ -172,10 +170,12 @@ class Merchant(BASE, BaseMixin):
products = relationship('Product', backref='merchant')
currency = relationship('Currency', uselist=False, backref='merchants')
currency_name = Column(Unicode(10), ForeignKey('currency.name'), nullable=False)
currency_name = Column(Unicode(10), ForeignKey('currency.name'),
nullable=False)
language = relationship('Language', uselist=False, backref='merchants')
language_name = Column(Unicode(10), ForeignKey('language.name'), nullable=False)
language_name = Column(Unicode(10), ForeignKey('language.name'),
nullable=False)
class PGAccountConfig(BASE, BaseMixin):
@ -278,10 +278,12 @@ class Invoice(BASE, BaseMixin):
line_items = relationship('InvoiceLine', backref='invoice_lines')
state = relationship('InvoiceState', backref='invoices')
state_id = Column(Unicode(60), ForeignKey('invoice_state.name'), nullable=False)
state_id = Column(Unicode(60), ForeignKey('invoice_state.name'),
nullable=False)
currency = relationship('Currency', backref='invoices')
currency_name = Column(Unicode(10), ForeignKey('currency.name'), nullable=False)
currency_name = Column(Unicode(10), ForeignKey('currency.name'),
nullable=False)
merchant = relationship('Merchant', backref='invoices')
merchant_id = Column(UUID, ForeignKey('merchant.id', ondelete='CASCADE'),
@ -313,7 +315,7 @@ class Pricing(BASE, BaseMixin):
plan_item_id = Column(UUID, ForeignKey('plan_item.id', ondelete='CASCADE',
onupdate='CASCADE'))
product_id = Column(UUID, ForeignKey('product.id', ondelete='CASCADE',
onupdate='CASCADE'))
onupdate='CASCADE'))
class Plan(BASE, BaseMixin):
@ -419,9 +421,9 @@ class Subscription(BASE, BaseMixin):
payment_method = relationship('PaymentMethod', backref='subscriptions')
payment_method_id = Column(UUID, ForeignKey('payment_method.id',
ondelete='CASCADE',
onupdate='CASCADE'),
nullable=False)
ondelete='CASCADE',
onupdate='CASCADE'),
nullable=False)
class Usage(BASE, BaseMixin):

View File

@ -61,7 +61,7 @@ def get_country(country_obj, **kw):
obj = country_obj.get(**kw)
except KeyError:
raise exceptions.InvalidObject(errors=kw)
return dict([(k, v) for k, v in obj.__dict__.items() \
return dict([(k, v) for k, v in obj.__dict__.items()
if not k.startswith('_')])
@ -131,4 +131,4 @@ def unixtime(dt_obj):
:returns: float
"""
return time.mktime(dt_obj.utctimetuple())
return time.mktime(dt_obj.utctimetuple())