Skip to content

Commit bb51e69

Browse files
committed
Token
1 parent 09d0a94 commit bb51e69

File tree

10 files changed

+189
-36
lines changed

10 files changed

+189
-36
lines changed

oqtopus/core/module.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22

3+
from ..utils.plugin_utils import PluginUtils
34
from .module_version import ModuleVersion
45

56

@@ -17,7 +18,8 @@ def __repr__(self):
1718

1819
def load_versions(self):
1920
r = requests.get(
20-
f"https://api.github.com/repos/{self.organisation}/{self.repository}/releases"
21+
f"https://api.github.com/repos/{self.organisation}/{self.repository}/releases",
22+
headers=PluginUtils.get_github_headers(),
2123
)
2224

2325
# Raise an exception in case of http errors
@@ -74,7 +76,8 @@ def load_development_versions(self):
7476

7577
# Load versions from pull requests
7678
r = requests.get(
77-
f"https://api.github.com/repos/{self.organisation}/{self.repository}/pulls"
79+
f"https://api.github.com/repos/{self.organisation}/{self.repository}/pulls",
80+
headers=PluginUtils.get_github_headers(),
7881
)
7982

8083
# Raise an exception in case of http errors

oqtopus/core/module_version.py

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

4+
from ..utils.plugin_utils import PluginUtils
45
from .module_asset import ModuleAsset
56

67

@@ -72,7 +73,7 @@ def __parse_release(self, json_payload: dict):
7273
def __parse_release_assets(self, assets_url: str):
7374

7475
# Load assets
75-
r = requests.get(assets_url)
76+
r = requests.get(assets_url, headers=PluginUtils.get_github_headers())
7677

7778
# Raise an exception in case of http errors
7879
r.raise_for_status()

oqtopus/gui/main_dialog.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
QDialog,
3636
QFileDialog,
3737
QMenu,
38+
QMenuBar,
3839
QMessageBox,
3940
QStyle,
4041
QTreeWidgetItem,
@@ -44,13 +45,15 @@
4445
from ..core.module_version import ModuleVersion
4546
from ..core.package_prepare_task import PackagePrepareTask
4647
from ..libs import pgserviceparser
47-
from ..libs.pum.config import PumConfig
48+
from ..libs.pum.pum_config import PumConfig
4849
from ..libs.pum.schema_migrations import SchemaMigrations
4950
from ..libs.pum.upgrader import Upgrader
5051
from ..utils.plugin_utils import LoggingBridge, PluginUtils, logger
5152
from ..utils.qt_utils import CriticalMessageBox, OverrideCursor, QtUtils
53+
from .about_dialog import AboutDialog
5254
from .database_create_dialog import DatabaseCreateDialog
5355
from .database_duplicate_dialog import DatabaseDuplicateDialog
56+
from .settings_dialog import SettingsDialog
5457

5558
DIALOG_UI = PluginUtils.get_ui_class("main_dialog.ui")
5659

@@ -105,6 +108,22 @@ def __init__(self, modules_config, parent=None):
105108
self.__packagePrepareTaskProgress
106109
)
107110

111+
# Add menubar
112+
self.menubar = QMenuBar(self)
113+
self.layout().setMenuBar(self.menubar)
114+
115+
# Settings action
116+
settings_action = QAction(self.tr("Settings"), self)
117+
settings_action.triggered.connect(self.__open_settings_dialog)
118+
119+
# About action
120+
about_action = QAction(self.tr("About"), self)
121+
about_action.triggered.connect(self.__show_about_dialog)
122+
123+
# Add actions to menubar
124+
self.menubar.addAction(settings_action)
125+
self.menubar.addAction(about_action)
126+
108127
logger.info("Ready.")
109128

110129
def __initGuiModules(self):
@@ -299,7 +318,7 @@ def __moduleVersionChanged(self, index):
299318
QtUtils.resetForegroundColor(self.module_information_label)
300319
logger.info(loading_text)
301320

302-
self.module_informationDemodatal_label.setText("-")
321+
self.module_informationDatamodel_label.setText("-")
303322
self.module_informationProject_label.setText("-")
304323
self.module_informationPlugin_label.setText("-")
305324

@@ -379,9 +398,9 @@ def __packagePrepareTaskFinished(self):
379398

380399
asset_datamodel = self.module_version_comboBox.currentData().asset_datamodel
381400
if asset_datamodel:
382-
self.module_informationDemodata_label.setText(asset_datamodel.package_dir)
401+
self.module_informationDatamodel_label.setText(asset_datamodel.package_dir)
383402
else:
384-
self.module_informationDemodata_label.setText("No asset available")
403+
self.module_informationDatamodel_label.setText("No asset available")
385404

386405
asset_project = self.module_version_comboBox.currentData().asset_project
387406
if asset_project:
@@ -414,7 +433,7 @@ def __packagePrepareGetPUMConfig(self):
414433
return
415434

416435
try:
417-
self.__pum_config = PumConfig.from_yaml(pumConfigFilename)
436+
self.__pum_config = PumConfig.from_yaml(pumConfigFilename, install_dependencies=True)
418437
except Exception as exception:
419438
CriticalMessageBox(
420439
self.tr("Error"),
@@ -802,3 +821,11 @@ def __logsOpenFolderClicked(self):
802821

803822
def __logsClearClicked(self):
804823
self.logs_treeWidget.clear()
824+
825+
def __open_settings_dialog(self):
826+
dlg = SettingsDialog(self)
827+
dlg.exec_()
828+
829+
def __show_about_dialog(self):
830+
dialog = AboutDialog(self)
831+
dialog.exec_()

oqtopus/gui/settings_dialog.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from qgis.PyQt.QtWidgets import QDialog
2+
3+
from ..utils.plugin_utils import PluginUtils
4+
5+
DIALOG_UI = PluginUtils.get_ui_class("settings_dialog.ui")
6+
7+
8+
class SettingsDialog(QDialog, DIALOG_UI):
9+
def __init__(self, parent=None):
10+
QDialog.__init__(self, parent)
11+
self.setupUi(self)
12+
13+
self.githubToken_lineEdit.setText(PluginUtils.get_github_token())
14+
15+
def accept(self):
16+
PluginUtils.set_github_token(self.githubToken_lineEdit.text())
17+
super().accept()

oqtopus/ui/about_dialog.ui

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,14 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>627</width>
9+
<width>634</width>
1010
<height>426</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Dialog</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="6" column="0">
18-
<spacer name="verticalSpacer">
19-
<property name="orientation">
20-
<enum>Qt::Vertical</enum>
21-
</property>
22-
<property name="sizeHint" stdset="0">
23-
<size>
24-
<width>20</width>
25-
<height>40</height>
26-
</size>
27-
</property>
28-
</spacer>
29-
</item>
3017
<item row="1" column="0">
3118
<layout class="QVBoxLayout" name="verticalLayout">
3219
<item>
@@ -73,6 +60,29 @@
7360
</item>
7461
</layout>
7562
</item>
63+
<item row="6" column="0">
64+
<spacer name="verticalSpacer">
65+
<property name="orientation">
66+
<enum>Qt::Vertical</enum>
67+
</property>
68+
<property name="sizeHint" stdset="0">
69+
<size>
70+
<width>20</width>
71+
<height>40</height>
72+
</size>
73+
</property>
74+
</spacer>
75+
</item>
76+
<item row="4" column="0">
77+
<widget class="QLabel" name="label">
78+
<property name="text">
79+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;For any feedback, bugs or comments, please visit &lt;a href=&quot;https://github.com/Oqtopus/Oqtopus/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;https://github.com/Oqtopus/Oqtopus/issues&lt;/span&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;For the changelog: &lt;a href=&quot;https://github.com/Oqtopus/Oqtopus/releases&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;https://github.com/Oqtopus/Oqtopus/releases&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
80+
</property>
81+
<property name="openExternalLinks">
82+
<bool>true</bool>
83+
</property>
84+
</widget>
85+
</item>
7686
<item row="5" column="0">
7787
<layout class="QGridLayout" name="gridLayout_2">
7888
<item row="1" column="1">
@@ -176,16 +186,6 @@
176186
</item>
177187
</layout>
178188
</item>
179-
<item row="4" column="0">
180-
<widget class="QLabel" name="label">
181-
<property name="text">
182-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;For any feedback, bugs or comments, please visit &lt;a href=&quot;https://github.com/Oqtopus/Oqtopus/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;https://github.com/Oqtopus/Oqtopus/issues&lt;/span&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;For the changelog: &lt;a href=&quot;https://github.com/Oqtopus/Oqtopus/releases&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;https://github.com/Oqtopus/Oqtopus/releases&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
183-
</property>
184-
<property name="openExternalLinks">
185-
<bool>true</bool>
186-
</property>
187-
</widget>
188-
</item>
189189
<item row="0" column="1" rowspan="5">
190190
<widget class="QLabel" name="iconLabel">
191191
<property name="text">

oqtopus/ui/main_dialog.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,12 @@
346346
<item row="6" column="0">
347347
<widget class="QLabel" name="label_10">
348348
<property name="text">
349-
<string>Demodata:</string>
349+
<string>Datamodel</string>
350350
</property>
351351
</widget>
352352
</item>
353353
<item row="6" column="1" colspan="2">
354-
<widget class="QLabel" name="module_informationDemodatal_label">
354+
<widget class="QLabel" name="module_informationDatamodel_label">
355355
<property name="text">
356356
<string>-</string>
357357
</property>

oqtopus/ui/settings_dialog.ui

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>439</width>
10+
<height>161</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Oqtopus settings</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="1">
18+
<widget class="QLineEdit" name="githubToken_lineEdit"/>
19+
</item>
20+
<item row="2" column="0" colspan="2">
21+
<widget class="QDialogButtonBox" name="buttonBox">
22+
<property name="orientation">
23+
<enum>Qt::Horizontal</enum>
24+
</property>
25+
<property name="standardButtons">
26+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
27+
</property>
28+
</widget>
29+
</item>
30+
<item row="0" column="0">
31+
<widget class="QLabel" name="label">
32+
<property name="text">
33+
<string>Github token</string>
34+
</property>
35+
</widget>
36+
</item>
37+
<item row="1" column="1">
38+
<spacer name="verticalSpacer">
39+
<property name="orientation">
40+
<enum>Qt::Vertical</enum>
41+
</property>
42+
<property name="sizeHint" stdset="0">
43+
<size>
44+
<width>20</width>
45+
<height>40</height>
46+
</size>
47+
</property>
48+
</spacer>
49+
</item>
50+
</layout>
51+
</widget>
52+
<resources/>
53+
<connections>
54+
<connection>
55+
<sender>buttonBox</sender>
56+
<signal>accepted()</signal>
57+
<receiver>Dialog</receiver>
58+
<slot>accept()</slot>
59+
<hints>
60+
<hint type="sourcelabel">
61+
<x>248</x>
62+
<y>254</y>
63+
</hint>
64+
<hint type="destinationlabel">
65+
<x>157</x>
66+
<y>274</y>
67+
</hint>
68+
</hints>
69+
</connection>
70+
<connection>
71+
<sender>buttonBox</sender>
72+
<signal>rejected()</signal>
73+
<receiver>Dialog</receiver>
74+
<slot>reject()</slot>
75+
<hints>
76+
<hint type="sourcelabel">
77+
<x>316</x>
78+
<y>260</y>
79+
</hint>
80+
<hint type="destinationlabel">
81+
<x>286</x>
82+
<y>274</y>
83+
</hint>
84+
</hints>
85+
</connection>
86+
</connections>
87+
</ui>

oqtopus/utils/plugin_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ def open_log_file():
128128
else:
129129
logger.error(f"Log file '{log_file_path}' does not exist.")
130130

131+
@staticmethod
132+
def get_github_token():
133+
settings = QSettings()
134+
return settings.value("oqtopus/github_token", type=str)
135+
136+
@staticmethod
137+
def set_github_token(token: str):
138+
settings = QSettings()
139+
settings.setValue("oqtopus/github_token", token)
140+
141+
@staticmethod
142+
def get_github_headers():
143+
token = PluginUtils.get_github_token()
144+
headers = {}
145+
if token:
146+
headers["Authorization"] = f"token {token}"
147+
return headers
148+
131149

132150
class LoggingBridge(logging.Handler, QObject):
133151

oqtopus/utils/qt_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ def __init__(self, title: str, description: str, exception: Exception = None, pa
8585

8686
def showEvent(self, event):
8787
super().showEvent(event)
88-
self.resize(700, 400) # Set your preferred initial size here
88+
self.resize(700, 1000) # Set your preferred initial size here

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pgserviceparser >= 2.3.0
2-
git+https://github.com/opengisch/pum.git
2+
pum >= 1.1.1

0 commit comments

Comments
 (0)