Update commander.py, store.py and one other file

This commit is contained in:
Richard Bronkhorst 2023-06-12 14:32:58 +02:00
parent 9410726f07
commit db312d2e35
3 changed files with 23 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import argparse
from nullptr.models.agent import Agent
from nullptr.models.system import System
from nullptr.models.waypoint import Waypoint
from nullptr.models.marketplace import Marketplace
from nullptr.api import Api
from .util import *
from time import sleep
@ -61,4 +62,8 @@ class Commander(CommandLine):
waypoint = self.store.get(Waypoint, waypoint_str.upper())
r = self.api.jumps(waypoint)
pprint(r)
def do_test(self):
for m in self.store.all('', Marketplace, True):
print(m)

View File

@ -32,6 +32,7 @@ class Store:
def get_file(self, typ, path):
if not isfile(path):
print(path)
return None
with open(path) as f:
data = json.load(f)
@ -70,17 +71,14 @@ class Store:
def update_list(self, typ, lst):
return [self.update(typ, mg(d, 'symbol'), d) for d in lst]
def all(self, path, typ):
def all(self, path, typ, recursive=False):
if hasattr(path, 'path'):
path = path.path()
path = os.path.join(self.data_dir, path)
if not isdir(path):
return
ext = '.' + typ.ext()
for f in os.listdir(path):
fil = os.path.join(path, f)
if not isfile(fil):
continue
for fil in list_files(path, recursive):
if not fil.endswith(ext):
continue
yield self.get_file(typ, fil)

View File

@ -1,6 +1,21 @@
from datetime import datetime
from math import ceil
import os
from os.path import isfile
def list_files(path, recursive=False):
if recursive:
for p, dirnames, fils in os.walk(path):
for f in fils:
fil = os.path.join(p, f)
yield fil
else:
for f in os.listdir(path):
fil = os.path.join(path, f)
if not isfile(fil):
continue
yield fil
def must_get(d, k):
if type(k) == str:
k = k.split('.')