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
def prompt(self):
return '> hh'
return '> '
def handle_not_found(self, c, args):
print(f'command not found; {c}')

View File

@ -1,16 +1,16 @@
#!/usr/bin/env python3
import logging
import argparse
from store import Store
import importlib
import sys
from command_line import CommandLine
import argparse
class Commander(CommandLine):
def __init__(self, store_dir):
self.store_dir = store_dir
self.store = Store(store_dir)
super().__init__()
def do_foo(self):
store_file = 'data/store.db'
s = Store(store_file)
s.foo()
self.store.foo()
Commander().run()
def main(args):
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):
__tablename__ = 'sectors'
id = Column(Integer, primary_key=True)
symbol = Column(String)
magic = Column(Integer)
def __init__(self, symbol):
self.symbol = symbol
def ext(self):
return 'sct'

View File

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

View File

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

View File

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

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.system import System
from models.setting import Setting
class Store:
def __init__(self, fil):
self.engine, self.session = get_session(fil)
Base.metadata.create_all(self.engine)
pass
def foo(self):
print('goo')
w = Waypoint('jdjdj', self)
print(w.__dict__)