-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAGOLConfigHelper.py
131 lines (115 loc) · 3.54 KB
/
AGOLConfigHelper.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
__version__ = "1.4"
'''
__author__ = "Simon Geigenberger, Lukas Bug"
__copyright__ = "Copyright 2018, Esri Deutschland GmbH"
__license__ = "Apache-2.0"
__version__ = "1.4"
__email__ = "simon@geigenberger.info, lukas.bug@aol.de"
'''
import json
import sys
def readConfig():
dictAGOLConfig = {}
#Try to import the ArcGIS API for Python
try:
from arcgis.gis import GIS
except:
print("ArcGIS API for Python cannot be imported")
sys.exit()
#Check version of ArcGIS API for Python <= 1.5.0
import arcgis
v = int(arcgis.__version__.replace(".", ""))
if v > 150:
print("ArcGIS API for Python is newer than the version required by this module, please install ArcGIS API for Python 1.5.0 or a previous version.")
sys.exit()
#Try to open the config file.
try:
json_data = open("agolconfig.json").read()
except:
print("JSON file does not exist.")
sys.exit()
#Try to load the config file as JSON.
try:
data = json.loads(json_data)
except:
print("JSON file cannot be read.")
sys.exit()
#Check if a portal is selected
try:
portalInit = data["portalInit"]
dictAGOLConfig["portal"] = portalInit
except:
print("No Portal chosen.")
sys.exit()
#Check if a user is selected
try:
userInit = data["userInit"]
dictAGOLConfig["user"] = userInit
except:
print("No user chosen.")
sys.exit()
#check if a password is selected
try:
passwordInit = data["passwordInit"]
dictAGOLConfig["password"] = passwordInit
except:
print("No passord box chosen.")
sys.exit()
#Try to connect to the selected portal with the login information.
try:
GIS(portalInit, userInit, passwordInit)
except:
print("Cannot connect to the portal.")
sys.exit()
#Checks if a titel is selected
try:
title = data["title"]
dictAGOLConfig["title"] = title
except:
print("No title chosen.")
sys.exit()
#Check if tags are selected. Remove tags if the string contains only spaces.
try:
tags = data["tags"]
if len(tags) == 0:
print("No tags chosen - 1.")
sys.exit()
should_restart = True
while should_restart:
should_restart = False
for tag in tags:
tagTest = tag.lstrip()
if len(tagTest) == 0:
tags.remove(tag)
should_restart = True
if len(tags) == 0:
print("No tags chosen - 2.")
sys.exit()
else:
dictAGOLConfig["tags"] = tags
except:
print("No tags chosen - 3.")
sys.exit()
#Check if a description is selected.
try:
description = data["description"]
dictAGOLConfig["description"] = description
except:
print("No description chosen.")
sys.exit()
#Checks if a copyrightText is selected
try:
copyrightText = data["copyrightText"]
dictAGOLConfig["copyrightText"] = copyrightText
except:
print("No copyrightText chosen.")
sys.exit()
#Checks if a maxRecordCount is selected
try:
maxRecordCount = data["maxRecordCount"]
dictAGOLConfig["maxRecordCount"] = maxRecordCount
except:
print("No maxRecordCount chosen.")
sys.exit()
dictAGOLConfig["overwriteService"] = 0
return dictAGOLConfig