-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqgis-check-platform
More file actions
executable file
·109 lines (78 loc) · 3.21 KB
/
qgis-check-platform
File metadata and controls
executable file
·109 lines (78 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
import os
import sys
import logging
from time import sleep
qgis_application = None
def start_qgis_application(enable_gui=False, enable_processing=False, verbose=False, cleanup=True):
global qgis_application
from qgis.core import QgsApplication, QgsMessageLog, QgsProviderRegistry
# In python3 we need to convert to a bytes object (or should
# QgsApplication accept a QString instead of const char* ?)
try:
argvb = list(map(os.fsencode, sys.argv))
except AttributeError:
argvb = sys.argv
qgis_application = QgsApplication(argvb, enable_gui )
qgis_application.setPrefixPath('/usr', True)
qgis_application.initQgis()
if cleanup:
import atexit
print("Installing cleanup hook")
@atexit.register
def exitQgis():
if qgis_application:
qgis_application.exitQgis()
if verbose:
print(qgis_application.showSettings())
# Add a hook to qgis message log
def writelogmessage(message, tag, level):
print('Qgis: {}({}): {}'.format( tag, level, message ), file=sys.stderr)
QgsApplication.instance().messageLog().messageReceived.connect( writelogmessage )
print("QGIS initialized......")
if enable_processing:
sys.path.append("/usr/share/qgis/python/plugins/")
from processing.core.Processing import Processing
from qgis.analysis import QgsNativeAlgorithms
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
Processing.initialize()
print("QGis processing initialized")
def stop_qgis_application():
""" Cleans up and exits QGIS
"""
global qgis_application
qgis_application.exitQgis()
del qgis_application
def print_processing_algs_tree():
""" Print all processing providers/modules
"""
for provider in qgis_application.processingRegistry().providers():
if provider.isActive:
print('* |--- ', provider.name() )
else:
print(' |--- ', provider.name() )
for alg in provider.algorithms():
print(' |---', alg.name())
def print_processing_algs_list():
""" Print all processing providers/modules
"""
for provider in qgis_application.processingRegistry().providers():
for alg in provider.algorithms():
print('%s/%s' % (provider.name(),alg.name()))
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Run headless qgis app and exit')
parser.add_argument('--verbose', action='store_true', default=False )
parser.add_argument('--disable-exit-hook', action='store_true', default=False)
parser.add_argument('--list-processing-algs', choices=['tree','list'], default='tree')
args = parser.parse_args()
# We MUST set the QT_QPA_PLATFORM to prevent
# Qt trying to connect to display
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
start_qgis_application(verbose = args.verbose,
enable_processing = True,
cleanup = not args.disable_exit_hook)
if args.list_processing_algs == 'tree':
print_processing_algs_tree()
else:
print_processing_algs_list()