Rename all modules to comply with PEP8

Lowercase with underscores
This commit is contained in:
Ben 2019-05-16 16:34:16 +01:00
parent 5a77c09ac7
commit 75c05604d9
59 changed files with 116 additions and 100 deletions

View File

@ -1,6 +1,6 @@
import asyncio
import sys
from Houdini.HoudiniFactory import HoudiniFactory
from houdini.houdini import HoudiniFactory
if __name__ == '__main__':
if sys.platform == 'win32':

View File

@ -2,11 +2,11 @@ import inspect
import config
from Houdini import Handlers
from Houdini import Plugins
from Houdini import ConflictResolution
from houdini import handlers
from houdini import plugins
from houdini import ConflictResolution
from Houdini.Converters import _ArgumentDeserializer, _listener
from houdini.converters import _ArgumentDeserializer, _listener
class UnknownCommandException(Exception):
@ -55,12 +55,12 @@ def group(name=None, **kwargs):
string_separator=' ', **kwargs)
cooldown = Handlers.cooldown
check = Handlers.check
cooldown = handlers.cooldown
check = handlers.check
player_attribute = Handlers.player_attribute
player_data_attribute = Handlers.player_data_attribute
player_in_room = Handlers.player_in_room
player_attribute = handlers.player_attribute
player_data_attribute = handlers.player_data_attribute
player_in_room = handlers.player_in_room
def is_command(command_object):
@ -69,7 +69,7 @@ def is_command(command_object):
def commands_from_plugin(commands, plugin):
command_objects = inspect.getmembers(plugin, is_command)
if not isinstance(plugin, Plugins.IPlugin):
if not isinstance(plugin, plugins.IPlugin):
raise TypeError('Commands can only be loaded from plugins')
for command_name, command_object in command_objects:

View File

@ -6,7 +6,7 @@ import itertools
import inspect
from Houdini.Cooldown import CooldownError
from houdini.cooldown import CooldownError
class ChecklistError(Exception):
@ -213,7 +213,7 @@ class ConnectedIglooConverter(IConverter):
class RoomConverter(IConverter):
description = """Converts a room ID into a Houdini.Data.Room instance"""
description = """Converts a room ID into a houdini.data.Room instance"""
async def convert(self, ctx):
room_id = int(ctx.argument)
@ -224,7 +224,7 @@ class RoomConverter(IConverter):
class ItemConverter(IConverter):
description = """Converts an item ID into a Houdini.Data.Item instance"""
description = """Converts an item ID into a houdini.data.Item instance"""
async def convert(self, ctx):
item_id = int(ctx.argument)
@ -235,7 +235,7 @@ class ItemConverter(IConverter):
class IglooConverter(IConverter):
description = """Converts an igloo ID into a Houdini.Data.Igloo instance"""
description = """Converts an igloo ID into a houdini.data.Igloo instance"""
async def convert(self, ctx):
igloo_id = int(ctx.argument)
@ -246,7 +246,7 @@ class IglooConverter(IConverter):
class FurnitureConverter(IConverter):
description = """Converts a furniture ID into a Houdini.Data.Furniture instance"""
description = """Converts a furniture ID into a houdini.data.Furniture instance"""
async def convert(self, ctx):
furniture_id = int(ctx.argument)
@ -257,7 +257,7 @@ class FurnitureConverter(IConverter):
class FlooringConverter(IConverter):
description = """Converts a flooring ID into a Houdini.Data.Flooring instance"""
description = """Converts a flooring ID into a houdini.data.Flooring instance"""
async def convert(self, ctx):
flooring_id = int(ctx.argument)
@ -268,7 +268,7 @@ class FlooringConverter(IConverter):
class StampConverter(IConverter):
description = """Converts a stamp ID into a Houdini.Data.Stamp instance"""
description = """Converts a stamp ID into a houdini.data.Stamp instance"""
async def convert(self, ctx):
stamp_id = int(ctx.argument)

View File

@ -1,4 +1,4 @@
from Houdini.Data import db
from houdini.data import db
class BuddyList(db.Model):

View File

@ -1,4 +1,4 @@
from Houdini.Data import db
from houdini.data import db
class DanceSong(db.Model):

View File

@ -1,5 +1,5 @@
from Houdini.Data import db, BaseCrumbsCollection
from Houdini.Data.Penguin import PenguinIgloo, PenguinLocation, PenguinFurniture
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinIgloo, PenguinLocation, PenguinFurniture
class Flooring(db.Model):

View File

@ -1,5 +1,5 @@
from Houdini.Data import db, BaseCrumbsCollection
from Houdini.Data.Penguin import PenguinItem
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinItem
class Item(db.Model):
@ -19,6 +19,6 @@ class Item(db.Model):
class ItemCrumbsCollection(BaseCrumbsCollection):
def __init__(self, model=Item, key='ID', inventory_model=PenguinItem, inventory_id=None):
super().__init__(model=model, key=key, inventory_model=inventory_model,
def __init__(self, inventory_id=None):
super().__init__(model=Item, key='ID', inventory_model=PenguinItem,
inventory_id=inventory_id)

View File

@ -1,5 +1,5 @@
from Houdini.Data import db, BaseCrumbsCollection
from Houdini.Data.Penguin import PenguinPostcard
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinPostcard
class Postcard(db.Model):

View File

@ -1,4 +1,4 @@
from Houdini.Data import db
from houdini.data import db
class Ban(db.Model):

View File

@ -1,4 +1,4 @@
from Houdini.Data import db
from houdini.data import db
class PenguinTrack(db.Model):

View File

@ -1,5 +1,5 @@
from Houdini.Data import db, BaseCrumbsCollection
from Houdini.Data.Penguin import PenguinCard
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinCard
class Card(db.Model):

View File

@ -1,4 +1,4 @@
from Houdini.Data import db
from houdini.data import db
class Penguin(db.Model):
@ -71,6 +71,11 @@ class Penguin(db.Model):
return int('{}{}0{}{}{}{}'.format(self.ApprovalRu * 1, self.ApprovalDe * 1, self.ApprovalEs * 1,
self.ApprovalFr * 1, self.ApprovalPt * 1, self.ApprovalEn * 1), 2)
@property
def rejection(self):
return int('{}{}0{}{}{}{}'.format(self.RejectionRu * 1, self.RejectionDe * 1, self.RejectionEs * 1,
self.RejectionFr * 1, self.RejectionPt * 1, self.RejectionEn * 1), 2)
class ActivationKey(db.Model):
__tablename__ = 'activation_key'
@ -233,6 +238,13 @@ class PenguinPuffleItem(db.Model):
Quantity = db.Column(db.SmallInteger, nullable=False)
class PenguinPermission(db.Model):
__tablename__ = 'penguin_permission'
PenguinID = db.Column(db.ForeignKey(u'penguin.ID', ondelete=u'CASCADE', onupdate=u'CASCADE'), primary_key=True)
PermissionID = db.Column(db.ForeignKey(u'permission.ID', ondelete=u'CASCADE', onupdate=u'CASCADE'), nullable=False)
class Login(db.Model):
__tablename__ = 'login'

View File

@ -1,5 +1,5 @@
from Houdini.Data import db, BaseCrumbsCollection
from Houdini.Data.Penguin import PenguinPuffle, PenguinPuffleItem
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinPuffle, PenguinPuffleItem
class Puffle(db.Model):

View File

@ -1,4 +1,4 @@
from Houdini.Data import db
from houdini.data import db
class RedemptionBook(db.Model):

View File

@ -1,4 +1,4 @@
from Houdini.Data import db, BaseCrumbsCollection
from houdini.data import db, BaseCrumbsCollection
class Room(db.Model):

View File

@ -1,5 +1,5 @@
from Houdini.Data import db, BaseCrumbsCollection
from Houdini.Data.Penguin import PenguinStamp
from houdini.data import db, BaseCrumbsCollection
from houdini.data.penguin import PenguinStamp
class Stamp(db.Model):

View File

@ -3,8 +3,8 @@ import importlib
import copy
from watchdog.events import FileSystemEventHandler
from Houdini.Handlers import listeners_from_module, remove_handlers_by_module
from Houdini.Events import evaluate_handler_file_event
from houdini.handlers import listeners_from_module, remove_handlers_by_module
from houdini.events import evaluate_handler_file_event
class HandlerFileEventHandler(FileSystemEventHandler):

View File

@ -5,7 +5,7 @@ import copy
import asyncio
from watchdog.events import FileSystemEventHandler
from Houdini.Events import evaluate_handler_file_event
from houdini.events import evaluate_handler_file_event
class PluginFileEventHandler(FileSystemEventHandler):

View File

@ -4,10 +4,10 @@ import os
import itertools
from types import FunctionType
from Houdini.Converters import _listener, _ArgumentDeserializer, get_converter, do_conversion, _ConverterContext
from houdini.converters import _listener, _ArgumentDeserializer, get_converter, do_conversion, _ConverterContext
from Houdini.Cooldown import _Cooldown, _CooldownMapping, BucketType
from Houdini import Plugins
from houdini.cooldown import _Cooldown, _CooldownMapping, BucketType
from houdini import plugins
class AuthorityError(Exception):
@ -132,7 +132,7 @@ def is_listener(listener):
def listeners_from_module(xt_listeners, xml_listeners, module):
listener_objects = inspect.getmembers(module, is_listener)
for listener_name, listener_object in listener_objects:
if isinstance(module, Plugins.IPlugin):
if isinstance(module, plugins.IPlugin):
listener_object.instance = module
listener_collection = xt_listeners if type(listener_object) == _XTListener else xml_listeners

View File

@ -1,10 +1,10 @@
from Houdini import Handlers
from Houdini.Handlers import XMLPacket
from Houdini.Converters import VersionChkConverter
from houdini import handlers
from houdini.handlers import XMLPacket
from houdini.converters import VersionChkConverter
@Handlers.handler(XMLPacket('verChk'))
@Handlers.allow_once()
@handlers.handler(XMLPacket('verChk'))
@handlers.allow_once()
async def handle_version_check(p, version: VersionChkConverter):
if not version == 153:
await p.send_xml({'body': {'action': 'apiKO', 'r': '0'}})
@ -13,7 +13,7 @@ async def handle_version_check(p, version: VersionChkConverter):
await p.send_xml({'body': {'action': 'apiOK', 'r': '0'}})
@Handlers.handler(XMLPacket('rndK'))
@Handlers.allow_once()
@handlers.handler(XMLPacket('rndK'))
@handlers.allow_once()
async def handle_random_key(p, data):
await p.send_xml({'body': {'action': 'rndK', 'r': '-1'}, 'k': 'houdini'})

View File

@ -1,10 +1,10 @@
from Houdini import Handlers
from Houdini.Handlers import XMLPacket, Login
from Houdini.Converters import CredentialsConverter
from Houdini.Data.Penguin import Penguin
from Houdini.Data.Buddy import BuddyList
from Houdini.Data.Moderator import Ban
from Houdini.Crypto import Crypto
from houdini import handlers
from houdini.handlers import XMLPacket, login
from houdini.converters import CredentialsConverter
from houdini.data.penguin import Penguin
from houdini.data.buddy import BuddyList
from houdini.data.moderator import Ban
from houdini.crypto import Crypto
import asyncio
import bcrypt
@ -15,8 +15,8 @@ import config
from datetime import datetime
@Handlers.handler(XMLPacket('login'))
@Handlers.allow_once()
@handlers.handler(XMLPacket('login'))
@handlers.allow_once()
async def handle_login(p, credentials: CredentialsConverter):
loop = asyncio.get_event_loop()
@ -97,7 +97,8 @@ async def handle_login(p, credentials: CredentialsConverter):
for server_name, server_config in servers_config.items():
if server_config['World']:
server_population = await p.server.redis.get('{}.population'.format(server_name))
server_population = int(server_population) / (server_config['Capacity'] / 6) if server_population else 0
server_population = (7 if int(server_population) == server_config['Capacity'] \
else int(server_population) / (server_config['Capacity'] / 6)) if server_population else 0
server_players = await p.server.redis.smembers('{}.players'.format(server_name))
@ -113,8 +114,9 @@ async def handle_login(p, credentials: CredentialsConverter):
buddy_worlds.append(server_config['Id'])
break
raw_login_data = '|'.join([str(data.ID), str(data.ID), data.Username, login_key, str(data.approval), '1'])
await p.send_xt('l', raw_login_data, confirmation_hash, 'friendsKey', '|'.join(world_populations), data.Email)
raw_login_data = '|'.join([str(data.ID), str(data.ID), data.Username, login_key, str(data.approval),
str(data.rejection)])
await p.send_xt('l', raw_login_data, confirmation_hash, '', '|'.join(world_populations), '|'.join(buddy_worlds), data.Email)
handle_version_check = Login.handle_version_check
handle_random_key = Login.handle_random_key
handle_version_check = login.handle_version_check
handle_random_key = login.handle_random_key

View File

@ -4,9 +4,9 @@ import sys
import pkgutil
import importlib
from Houdini.Spheniscidae import Spheniscidae
from Houdini.Penguin import Penguin
from Houdini import PenguinStringCompiler
from houdini.spheniscidae import Spheniscidae
from houdini.penguin import Penguin
from houdini import PenguinStringCompiler
import config
from aiologger import Logger
@ -20,15 +20,17 @@ import aioredis
from aiocache import SimpleMemoryCache
from watchdog.observers import Observer
from Houdini.Data import db
from Houdini.Data.Item import ItemCrumbsCollection
from Houdini.Data.Igloo import IglooCrumbsCollection, FurnitureCrumbsCollection, \
from houdini.data import db
from houdini.data.item import ItemCrumbsCollection
from houdini.data.igloo import IglooCrumbsCollection, FurnitureCrumbsCollection, \
LocationCrumbsCollection, FlooringCrumbsCollection
from Houdini.Data.Room import RoomCrumbsCollection
from Houdini.Data.Stamp import StampCrumbsCollection
from Houdini.Data.Ninja import CardCrumbsCollection
from Houdini.Data.Mail import PostcardCrumbsCollection
from Houdini.Data.Pet import PuffleCrumbsCollection, PuffleItemCrumbsCollection
from houdini.data.room import RoomCrumbsCollection
from houdini.data.stamp import StampCrumbsCollection
from houdini.data.ninja import CardCrumbsCollection
from houdini.data.mail import PostcardCrumbsCollection
from houdini.data.pet import PuffleCrumbsCollection, PuffleItemCrumbsCollection
from houdini.data.permission import PermissionCrumbsCollection
try:
import uvloop
@ -36,14 +38,14 @@ try:
except ImportError:
uvloop = None
import Houdini.Handlers
from Houdini.Handlers import listeners_from_module, remove_handlers_by_module
from Houdini.Events.HandlerFileEvent import HandlerFileEventHandler
from Houdini.Events.PluginFileEvent import PluginFileEventHandler
import houdini.handlers
from houdini.handlers import listeners_from_module, remove_handlers_by_module
from houdini.events.handler_file_event import HandlerFileEventHandler
from houdini.events.plugin_file_event import PluginFileEventHandler
from Houdini.Commands import commands_from_plugin
from houdini.commands import commands_from_plugin
import Houdini.Plugins as Plugins
import houdini.plugins as plugins
class HoudiniFactory:
@ -103,7 +105,7 @@ class HoudiniFactory:
os.mkdir(errors_log_directory)
if sys.platform != 'win32':
self.logger = Logger(name='Houdini')
self.logger = Logger(name='houdini')
universal_handler = AsyncTimedRotatingFileHandler(
filename=self.server_config['Logging']['General'],
backup_count=3,
@ -112,7 +114,7 @@ class HoudiniFactory:
error_handler = AsyncFileHandler(filename=self.server_config['Logging']['Errors'])
console_handler = AsyncStreamHandler(stream=sys.stdout)
else:
self.logger = logging.getLogger('Houdini')
self.logger = logging.getLogger('houdini')
universal_handler = RotatingFileHandler(self.server_config['Logging']['General'],
maxBytes=2097152, backupCount=3, encoding='utf-8')
@ -142,7 +144,7 @@ class HoudiniFactory:
self.config.database['Address'],
self.config.database['Name']))
self.logger.info('Houdini module instantiated')
self.logger.info('houdini module instantiated')
self.redis = await aioredis.create_redis_pool('redis://{}:{}'.format(
self.config.redis['Address'], self.config.redis['Port']),
@ -161,10 +163,10 @@ class HoudiniFactory:
PenguinStringCompiler.setup_default_builder(self.penguin_string_compiler)
PenguinStringCompiler.setup_anonymous_default_builder(self.anonymous_penguin_string_compiler)
self.load_handler_modules(exclude_load='Houdini.Handlers.Login.Login')
self.load_handler_modules(exclude_load='houdini.Handlers.Login.Login')
self.logger.info('World server started')
else:
self.load_handler_modules('Houdini.Handlers.Login.Login')
self.load_handler_modules('houdini.Handlers.Login.Login')
self.logger.info('Login server started')
self.items = await ItemCrumbsCollection.get_collection()
@ -203,8 +205,8 @@ class HoudiniFactory:
self.puffle_items = await PuffleItemCrumbsCollection.get_collection()
self.logger.info('Loaded {} puffle care items'.format(len(self.puffle_items)))
handlers_path = './Houdini{}Handlers'.format(os.path.sep)
plugins_path = './Houdini{}Plugins'.format(os.path.sep)
handlers_path = './houdini{}handlers'.format(os.path.sep)
plugins_path = './houdini{}plugins'.format(os.path.sep)
self.configure_observers([handlers_path, HandlerFileEventHandler],
[plugins_path, PluginFileEventHandler])
@ -216,7 +218,7 @@ class HoudiniFactory:
await self.server.serve_forever()
async def load_plugins(self):
for plugin_package in self.get_package_modules(Plugins):
for plugin_package in self.get_package_modules(plugins):
await self.load_plugin(plugin_package)
async def load_plugin(self, plugin):
@ -227,7 +229,7 @@ class HoudiniFactory:
plugin_object = getattr(plugin_module, plugin_class)(self)
if isinstance(plugin_object, Plugins.IPlugin):
if isinstance(plugin_object, plugins.IPlugin):
self.plugins[plugin_class] = plugin_object
listeners_from_module(self.xt_listeners, self.xml_listeners, plugin_object)
@ -251,7 +253,7 @@ class HoudiniFactory:
await client_object.run()
def load_handler_modules(self, strict_load=None, exclude_load=None):
for handler_module in self.get_package_modules(Houdini.Handlers):
for handler_module in self.get_package_modules(houdini.handlers):
if not (strict_load and handler_module not in strict_load or exclude_load and handler_module in exclude_load):
if handler_module not in sys.modules.keys():
module = importlib.import_module(handler_module)
@ -269,7 +271,7 @@ class HoudiniFactory:
subpackage_object = importlib.import_module(full_module_name, package=package.__path__)
subpackage_object_directory = dir(subpackage_object)
if Plugins.IPlugin.__name__ in subpackage_object_directory:
if plugins.IPlugin.__name__ in subpackage_object_directory:
package_modules.append((subpackage_object, module_name))
continue

View File

@ -1,4 +1,4 @@
from Houdini.Spheniscidae import Spheniscidae
from houdini.spheniscidae import Spheniscidae
class Penguin(Spheniscidae):

View File

@ -1,5 +1,5 @@
from Houdini import Handlers
from Houdini.Handlers import XMLPacket, XTPacket
from houdini import handlers
from houdini.handlers import XMLPacket, XTPacket
from asyncio import IncompleteReadError
@ -85,7 +85,7 @@ class Spheniscidae:
packet_id = parsed_data[2]
packet = XTPacket(packet_id)
if Handlers.listener_exists(self.server.xt_listeners, self.server.xml_listeners, packet):
if handlers.listener_exists(self.server.xt_listeners, self.server.xml_listeners, packet):
xt_listeners = self.server.xt_listeners[packet]
packet_data = parsed_data[4:]
@ -111,7 +111,7 @@ class Spheniscidae:
action = body_tag.get('action')
packet = XMLPacket(action)
if Handlers.listener_exists(self.server.xt_listeners, self.server.xml_listeners, packet):
if handlers.listener_exists(self.server.xt_listeners, self.server.xml_listeners, packet):
xml_listeners = self.server.xml_listeners[packet]
for listener in xml_listeners: