First setup of the store
This commit is contained in:
parent
e0758a7817
commit
d4c593208a
13
base.py
13
base.py
@ -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()
|
@ -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}')
|
||||
|
20
commander.py
20
commander.py
@ -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
0
models/__init__.py
Normal file
18
models/base.py
Normal file
18
models/base.py
Normal 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()}'
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
12
store.py
12
store.py
@ -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__)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user