Skip to content

Commit

Permalink
Merge pull request #59 from waartaa/logging
Browse files Browse the repository at this point in the history
Implement logging, unified import layout
  • Loading branch information
rtnpro committed Apr 18, 2016
2 parents b9e1946 + 6012aae commit d773252
Show file tree
Hide file tree
Showing 39 changed files with 106 additions and 54 deletions.
1 change: 0 additions & 1 deletion ircb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
15 changes: 8 additions & 7 deletions ircb/bouncer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-
import asyncio
from collections import defaultdict
import logging
import logging.config
from ircb.connection import Connection

from collections import defaultdict

import ircb.stores

from ircb.config import settings
from ircb.storeclient import (NetworkStore, ClientStore, ChannelStore,
UserStore, initialize as storeclient_initialize)
from ircb.connection import Connection
from ircb.irc import IrcbBot

from ircb.storeclient import initialize as storeclient_initialize
from ircb.storeclient import ChannelStore, ClientStore, NetworkStore, UserStore

logger = logging.getLogger('bouncer')

Expand Down Expand Up @@ -250,7 +252,6 @@ def unregister_client(self, network_id, client):


def runserver(host='0.0.0.0', port=9000, mode='allinone'):
logging.config.dictConfig(settings.LOGGING_CONF)
if mode == 'allinone':
ircb.stores.initialize()
storeclient_initialize()
Expand Down
7 changes: 3 additions & 4 deletions ircb/cli/loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import yaml

from ircb.lib.async import coroutinize
from ircb.storeclient import UserStore
from ircb.storeclient import NetworkStore
from ircb.storeclient import NetworkStore, UserStore


@click.group(name='users')
Expand All @@ -13,7 +12,7 @@ def loaddata_cli():
pass


def validate_yaml(f):
def validate_yaml(f):
"Validates YAML file"
return True

Expand All @@ -25,7 +24,7 @@ def load_data(f):
with open(f, 'r') as f:
config = yaml.load(f)

if validate_yaml(config):
if validate_yaml(config):

for user in config.keys():
user_data = config[user]
Expand Down
8 changes: 4 additions & 4 deletions ircb/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import click

from ircb.cli.user import user_cli
from ircb.cli.loaddata import load_data
from ircb.cli.network import network_cli
from ircb.cli.run import run_cli
from ircb.cli.loaddata import load_data

from ircb.cli.user import user_cli
from ircb.utils.config import load_config

@click.group()
def cli():
"""ircb CLI"""
pass
load_config()


cli.add_command(user_cli)
Expand Down
2 changes: 1 addition & 1 deletion ircb/cli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from tabulate import tabulate

from ircb.storeclient import NetworkStore
from ircb.lib.async import coroutinize
from ircb.storeclient import NetworkStore


@click.group(name='networks')
Expand Down
6 changes: 2 additions & 4 deletions ircb/cli/run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
import click
import logging
import logging.config
from ircb.config import settings

from ircb.bouncer import runserver
from ircb.config import settings


@click.group(name='run')
Expand All @@ -27,7 +26,6 @@ def run_server(host, port, mode):

@click.command(name='stores')
def run_stores():
logging.config.dictConfig(settings.LOGGING_CONF)
import ircb.stores
import ircb.stores.base
ircb.stores.initialize()
Expand Down
3 changes: 3 additions & 0 deletions ircb/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

import os

from . import default_settings


Expand Down
10 changes: 10 additions & 0 deletions ircb/config/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
}
),
loggers=dict(
ircb={
"level": "DEBUG",
"propagate": False,
"handlers": ["console"],
},
network={
"level": "DEBUG",
"propagate": False,
Expand All @@ -47,6 +52,11 @@
"level": "DEBUG",
"propagate": False,
"handlers": ["console"],
},
aiohttp={
"level": "DEBUG",
"propagate": False,
"handlers": ["console"],
}
),
)
Expand Down
1 change: 1 addition & 0 deletions ircb/connection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import asyncio


Expand Down
1 change: 1 addition & 0 deletions ircb/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from .network import NetworkForm

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions ircb/forms/network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from wtforms_alchemy import ModelForm
from wtforms.fields import SelectField

Expand Down
1 change: 1 addition & 0 deletions ircb/forms/user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from wtforms_alchemy import ModelForm

from ircb.models import User
Expand Down
1 change: 0 additions & 1 deletion ircb/irc/plugins/autojoins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

import irc3
from irc3.plugins.autojoins import AutoJoins as Irc3AutoJoins

Expand Down
1 change: 1 addition & 0 deletions ircb/irc/plugins/ircb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import asyncio
import irc3

Expand Down
1 change: 1 addition & 0 deletions ircb/lib/async.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import asyncio


Expand Down
4 changes: 3 additions & 1 deletion ircb/lib/dispatcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
import asyncio
import aiozmq.rpc
import aioredis
from collections import defaultdict
import logging

from collections import defaultdict

from ircb.config import settings

logger = logging.getLogger('dispatcher')
Expand Down
1 change: 1 addition & 0 deletions ircb/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from .network import Network
from .user import User
from .channel import Channel
Expand Down
5 changes: 2 additions & 3 deletions ircb/models/channel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-

import datetime

from sqlalchemy import (Column, String, Integer, ForeignKey, DateTime,
UniqueConstraint)
from sqlalchemy import Column, String, Integer, ForeignKey, DateTime
from sqlalchemy import UniqueConstraint
from sqlalchemy_utils import ChoiceType

from ircb.config import settings
Expand Down
6 changes: 3 additions & 3 deletions ircb/models/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

import datetime
from sqlalchemy import (Column, String, Integer, ForeignKey, DateTime,
UniqueConstraint)

from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
from sqlalchemy import UniqueConstraint

from ircb.models.lib import Base

Expand Down
2 changes: 2 additions & 0 deletions ircb/models/lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import scoped_session

from ircb.config import settings


Expand Down
3 changes: 2 additions & 1 deletion ircb/models/network.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-

import datetime

from hashlib import md5

import sqlalchemy as sa

from sqlalchemy_utils import ChoiceType, Choice

from ircb.models.lib import Base, get_session
Expand Down
6 changes: 4 additions & 2 deletions ircb/models/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime

from flask_user import UserMixin
from sqlalchemy import (Column, String, Unicode, Boolean, ForeignKey, Integer,
DateTime)
from sqlalchemy import Column, String, Unicode, Boolean, ForeignKey, Integer
from sqlalchemy import DateTime
from sqlalchemy.orm import relationship, backref
from sqlalchemy_utils import PasswordType

from ircb.models.lib import Base


Expand Down
1 change: 1 addition & 0 deletions ircb/storeclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from .network import NetworkStore
Expand Down
2 changes: 2 additions & 0 deletions ircb/storeclient/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import asyncio

from uuid import uuid1

from ircb.lib.dispatcher import Dispatcher
Expand Down
1 change: 1 addition & 0 deletions ircb/storeclient/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from ircb.models import Client
from ircb.storeclient.base import BaseStore
from ircb.lib.constants.signals import (STORE_CLIENT_CREATE,
Expand Down
11 changes: 7 additions & 4 deletions ircb/storeclient/network.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-
from ircb.models import Network
from ircb.storeclient.base import BaseStore
from ircb.lib.constants.signals import (
STORE_NETWORK_CREATE, STORE_NETWORK_CREATED,
STORE_NETWORK_GET, STORE_NETWORK_GOT,
STORE_NETWORK_UPDATE, STORE_NETWORK_UPDATED)
from ircb.lib.constants.signals import (STORE_NETWORK_CREATE,
STORE_NETWORK_CREATED,
STORE_NETWORK_GET,
STORE_NETWORK_GOT,
STORE_NETWORK_UPDATE,
STORE_NETWORK_UPDATED)


class NetworkStore(BaseStore):
Expand Down
8 changes: 5 additions & 3 deletions ircb/storeclient/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from ircb.models import User
from ircb.storeclient.base import BaseStore
from ircb.lib.constants.signals import (
STORE_USER_CREATE, STORE_USER_CREATED,
STORE_USER_GET, STORE_USER_GOT)
from ircb.lib.constants.signals import (STORE_USER_CREATE,
STORE_USER_CREATED,
STORE_USER_GET,
STORE_USER_GOT)


class UserStore(BaseStore):
Expand Down
1 change: 1 addition & 0 deletions ircb/stores/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from ircb.models import create_tables
Expand Down
4 changes: 2 additions & 2 deletions ircb/stores/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
import logging

from ircb.lib.dispatcher import Dispatcher
from ircb.models.lib import Base

import logging

logger = logging.getLogger('stores')


Expand Down
1 change: 0 additions & 1 deletion ircb/stores/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from ircb.models import Client, Network, get_session
from ircb.lib.constants.signals import (STORE_CLIENT_CREATE,
STORE_CLIENT_CREATED,
Expand Down
11 changes: 7 additions & 4 deletions ircb/stores/network.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from ircb.lib.constants.signals import (
STORE_NETWORK_CREATE, STORE_NETWORK_CREATED,
STORE_NETWORK_UPDATE, STORE_NETWORK_UPDATED,
STORE_NETWORK_GET, STORE_NETWORK_GOT)
# -*- coding: utf-8 -*-
from ircb.lib.constants.signals import (STORE_NETWORK_CREATE,
STORE_NETWORK_CREATED,
STORE_NETWORK_UPDATE,
STORE_NETWORK_UPDATED,
STORE_NETWORK_GET,
STORE_NETWORK_GOT)
from ircb.models import get_session, User, Network
from ircb.stores.base import BaseStore

Expand Down
8 changes: 5 additions & 3 deletions ircb/stores/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ircb.lib.constants.signals import (
STORE_USER_CREATE, STORE_USER_CREATED,
STORE_USER_GET, STORE_USER_GOT)
# -*- coding: utf-8 -*-
from ircb.lib.constants.signals import (STORE_USER_CREATE,
STORE_USER_CREATED,
STORE_USER_GET,
STORE_USER_GOT)
from ircb.models import get_session, User
from ircb.stores.base import BaseStore

Expand Down
Empty file added ircb/utils/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions ircb/utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
import logging.config

from ircb.config import settings

def load_config():
logging.config.dictConfig(settings.LOGGING_CONF)
Loading

0 comments on commit d773252

Please sign in to comment.