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.agent import Agent
from nullptr.models.system import System from nullptr.models.system import System
from nullptr.models.waypoint import Waypoint from nullptr.models.waypoint import Waypoint
from nullptr.models.marketplace import Marketplace
from nullptr.api import Api from nullptr.api import Api
from .util import * from .util import *
from time import sleep from time import sleep
@ -62,3 +63,7 @@ class Commander(CommandLine):
r = self.api.jumps(waypoint) r = self.api.jumps(waypoint)
pprint(r) 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): def get_file(self, typ, path):
if not isfile(path): if not isfile(path):
print(path)
return None return None
with open(path) as f: with open(path) as f:
data = json.load(f) data = json.load(f)
@ -70,17 +71,14 @@ class Store:
def update_list(self, typ, lst): def update_list(self, typ, lst):
return [self.update(typ, mg(d, 'symbol'), d) for d in 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'): if hasattr(path, 'path'):
path = path.path() path = path.path()
path = os.path.join(self.data_dir, path) path = os.path.join(self.data_dir, path)
if not isdir(path): if not isdir(path):
return return
ext = '.' + typ.ext() ext = '.' + typ.ext()
for f in os.listdir(path): for fil in list_files(path, recursive):
fil = os.path.join(path, f)
if not isfile(fil):
continue
if not fil.endswith(ext): if not fil.endswith(ext):
continue continue
yield self.get_file(typ, fil) yield self.get_file(typ, fil)

View File

@ -1,5 +1,20 @@
from datetime import datetime from datetime import datetime
from math import ceil 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): def must_get(d, k):
if type(k) == str: if type(k) == str: