Browse Source

#75 #59 change error message about OGR and the OSM driver

tags/1.4.4
Etienne Trimaille 3 years ago
parent
commit
7762413572
4 changed files with 33 additions and 11 deletions
  1. 8
    3
      controller/process.py
  2. 11
    2
      core/exceptions.py
  3. 6
    3
      core/utilities/utilities_qgis.py
  4. 8
    3
      ui/osm_file_dialog.py

+ 8
- 3
controller/process.py View File

@@ -29,11 +29,13 @@ from qgis.core import \
29 29
 
30 30
 from QuickOSM.core.query_factory import QueryFactory
31 31
 from QuickOSM.core.utilities.tools import tr
32
-from QuickOSM.core.exceptions import FileOutPutException, OsmDriver
32
+from QuickOSM.core.exceptions import \
33
+    FileOutPutException, OsmDriverNotFound, GDALVersion
33 34
 from QuickOSM.core.api.connexion_oapi import ConnexionOAPI
34 35
 from QuickOSM.core.parser.osm_parser import OsmParser
35 36
 from QuickOSM.core.utilities.operating_system import get_default_encoding
36
-from QuickOSM.core.utilities.utilities_qgis import is_osm_driver_enabled
37
+from QuickOSM.core.utilities.utilities_qgis import \
38
+    is_osm_driver_enabled, is_ogr_version_ok
37 39
 from QuickOSM.core.utilities.tools import get_setting
38 40
 from QuickOSM.core.query_parser import prepare_query
39 41
 
@@ -223,8 +225,11 @@ def process_query(
223 225
     """execute a query and send the result file to open_file."""
224 226
 
225 227
     # Check OGR
228
+    if not is_ogr_version_ok():
229
+        raise GDALVersion
230
+
226 231
     if not is_osm_driver_enabled():
227
-        raise OsmDriver
232
+        raise OsmDriverNotFound
228 233
 
229 234
     # Get output's format
230 235
     output_format = get_setting('outputFormat')

+ 11
- 2
core/exceptions.py View File

@@ -90,12 +90,21 @@ Ogr2Ogr
90 90
 '''
91 91
 
92 92
 
93
-class OsmDriver(QuickOsmException):
93
+class OsmDriverNotFound(QuickOsmException):
94 94
     def __init__(self, msg=None):
95 95
         if not msg:
96 96
             msg = tr(
97 97
                 'Exception', u"The OSM's driver is not installed. "
98
-                             u"You must have GDAL/OGR >= 1.10.")
98
+                             u"Please install the OSM driver for GDAL "
99
+                             u": http://www.gdal.org/drv_osm.html")
100
+        QuickOsmException.__init__(self, msg)
101
+
102
+
103
+class GDALVersion(QuickOsmException):
104
+    def __init__(self, msg=None):
105
+        if not msg:
106
+            msg = tr(
107
+                'Exception', u"You must upgrade GDAL/OGR >= 1.10.0.")
99 108
         QuickOsmException.__init__(self, msg)
100 109
 
101 110
 

+ 6
- 3
core/utilities/utilities_qgis.py View File

@@ -24,6 +24,7 @@
24 24
 from osgeo import gdal, ogr
25 25
 from qgis.gui import QgsMessageBar
26 26
 from qgis.utils import iface
27
+from QuickOSM.core.exceptions import GDALVersion, OsmDriverNotFound
27 28
 
28 29
 
29 30
 def display_message_bar(
@@ -42,11 +43,13 @@ def get_ogr_version():
42 43
     return int(gdal.VersionInfo('VERSION_NUM'))
43 44
 
44 45
 
45
-def is_osm_driver_enabled():
46
-    if get_ogr_version < 1100000:
46
+def is_ogr_version_ok():
47
+    if get_ogr_version() < 1100000:
47 48
         return False
49
+    return True
50
+
48 51
 
52
+def is_osm_driver_enabled():
49 53
     if not ogr.GetDriverByName('OSM'):
50 54
         return False
51
-
52 55
     return True

+ 8
- 3
ui/osm_file_dialog.py View File

@@ -33,8 +33,10 @@ from QuickOSM.core.exceptions import (
33 33
     OutPutGeomTypesException,
34 34
     FileDoesntExistException,
35 35
     DirectoryOutPutException,
36
-    OsmDriver)
37
-from QuickOSM.core.utilities.utilities_qgis import is_osm_driver_enabled
36
+    GDALVersion,
37
+    OsmDriverNotFound)
38
+from QuickOSM.core.utilities.utilities_qgis import \
39
+    is_osm_driver_enabled, is_ogr_version_ok
38 40
 from QuickOSM.core.parser.osm_parser import OsmParser
39 41
 from QuickOSM.controller.process import open_file
40 42
 from QuickOSMWidget import QuickOSMWidget
@@ -151,8 +153,11 @@ class OsmFileWidget(QuickOSMWidget, Ui_ui_osm_file):
151 153
                 raise DirectoryOutPutException
152 154
 
153 155
             # Check OGR
156
+            if not is_ogr_version_ok():
157
+                raise GDALVersion
158
+
154 159
             if not is_osm_driver_enabled():
155
-                raise OsmDriver
160
+                raise OsmDriverNotFound
156 161
 
157 162
             if load_only:
158 163
                 osm_parser = OsmParser(

Loading…
Cancel
Save