Skip to content

Commit

Permalink
factory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fpurcell committed Mar 13, 2018
1 parent f4c31fd commit 4868c33
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions gtfsdb/model/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ def metadata(self):
from gtfsdb.model.base import Base
return Base.metadata

@classmethod
def factory(cls, **kwargs):
db = cls(**kwargs)
if kwargs.get('create'):
db.create()
return db

@classmethod
def factory_from_cmdline(cls, args):
kwargs = dict(
tables=args.tables,
is_geospatial=args.is_geospatial,
schema=args.schema,
url=args.database_url,
create=args.create
)
db = cls(**kwargs)
if args.create:
db.create()
return db
return cls.factory(**kwargs)

def load_tables(self, **kwargs):
""" load the sorted classes """
for cls in self.sorted_classes:
cls.load(self, **kwargs)

def create(self):
"""Drop/create GTFS database"""
Expand Down

0 comments on commit 4868c33

Please sign in to comment.