Skip to content

Commit

Permalink
ENH: Tree view for manifest, closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pastewka committed Oct 26, 2020
1 parent 7479dec commit 2b374c4
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions dtool_lookup_gui/MainApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def human_readable_file_size(num, suffix='B'):
val = num / math.pow(1024, magnitude)
if magnitude > 7:
return '{:.1f}{}{}'.format(val, 'Yi', suffix)
return '{:3.1f}{}{}'.format(val,
['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi'][
magnitude], suffix)
return '{:3.1f}{}{}'.format(val, ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi'][magnitude], suffix)


def fill_readme_tree_store(store, data, parent=None):
Expand Down Expand Up @@ -137,9 +135,24 @@ def fill_readme_tree_store_from_list(store, list_data, parent=None):


def fill_manifest_tree_store(store, data, parent=None):
for uuid, values in data.items():
store.append(parent,
[values['relpath'],
nodes = {}

def find_or_create_parent_node(path, top_parent):
if not path:
return top_parent
try:
return nodes[path]
except KeyError:
head, tail = os.path.split(path)
parent = find_or_create_parent_node(head, top_parent)
new_node = store.append(parent, [tail, '', '', ''])
nodes[path] = new_node
return new_node

for uuid, values in sorted(data.items(), key=lambda kv: kv[1]['relpath']):
head, tail = os.path.split(values['relpath'])
store.append(find_or_create_parent_node(head, parent),
[tail,
human_readable_file_size(values['size_in_bytes']),
f'{date_to_string(values["utc_timestamp"])}',
uuid])
Expand Down Expand Up @@ -271,7 +284,10 @@ async def _fetch_manifest(self, uri):
store = manifest_view.get_model()
store.clear()
self._manifest = await self.lookup.manifest(uri)
fill_manifest_tree_store(store, self._manifest['items'])
try:
fill_manifest_tree_store(store, self._manifest['items'])
except Exception as e:
print(e)
manifest_view.columns_autosize()
manifest_view.show_all()

Expand Down

0 comments on commit 2b374c4

Please sign in to comment.