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
|
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}')
|
||||||
|
20
commander.py
20
commander.py
@ -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()
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
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
|
|
||||||
|
@ -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
|
|
||||||
|
@ -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
|
|
||||||
|
@ -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
|
|
||||||
|
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.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__)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user