diff --git a/CHANGELOG.md b/CHANGELOG.md index 6af5aee6..4e4c3350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ Change log for dtool-lookup-gui +0.3.0 (15May21) +--------------- + +- Download files from manifest + 0.2.1 (26Oct20) --------------- diff --git a/README.rst b/README.rst index 12826def..caf0ed0b 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,10 @@ dtool-lookup-gui ================ +.. image:: https://badge.fury.io/py/dtool-lookup-gui.svg + :target: https://badge.fury.io/py/dtool-lookup-gui + :alt: PyPI package + dtool-lookup-gui is a graphical user interface for dtool_, dtool-lookup-server_ and dtool-lookup-server-dependency-graph-plugin_ written in Python_ and GTK_. diff --git a/dtool_lookup_gui/MainApplication.py b/dtool_lookup_gui/MainApplication.py index ebe0a02d..77c9e80c 100644 --- a/dtool_lookup_gui/MainApplication.py +++ b/dtool_lookup_gui/MainApplication.py @@ -23,9 +23,12 @@ # import asyncio +import concurrent.futures import locale import math import os +import shutil +import subprocess from contextlib import contextmanager from datetime import date, datetime from functools import reduce @@ -47,6 +50,10 @@ from .Dependencies import DependencyGraph, is_uuid from .GraphWidget import GraphWidget +def open(filename): + """Open file in system-default application""" + + @contextmanager def time_locale(name): # This code snippet was taken from: @@ -122,17 +129,18 @@ def fill_readme_tree_store_from_list(store, list_data, parent=None): else: append_entry(store, entry, current_data, parent) - for entry, value in data.items(): - if type(value) is list: - current = store.append(parent, - [entry, None, False, None]) - fill_readme_tree_store_from_list(store, value, parent=current) - elif type(value) is dict: - current = store.append(parent, - [entry, None, False, None]) - fill_readme_tree_store(store, value, parent=current) - else: - append_entry(store, entry, value, parent) + if data is not None: + for entry, value in data.items(): + if type(value) is list: + current = store.append(parent, + [entry, None, False, None]) + fill_readme_tree_store_from_list(store, value, parent=current) + elif type(value) is dict: + current = store.append(parent, + [entry, None, False, None]) + fill_readme_tree_store(store, value, parent=current) + else: + append_entry(store, entry, value, parent) def fill_manifest_tree_store(store, data, parent=None): @@ -221,10 +229,12 @@ def __init__(self, event_loop, builder, settings): self.datasets = None self.server_config = None + self.thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=2) + def _refresh_results(self): results_widget = self.builder.get_object('search-results') statusbar_widget = self.builder.get_object('main-statusbar') - if self.datasets and self.server_config: + if self.datasets is not None and self.server_config: statusbar_widget.push(0, f'{len(self.datasets)} datasets - ' f'Connected to lookup server version ' f"{self.server_config['version']}") @@ -338,10 +348,13 @@ async def connect(self): self.lookup = LookupClient(lookup_url=self.settings.lookup_url, auth_url=self.settings.authenticator_url, username=self.settings.username, - password=self.settings.password) + password=self.settings.password, + verify_ssl=False) try: await self.lookup.connect() self.server_config = await self.lookup.config() + if 'msg' in self.server_config: + self.show_error(self.server_config['msg']) self.datasets = await self.lookup.all() except Exception as e: self.show_error(str(e)) @@ -448,6 +461,32 @@ def on_readme_row_activated(self, tree_view, path, column): return True return False + def dtool_retrieve_item(self, uri, item_name, item_uuid): + dataset = dtoolcore.DataSet.from_uri(uri) + if item_uuid in dataset.identifiers: + shutil.copyfile(dataset.item_content_abspath(item_uuid), + f'/home/pastewka/Downloads/{item_name}') + subprocess.run(["xdg-open", f'/home/pastewka/Downloads/{item_name}']) + # The following lines should be more portable but don't run + #Gio.AppInfo.launch_default_for_uri( + # dataset.item_content_abspath(uuid)) + else: + self.show_error(f'Cannot open item {item_name}, since the UUID {uuid_name} ' + 'appears to exist in the lookup server only.') + + async def retrieve_item(self, uri, item_name, item_uuid): + loop = asyncio.get_event_loop() + await asyncio.wait([ + loop.run_in_executor(self.thread_pool, self.dtool_retrieve_item, + uri, item_name, item_uuid)]) + + def on_manifest_row_activated(self, tree_view, path, column): + store = tree_view.get_model() + iter = store.get_iter(path) + item = store.get_value(iter, 0) + uuid = store.get_value(iter, 3) + asyncio.ensure_future( + self.retrieve_item(self._selected_dataset['uri'], item, uuid)) def run_gui(): builder = Gtk.Builder() diff --git a/dtool_lookup_gui/dtool-lookup-gui.glade b/dtool_lookup_gui/dtool-lookup-gui.glade index bdd03304..0a5dfea7 100644 --- a/dtool_lookup_gui/dtool-lookup-gui.glade +++ b/dtool_lookup_gui/dtool-lookup-gui.glade @@ -1,7 +1,75 @@ - + + + False + + + True + False + vertical + + + True + False + Server configuration + True + + + False + True + 0 + + + + + True + True + True + + + True + True + + + + + + + + True + False + Users + + + False + + + + + + + + True + False + Storage + + + 1 + False + + + + + False + True + 1 + + + + + False bottom @@ -147,7 +215,8 @@ True True True - About dtool-gui + Configure server + False @@ -155,6 +224,19 @@ 1 + + + True + True + True + About dtool-lookup-gui + + + False + True + 2 + + submenu0 @@ -162,6 +244,26 @@ + + True + False + + + True + False + Open + True + + + + + True + False + Show in file manager + True + + + @@ -615,6 +717,7 @@ True manifest-treestore 0 + @@ -622,9 +725,7 @@ Name - - True - + 0 diff --git a/requirements.txt b/requirements.txt index 49bfee2e..12d421aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ gbulb pyyaml PyGObject scipy +dtool-lookup-api \ No newline at end of file