obj function
This commit is contained in:
parent
237dcc8c14
commit
08ab3f0999
@ -194,7 +194,7 @@ class Api:
|
|||||||
def flight_mode(self, ship, mode):
|
def flight_mode(self, ship, mode):
|
||||||
data = {'flightMode': mode}
|
data = {'flightMode': mode}
|
||||||
data = self.request('patch', f'my/ships/{ship}/nav', data)
|
data = self.request('patch', f'my/ships/{ship}/nav', data)
|
||||||
ship.update(data)
|
ship.update({'nav':data})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def jump(self, ship, waypoint):
|
def jump(self, ship, waypoint):
|
||||||
|
@ -496,7 +496,27 @@ class Commander(CommandLine):
|
|||||||
def do_defrag(self):
|
def do_defrag(self):
|
||||||
self.store.defrag()
|
self.store.defrag()
|
||||||
|
|
||||||
|
def do_obj(self, oid):
|
||||||
|
if not '.' in oid:
|
||||||
|
print('Usage: obj SYMBOL.ext')
|
||||||
|
return
|
||||||
|
symbol, ext = oid.split('.')
|
||||||
|
symbol = symbol.upper()
|
||||||
|
if not ext in self.store.extensions:
|
||||||
|
print('unknown extension')
|
||||||
|
typ = self.store.extensions[ext]
|
||||||
|
obj = self.store.get(typ, symbol)
|
||||||
|
if obj is None:
|
||||||
|
print('object not found')
|
||||||
|
pprint(obj.__getstate__())
|
||||||
|
print('=== store ===')
|
||||||
|
h = self.store.get_header(obj)
|
||||||
|
if h:
|
||||||
|
pprint(h, 3)
|
||||||
|
else:
|
||||||
|
print('Not stored')
|
||||||
|
print('Dirty: ', obj in self.store.dirty_objects)
|
||||||
|
|
||||||
def do_query(self, resource):
|
def do_query(self, resource):
|
||||||
if not self.has_ship(): return
|
if not self.has_ship(): return
|
||||||
location = self.ship.location
|
location = self.ship.location
|
||||||
|
@ -145,6 +145,8 @@ class Ship(Base):
|
|||||||
r += f'Role: {role}\n'
|
r += f'Role: {role}\n'
|
||||||
r += f'Mission: {self.mission} ({mstatus})\n'
|
r += f'Mission: {self.mission} ({mstatus})\n'
|
||||||
for k, v in self.mission_state.items():
|
for k, v in self.mission_state.items():
|
||||||
|
if type(v) == list:
|
||||||
|
v = f'[{len(v)} items]'
|
||||||
r += f' {k}: {v}\n'
|
r += f' {k}: {v}\n'
|
||||||
adj = 'to' if self.status == 'IN_TRANSIT' else 'at'
|
adj = 'to' if self.status == 'IN_TRANSIT' else 'at'
|
||||||
r += f'Status {self.status} {adj} {self.location}\n'
|
r += f'Status {self.status} {adj} {self.location}\n'
|
||||||
|
@ -59,7 +59,16 @@ class ChunkHeader:
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'chunk {self.in_use} {self.size} {self.used}'
|
return f'chunk {self.in_use} {self.size} {self.used}'
|
||||||
|
|
||||||
|
def f(self, detail=1):
|
||||||
|
if detail == 1:
|
||||||
|
return f'chunk {self.offset} {self.used}/{self.size}'
|
||||||
|
else:
|
||||||
|
r = f'Stored at: {self.offset}\n'
|
||||||
|
slack = self.size - self.used
|
||||||
|
r += f'Used: {self.used}/{self.size} (slack {slack})'
|
||||||
|
return r
|
||||||
|
|
||||||
class Store:
|
class Store:
|
||||||
def __init__(self, data_file, verbose=False):
|
def __init__(self, data_file, verbose=False):
|
||||||
self.init_models()
|
self.init_models()
|
||||||
@ -146,6 +155,13 @@ class Store:
|
|||||||
h.offset = offset
|
h.offset = offset
|
||||||
h.write(self.fil)
|
h.write(self.fil)
|
||||||
return offset, h
|
return offset, h
|
||||||
|
|
||||||
|
def get_header(self, obj):
|
||||||
|
if obj._file_offset is None:
|
||||||
|
return None
|
||||||
|
self.fil.seek(obj._file_offset)
|
||||||
|
hdr = ChunkHeader.parse(self.fil)
|
||||||
|
return hdr
|
||||||
|
|
||||||
def purge(self, obj):
|
def purge(self, obj):
|
||||||
if obj._file_offset is None:
|
if obj._file_offset is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user