Skip to content

Commit

Permalink
Changing engine connection strings into piecewise strings with db nam…
Browse files Browse the repository at this point in the history
…e, username and password.
  • Loading branch information
ThomasThoren committed May 6, 2015
1 parent 49dcefd commit 4f20738
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 52 deletions.
3 changes: 3 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def pull():
def github(message):
'''Add, commit and push to Github.'''

print message
print type(message)

addthemall()
commit(message)
push()
Expand Down
10 changes: 8 additions & 2 deletions realestate/lib/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from realestate import db
from realestate.lib import parse
from realestate import log, PROJECT_DIR
from realestate import log, PROJECT_DIR, DATABASE_NAME


class Build(object):
Expand All @@ -28,7 +28,13 @@ def __init__(self, initial_date=None, until_date=None):
'''

base = declarative_base()
engine = create_engine(os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
engine = create_engine(
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(engine)
self.sn = sessionmaker(bind=engine)

Expand Down
16 changes: 13 additions & 3 deletions realestate/lib/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Vendor
)
from realestate.lib.libraries import Library
from realestate import log, USER
from realestate import log, USER, DATABASE_NAME


class Join(object):
Expand All @@ -37,7 +37,12 @@ def __init__(self, initial_date=None, until_date=None):

base = declarative_base()
self.engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(self.engine)
self.sn = sessionmaker(bind=self.engine)

Expand Down Expand Up @@ -289,7 +294,12 @@ def __init__(self, initial_date=None, until_date=None):

base = declarative_base()
self.engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(self.engine)
self.sn = sessionmaker(bind=self.engine)

Expand Down
34 changes: 22 additions & 12 deletions realestate/lib/delete_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
import sys
import psycopg2
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
Expand All @@ -20,7 +21,7 @@
Cleaned,
Detail
)
from realestate import log
from realestate import log, DATABASE_NAME


class DeleteDates(object):
Expand All @@ -32,10 +33,24 @@ def __init__(self, initial_date=None, until_date=None):

base = declarative_base()
self.engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(self.engine)
self.sn = sessionmaker(bind=self.engine)

self.conn = psycopg2.connect(
'host=localhost dbname=%s user=%s password=%s' % (
DATABASE_NAME,
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD')
)
)
self.cursor = self.conn.cursor()

self.initial_date = initial_date
self.until_date = until_date

Expand All @@ -52,17 +67,12 @@ def main(self):
def vacuum(self):
'''docstring'''

engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
conn = engine.connect()

old_isolation_level = conn.isolation_level
conn.set_isolation_level(0)
old_isolation_level = self.conn.isolation_level
self.conn.set_isolation_level(0)
sql = 'VACUUM;'
conn.execute(sql)
conn.set_isolation_level(old_isolation_level)

conn.close()
self.cursor.execute(sql)
self.conn.commit()
self.conn.set_isolation_level(old_isolation_level)

def delete_details(self):
session = self.sn()
Expand Down
10 changes: 8 additions & 2 deletions realestate/lib/form_tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from subprocess import call

from realestate.db import Cleaned
from realestate import log, TODAY_DATE, PROJECT_DIR
from realestate import log, TODAY_DATE, PROJECT_DIR, DATABASE_NAME
from realestate.lib.twitter import Twitter


Expand All @@ -29,7 +29,13 @@ def __init__(self):
'''Initialize self variables and establish connection to database.'''

base = declarative_base()
engine = create_engine(os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
engine = create_engine(
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(engine)
self.sn = sessionmaker(bind=engine)

Expand Down
9 changes: 7 additions & 2 deletions realestate/lib/geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Location,
Neighborhood
)
from realestate import log
from realestate import log, DATABASE_NAME


class Geocode(object):
Expand All @@ -40,7 +40,12 @@ def __init__(self, initial_date=None, until_date=None):

base = declarative_base()
self.engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(self.engine)
self.sn = sessionmaker(bind=self.engine)

Expand Down
9 changes: 7 additions & 2 deletions realestate/lib/get_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sqlalchemy.ext.declarative import declarative_base

from realestate.db import Detail
from realestate import log, YESTERDAY_DATE, OPENING_DATE
from realestate import log, YESTERDAY_DATE, OPENING_DATE, DATABASE_NAME


class GetDates(object):
Expand All @@ -21,7 +21,12 @@ def __init__(self):

base = declarative_base()
self.engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(self.engine)
self.sn = sessionmaker(bind=self.engine)

Expand Down
10 changes: 8 additions & 2 deletions realestate/lib/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Detail,
Location
)
from realestate import log
from realestate import log, DATABASE_NAME


class Publish(object):
Expand All @@ -34,7 +34,13 @@ def __init__(self, initial_date=None, until_date=None):
'''Initialize self variables and establish connection to database.'''

base = declarative_base()
engine = create_engine(os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
engine = create_engine(
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
base.metadata.create_all(engine)
self.sn = sessionmaker(bind=engine)

Expand Down
8 changes: 7 additions & 1 deletion realestate/lib/stat_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
from sqlalchemy import create_engine
from realestate import DATABASE_NAME


class StatAnalysis(object):
Expand All @@ -18,7 +19,12 @@ def __init__(self, initial_date=None, until_date=None):
self.until_date = until_date

self.engine = create_engine(
os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)

def count(self):
'''Get number of records.'''
Expand Down
27 changes: 8 additions & 19 deletions realestate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# from realestate.lib.check_assessor_urls import Assessor
from realestate.lib.results_language import ResultsLanguage
from realestate.lib.utils import Utils
from realestate import log, TODAY_DAY
from realestate import log, TODAY_DAY, DATABASE_NAME


class Models(object):
Expand All @@ -41,30 +41,19 @@ def __init__(self, initial_date=None, until_date=None):
:type until_date: string
'''

log.debug('1')

self.initial_date = initial_date

log.debug('2')

self.until_date = until_date

log.debug('3')

base = declarative_base()

log.debug('4')

try:
log.debug('try')
print os.environ.get('REAL_ESTATE_SERVER_ENGINE')
log.debug('why')
except Exception, error:
log.debug(error, exc_info=True)

log.debug('5')

engine = create_engine(os.environ.get('REAL_ESTATE_SERVER_ENGINE'))
engine = create_engine(
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)

base.metadata.create_all(engine)

Expand Down
8 changes: 6 additions & 2 deletions scripts/delete_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def __init__(self):
'''Establish connection to the database.'''

engine = create_engine(
'%s' % (os.environ.get('REAL_ESTATE_SERVER_ENGINE')))
'postgresql://%s:%s@localhost/%s' % (
os.environ.get('REAL_ESTATE_DATABASE_USERNAME'),
os.environ.get('REAL_ESTATE_DATABASE_PASSWORD'),
DATABASE_NAME
)
)
self.conn = engine.connect()
self.trans = self.conn.begin()
self.inspector = reflection.Inspector.from_engine(engine)
Expand Down Expand Up @@ -77,7 +82,6 @@ def drop_db():

log.debug('drop DB')

# Backup dashboard table, if it exists
try:
call([
'dropdb',
Expand Down
Loading

0 comments on commit 4f20738

Please sign in to comment.