Skip to content

Commit 8783d2f

Browse files
committed
Download all assets
1 parent 2c34867 commit 8783d2f

File tree

7 files changed

+53
-18
lines changed

7 files changed

+53
-18
lines changed

oqtopus.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828

2929
from oqtopus.core.modules_config import load_modules_from_conf # noqa: E402
3030
from oqtopus.gui.main_dialog import MainDialog # noqa: E402
31+
from oqtopus.utils.plugin_utils import PluginUtils # noqa: E402
3132

3233

3334
def main():
3435
app = pyqt5_widgets.QApplication(sys.argv)
3536
icon = QIcon("oqtopus/icons/oqtopus-logo.png")
3637
app.setWindowIcon(icon)
3738

39+
PluginUtils.init_logger()
40+
3841
conf_path = os.path.join(os.path.dirname(__file__), "oqtopus/default_config.conf")
3942
modules_config = load_modules_from_conf(conf_path)
4043

oqtopus/core/module_asset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from enum import Enum
2+
3+
4+
class ModuleAsset:
5+
class Type(Enum):
6+
PLUGIN = "oqtopus.plugin"
7+
DATAMODEL = "oqtopus.datamodel"
8+
PROJECT = "oqtopus.project"
9+
10+
def __init__(
11+
self, name: str, label: str, download_url: str, size: int, type: "ModuleAsset.Type" = None
12+
):
13+
self.name = name
14+
self.label = label
15+
self.download_url = download_url
16+
self.size = size
17+
self.type = type

oqtopus/core/module_version.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import requests
22
from qgis.PyQt.QtCore import QDateTime, Qt
33

4+
from .module_asset import ModuleAsset
5+
46

57
class ModuleVersion:
68

@@ -10,13 +12,6 @@ class Type:
1012
BRANCH = "branch"
1113
PULL_REQUEST = "pull_request"
1214

13-
class Asset:
14-
def __init__(self, name: str, label: str, download_url: str, size: int):
15-
self.name = name
16-
self.label = label
17-
self.download_url = download_url
18-
self.size = size
19-
2015
def __init__(
2116
self,
2217
organisation,
@@ -81,23 +76,26 @@ def __parse_release_assets(self, assets_url: str):
8176

8277
json_assets = r.json()
8378
for json_asset in json_assets:
84-
85-
asset = ModuleVersion.Asset(
79+
asset = ModuleAsset(
8680
name=json_asset["name"],
8781
label=json_asset["label"],
8882
download_url=json_asset["browser_download_url"],
8983
size=json_asset["size"],
84+
type=None,
9085
)
9186

92-
if asset.label == "oqtopus_datamodel":
87+
if asset.label == ModuleAsset.Type.DATAMODEL.value:
88+
asset.type = ModuleAsset.Type.DATAMODEL
9389
self.asset_datamodel = asset
9490
continue
9591

96-
if asset.label == "oqtopus_project":
92+
if asset.label == ModuleAsset.Type.PROJECT.value:
93+
asset.type = ModuleAsset.Type.PROJECT
9794
self.asset_project = asset
9895
continue
9996

100-
if asset.label == "oqtopus_plugin":
97+
if asset.label == ModuleAsset.Type.PLUGIN.value:
98+
asset.type = ModuleAsset.Type.PLUGIN
10199
self.asset_plugin = asset
102100
continue
103101

oqtopus/core/package_prepare_task.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def run(self):
5858

5959
try:
6060
if self.module_version is not None:
61-
self.__download_module_version(self.module_version)
61+
self.__download_module_assets(self.module_version)
6262

6363
self.__extract_zip_file(self.zip_file)
6464

@@ -67,10 +67,23 @@ def run(self):
6767
print(f"Erorr: {e}")
6868
self.lastError = e
6969

70-
def __download_module_version(self, module_version):
70+
def __download_module_assets(self, module_version):
7171

72-
url = module_version.download_url
73-
filename = module_version.name + ".zip"
72+
if module_version.asset_datamodel is not None:
73+
self.__download_module_asset(module_version.asset_datamodel)
74+
75+
self.__checkForCanceled()
76+
if module_version.asset_project is not None:
77+
self.__download_module_asset(module_version.asset_project)
78+
79+
self.__checkForCanceled()
80+
if module_version.asset_plugin is not None:
81+
self.__download_module_asset(module_version.asset_plugin)
82+
83+
def __download_module_asset(self, module_asset):
84+
85+
url = module_asset.download_url
86+
filename = module_asset.type.value + ".zip"
7487

7588
temp_dir = PluginUtils.plugin_temp_path()
7689
destination_directory = os.path.join(temp_dir, "Downloads")

oqtopus/gui/main_dialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#
2323
# ---------------------------------------------------------------------
2424

25+
import logging
2526
import os
2627
import shutil
2728

@@ -67,7 +68,7 @@ def __init__(self, modules_config, parent=None):
6768

6869
self.loggingBridge = LoggingBridge()
6970
self.loggingBridge.loggedLine.connect(self.__logged_line)
70-
logger.addHandler(self.loggingBridge)
71+
logging.getLogger().addHandler(self.loggingBridge)
7172

7273
self.buttonBox.rejected.connect(self.__closeDialog)
7374
self.buttonBox.helpRequested.connect(self.__helpRequested)

oqtopus/oqtopus_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, iface):
3333
self.actions = []
3434
self.main_menu_name = self.tr(f"&{PluginUtils.PLUGIN_NAME}")
3535

36-
conf_path = os.path.join(os.path.dirname(__file__), "../default_config.conf")
36+
conf_path = os.path.join(os.path.dirname(__file__), "default_config.conf")
3737
self.modules_config = load_modules_from_conf(conf_path)
3838

3939
# noinspection PyMethodMayBeStatic

oqtopus/ui/main_dialog.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
</item>
150150
<item row="0" column="0" rowspan="4">
151151
<widget class="QTreeWidget" name="logs_treeWidget">
152+
<property name="selectionMode">
153+
<enum>QAbstractItemView::ContiguousSelection</enum>
154+
</property>
152155
<column>
153156
<property name="text">
154157
<string>Level</string>

0 commit comments

Comments
 (0)