|
16 | 16 | * *
|
17 | 17 | ***************************************************************************
|
18 | 18 | """
|
19 |
| -from builtins import zip |
20 | 19 |
|
21 | 20 | __author__ = 'Martin Dobias'
|
22 | 21 | __date__ = 'January 2007'
|
23 | 22 | __copyright__ = '(C) 2007, Martin Dobias'
|
24 | 23 | # This will get replaced with a git SHA1 when you do a git archive
|
25 | 24 | __revision__ = '$Format:%H$'
|
26 | 25 |
|
| 26 | +from builtins import zip |
| 27 | +import os |
| 28 | + |
| 29 | +def setupenv(): |
| 30 | + """ |
| 31 | + Set the environment for Windows based on the .vars files from the |
| 32 | + OSGeo4W package format. |
| 33 | + """ |
| 34 | + # If the prefix path is already set the we don't do any more path setup. |
| 35 | + if os.getenv('QGIS_PREFIX_PATH'): |
| 36 | + return |
| 37 | + |
| 38 | + # Setup the paths based on the .vars file. |
| 39 | + from pathlib import PurePath |
| 40 | + |
| 41 | + path_split = PurePath(os.path.dirname(os.path.realpath(__file__))).parts |
| 42 | + |
| 43 | + try: |
| 44 | + appname = os.environ['QGIS_ENVNAME'] |
| 45 | + except KeyError: |
| 46 | + appname = path_split[-3] |
| 47 | + |
| 48 | + envfile= list(path_split[:-4]) |
| 49 | + envfile.append("bin") |
| 50 | + envfile.append("{0}-bin.env".format(appname)) |
| 51 | + envfile = os.path.join(*envfile) |
| 52 | + with open(envfile) as f: |
| 53 | + for line in f: |
| 54 | + linedata = line.split("=") |
| 55 | + name = linedata[0] |
| 56 | + data = linedata[1] |
| 57 | + os.environ[name] = data |
| 58 | + |
| 59 | + |
| 60 | +if os.name == 'nt': |
| 61 | + # On windows we need to setup the paths before we can import |
| 62 | + # any of the QGIS modules or else it will error. |
| 63 | + setupenv() |
| 64 | + |
| 65 | + |
27 | 66 | from qgis.PyQt import QtCore
|
28 | 67 | from qgis.core import QgsFeature, QgsGeometry
|
29 | 68 |
|
|
0 commit comments