From db312d2e35c21554f5c6a3ace5e6add4d5bf1d18 Mon Sep 17 00:00:00 2001 From: Richard Bronkhorst Date: Mon, 12 Jun 2023 14:32:58 +0200 Subject: [PATCH] Update commander.py, store.py and one other file --- nullptr/commander.py | 5 +++++ nullptr/store.py | 8 +++----- nullptr/util.py | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/nullptr/commander.py b/nullptr/commander.py index 9568d4e..946f08e 100644 --- a/nullptr/commander.py +++ b/nullptr/commander.py @@ -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) diff --git a/nullptr/store.py b/nullptr/store.py index c15fc00..52964e3 100644 --- a/nullptr/store.py +++ b/nullptr/store.py @@ -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) diff --git a/nullptr/util.py b/nullptr/util.py index 2646157..a5ea388 100644 --- a/nullptr/util.py +++ b/nullptr/util.py @@ -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('.')