Loading Dockerfile +4 −0 Original line number Diff line number Diff line Loading @@ -4,7 +4,11 @@ RUN apt-get -yqq update && apt-get -yqq upgrade && \ apt-get -yqq install vim COPY src/ tmp/src RUN set -eux && pip install --upgrade pip && \ cd /tmp/src/ && pip install -e . COPY ./test/test.py /test/test.py CMD ['sh', 'tail', '-f', '/dev/null'] src/common/database.py +7 −9 Original line number Diff line number Diff line Loading @@ -6,12 +6,13 @@ PostgreSQL database. However, the connection paramater may be specified to open any type of connection through implementation of this abstract class. """ import traceback from abc import ABCMeta, abstractmethod from abc import ABC, abstractmethod from common.logz import create_logger from common.env import check_environment as ce import psycopg2 class Database(ABCMeta): # from common.database import Database class Database(ABC): """ Provides an abstract class for connecting to a database using environmental variables. Loading Loading @@ -67,7 +68,8 @@ class Database(ABCMeta): :param connection_info: a dictionary containing connection info """ self.logger = create_logger() self.conection_info = connection_info self.connection_info = connection_info self.logger.debug(connection_info) self.connection = None self.cursor = None self.logger.debug('Database object successfully initialized') Loading @@ -93,10 +95,6 @@ class Database(ABCMeta): """ hande database closing when leaving with """ self.close() @abstractmethod def open(self): pass def silent_open(self): """Open database silently without returning anything.""" try: Loading Loading @@ -129,7 +127,7 @@ class Database(ABCMeta): def is_open(self): """Determine if the database is open or not.""" # TODO @Jonathan -- code review please if self.cursor is not None and self._connection is not None: if self.cursor is not None and self.connection is not None: # Test if both connection and cursor are on return True # If both are on, return True # If one or both connection and cursor are missing, return False Loading src/common/mixins/pandas.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import pandas as pd import sqlalchemy class Pandas_Mixin(): class PandasMixin(): """Group together all pandas logic.""" def query_pandas(self, query=None, table=None, schema=None): """Return a query as a pandas table. Loading src/common/mixins/postgres.py +2 −2 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ import psycopg2 class Postgres_Mixin(): class PostgresMixin(): """Serve common connection method for postgres.""" def open(self, search_path='public'): Loading @@ -27,7 +27,7 @@ class Postgres_Mixin(): connect_timeout=self.connection_info['dbTimeout']) self.connection.set_client_encoding('UTF8') self.logger.debug('Successfully opened connection to database') self.cursor = self._connection.cursor() self.cursor = self.connection.cursor() self.logger.debug('Successfully created a cursor') # TODO @Jonathan v--- not the default search paths - env var? """ ^---- need this re-explained """ Loading src/setup.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import os from setuptools import setup # update version information here _version = '0.1.5' _version = '0.1.6' # packages _packages = ['common', 'common.mixins'] Loading Loading
Dockerfile +4 −0 Original line number Diff line number Diff line Loading @@ -4,7 +4,11 @@ RUN apt-get -yqq update && apt-get -yqq upgrade && \ apt-get -yqq install vim COPY src/ tmp/src RUN set -eux && pip install --upgrade pip && \ cd /tmp/src/ && pip install -e . COPY ./test/test.py /test/test.py CMD ['sh', 'tail', '-f', '/dev/null']
src/common/database.py +7 −9 Original line number Diff line number Diff line Loading @@ -6,12 +6,13 @@ PostgreSQL database. However, the connection paramater may be specified to open any type of connection through implementation of this abstract class. """ import traceback from abc import ABCMeta, abstractmethod from abc import ABC, abstractmethod from common.logz import create_logger from common.env import check_environment as ce import psycopg2 class Database(ABCMeta): # from common.database import Database class Database(ABC): """ Provides an abstract class for connecting to a database using environmental variables. Loading Loading @@ -67,7 +68,8 @@ class Database(ABCMeta): :param connection_info: a dictionary containing connection info """ self.logger = create_logger() self.conection_info = connection_info self.connection_info = connection_info self.logger.debug(connection_info) self.connection = None self.cursor = None self.logger.debug('Database object successfully initialized') Loading @@ -93,10 +95,6 @@ class Database(ABCMeta): """ hande database closing when leaving with """ self.close() @abstractmethod def open(self): pass def silent_open(self): """Open database silently without returning anything.""" try: Loading Loading @@ -129,7 +127,7 @@ class Database(ABCMeta): def is_open(self): """Determine if the database is open or not.""" # TODO @Jonathan -- code review please if self.cursor is not None and self._connection is not None: if self.cursor is not None and self.connection is not None: # Test if both connection and cursor are on return True # If both are on, return True # If one or both connection and cursor are missing, return False Loading
src/common/mixins/pandas.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import pandas as pd import sqlalchemy class Pandas_Mixin(): class PandasMixin(): """Group together all pandas logic.""" def query_pandas(self, query=None, table=None, schema=None): """Return a query as a pandas table. Loading
src/common/mixins/postgres.py +2 −2 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ import psycopg2 class Postgres_Mixin(): class PostgresMixin(): """Serve common connection method for postgres.""" def open(self, search_path='public'): Loading @@ -27,7 +27,7 @@ class Postgres_Mixin(): connect_timeout=self.connection_info['dbTimeout']) self.connection.set_client_encoding('UTF8') self.logger.debug('Successfully opened connection to database') self.cursor = self._connection.cursor() self.cursor = self.connection.cursor() self.logger.debug('Successfully created a cursor') # TODO @Jonathan v--- not the default search paths - env var? """ ^---- need this re-explained """ Loading
src/setup.py +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import os from setuptools import setup # update version information here _version = '0.1.5' _version = '0.1.6' # packages _packages = ['common', 'common.mixins'] Loading