First setup of the store

This commit is contained in:
Richard Bronkhorst 2023-06-09 13:19:47 +02:00
parent e0758a7817
commit d4c593208a
10 changed files with 51 additions and 70 deletions

13
base.py
View File

@ -1,13 +0,0 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
def get_session(fil):
fil = 'data/store.db'
engine = create_engine('sqlite:///' + fil)
Session = sessionmaker(bind=engine)
return engine, Session
Base = declarative_base()

View File

@ -28,7 +28,7 @@ class CommandLine:
self.stopping = True self.stopping = True
def prompt(self): def prompt(self):
return '> hh' return '> '
def handle_not_found(self, c, args): def handle_not_found(self, c, args):
print(f'command not found; {c}') print(f'command not found; {c}')

View File

@ -1,16 +1,16 @@
#!/usr/bin/env python3
import logging
import argparse
from store import Store from store import Store
import importlib
import sys
from command_line import CommandLine from command_line import CommandLine
import argparse
class Commander(CommandLine): class Commander(CommandLine):
def __init__(self, store_dir):
self.store_dir = store_dir
self.store = Store(store_dir)
super().__init__()
def do_foo(self): def do_foo(self):
store_file = 'data/store.db' self.store.foo()
s = Store(store_file)
s.foo()
def main(args):
Commander().run() args = parser.parse_args()
main(args)

0
models/__init__.py Normal file
View File

18
models/base.py Normal file
View File

@ -0,0 +1,18 @@
class Base:
symbol: str
def __init__(self, symbol, store):
self.symbol = symbol
self.store = store
def path(self):
raise NotImplementedError('path')
def ext(self):
raise NotImplementedError('extension')
def type(self):
return self.__class__.__name__
def __str__(self):
return f'{self.symbol}.{self.ext()}'

View File

@ -1,13 +1,5 @@
from sqlalchemy import Column, String, Integer, Date from .base import Base
from base import Base
class Sector(Base): class Sector(Base):
__tablename__ = 'sectors' def ext(self):
return 'sct'
id = Column(Integer, primary_key=True)
symbol = Column(String)
magic = Column(Integer)
def __init__(self, symbol):
self.symbol = symbol

View File

@ -1,15 +1,8 @@
from sqlalchemy import Column, String, Integer, Date from .base import Base
from base import Base
class Setting(Base): class Setting(Base):
__tablename__ = 'settings' name: str
value: str
id = Column(Integer, primary_key=True) def ext(self):
name = Column(String) return 'set'
value = Column(String)
def __init__(self, name, value):
self.name = name
self.value = value

View File

@ -1,13 +1,7 @@
from sqlalchemy import Column, String, Integer, Date
from base import Base from .base import Base
class System(Base): class System(Base):
__tablename__ = 'systems' def ext(self):
return 'stm'
id = Column(Integer, primary_key=True)
symbol = Column(String)
def __init__(self, symbol):
self.symbol = symbol

View File

@ -1,13 +1,6 @@
from sqlalchemy import Column, String, Integer, Date from .base import Base
from base import Base
class Waypoint(Base): class Waypoint(Base):
__tablename__ = 'waypoints' def ext(self):
return 'way'
id = Column(Integer, primary_key=True)
symbol = Column(String)
def __init__(self, symbol):
self.symbol = symbol

View File

@ -1,10 +1,14 @@
from base import get_session, Base from models.base import Base
from models.waypoint import Waypoint
from models.sector import Sector from models.sector import Sector
from models.system import System from models.system import System
from models.setting import Setting
class Store: class Store:
def __init__(self, fil): def __init__(self, fil):
self.engine, self.session = get_session(fil) pass
Base.metadata.create_all(self.engine)
def foo(self): def foo(self):
print('goo') w = Waypoint('jdjdj', self)
print(w.__dict__)