Skip to content

Commit

Permalink
Merge pull request #20 from IMTEK-Simulation/21_download_files
Browse files Browse the repository at this point in the history
ENH: Download files from manifest
  • Loading branch information
pastewka authored May 15, 2021
2 parents b03f5f1 + 3c7f570 commit d44aee4
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Change log for dtool-lookup-gui

0.3.0 (15May21)
---------------

- Download files from manifest

0.2.1 (26Oct20)
---------------

Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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_.

Expand Down
65 changes: 52 additions & 13 deletions dtool_lookup_gui/MainApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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']}")
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down
111 changes: 106 additions & 5 deletions dtool_lookup_gui/dtool-lookup-gui.glade
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.1 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkWindow">
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Server configuration</property>
<property name="show-close-button">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Users</property>
</object>
<packing>
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Storage</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab-fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkPopover" id="dependency-popover">
<property name="can-focus">False</property>
<property name="position">bottom</property>
Expand Down Expand Up @@ -147,21 +215,55 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="text" translatable="yes">About dtool-gui</property>
<property name="text" translatable="yes">Configure server</property>
<signal name="clicked" handler="on_configure_server_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkModelButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="text" translatable="yes">About dtool-lookup-gui</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="submenu">submenu0</property>
<property name="position">1</property>
</packing>
</child>
</object>
<object class="GtkMenu" id="manifest-menu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkMenuItem" id="manifest-open">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Open</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="manifest-show-in-files">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Show in file manager</property>
<property name="use-underline">True</property>
</object>
</child>
</object>
<object class="GtkTreeStore" id="manifest-treestore">
<columns>
<!-- column-name name -->
Expand Down Expand Up @@ -615,16 +717,15 @@
<property name="can-focus">True</property>
<property name="model">manifest-treestore</property>
<property name="search-column">0</property>
<signal name="row-activated" handler="on_manifest_row_activated" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="manifest-column1">
<property name="title" translatable="yes">Name</property>
<child>
<object class="GtkCellRendererText" id="manifest-renderer1">
<property name="editable">True</property>
</object>
<object class="GtkCellRendererText" id="manifest-renderer1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gbulb
pyyaml
PyGObject
scipy
dtool-lookup-api

0 comments on commit d44aee4

Please sign in to comment.