-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergyadvisor_publish_hosted_layer.py
228 lines (157 loc) · 8.35 KB
/
energyadvisor_publish_hosted_layer.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import arcgis
from arcgis.gis import GIS
import os
import logging
import time
from arcgis.features import FeatureLayerCollection
starttime=time.time()
fileLog = str(os.path.abspath(__file__)).replace(".py",".log")
logging.basicConfig(filename=fileLog, filemode='w', format='%(asctime)s :: %(levelname)s :: %(threadName)s :: %(message)s', level=logging.INFO, datefmt='%m/%d/%Y %I:%M:%S %p')
gis = GIS("https://arcgis.com", "username", "password")
#FOLDER PATHS BASED ON PORTAL GROUPS
AMI_Path = r'C:\Temp\AMI'
SSN_SSN_RO_Path = r'C:\Temp\SSN'
AICC_DM_Path = r'C:\Temp\AICCDM'
DM_Path = r'C:\Temp\DM'
IEN_ProjMash_Path =r'C:\Temp\IENPM'
serviceProp = {}
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "AMI"
itemId = []
try:
def AMI():
for dirpath, subdirs, files in os.walk(AMI_Path) :
for aFile in files:
fgdbPath = os.path.join(AMI_Path, aFile)
fgdbPortalName = os.path.splitext(aFile)[0]
logging.info("Starting Copy and Publish for " + fgdbPortalName)
print("Starting Copy and Publish for " + fgdbPortalName)
#TAGS FOR EACH DIRECTORY
serviceProp = {}
serviceProp['title'] = fgdbPortalName
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "AMI"
pubProps = {}
pubProps["hasStaticData"] = 'false'
pubProps["name"] =fgdbPortalName
pubProps["maxRecordCount"] = 2000
pubProps["layerInfo"] = {"capabilities":"Query"}
addFGDB = gis.content.add(item_properties=serviceProp, data = fgdbPath)
pubFGDB = addFGDB.publish(publish_parameters = pubProps, file_type = 'filegeodatabase', overwrite=True)
pubFGDB.share(org=False, groups='AMI')
print("Finished Copy and Publish for AMI " + fgdbPortalName)
logging.info("Copy and Publish Complete for AMI " + fgdbPortalName)
def SSN_SSN_RO():
for dirpath, subdirs, files in os.walk(SSN_SSN_RO_Path) :
for aFile in files:
fgdbPath = os.path.join(SSN_SSN_RO_Path, aFile)
fgdbPortalName = os.path.splitext(aFile)[0]
logging.info("Starting Copy and Publish for " + fgdbPortalName)
print("Starting Copy and Publish for " + fgdbPortalName)
#TAGS FOR EACH DIRECTORY
serviceProp = {}
serviceProp['title'] = fgdbPortalName
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "SSN"
pubProps = {}
pubProps["hasStaticData"] = 'false'
pubProps["name"] =fgdbPortalName
pubProps["maxRecordCount"] = 2000
pubProps["layerInfo"] = {"capabilities":"Query"}
addFGDB = gis.content.add(item_properties=serviceProp, data = fgdbPath)
pubFGDB = addFGDB.publish(publish_parameters = pubProps, file_type = 'filegeodatabase', overwrite=True)
#dual group
pubFGDB.share(org=False, groups=['SSN','SSN_RO'])
print("Finished Copy and Publish for SSN " + fgdbPortalName)
logging.info("Copy and Publish Complete for SSN " + fgdbPortalName)
def AICC_DM():
for dirpath, subdirs, files in os.walk(AICC_DM_Path) :
for aFile in files:
fgdbPath = os.path.join(AICC_DM_Path, aFile)
fgdbPortalName = os.path.splitext(aFile)[0]
logging.info("Starting Copy and Publish for " + fgdbPortalName)
print("Starting Copy and Publish for " + fgdbPortalName)
#TAGS FOR EACH DIRECTORY
serviceProp = {}
serviceProp['title'] = fgdbPortalName
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "SSN"
pubProps = {}
pubProps["hasStaticData"] = 'false'
pubProps["name"] =fgdbPortalName
pubProps["maxRecordCount"] = 2000
pubProps["layerInfo"] = {"capabilities":"Query"}
addFGDB = gis.content.add(item_properties=serviceProp, data = fgdbPath)
pubFGDB = addFGDB.publish(publish_parameters = pubProps, file_type = 'filegeodatabase', overwrite=True)
#dual group
pubFGDB.share(org=False, groups=['AICC','DM Group'])
print("Finished Copy and Publish for SSN " + fgdbPortalName)
logging.info("Copy and Publish Complete for SSN " + fgdbPortalName)
def DM():
for dirpath, subdirs, files in os.walk(DM_Path) :
for aFile in files:
fgdbPath = os.path.join(DM_Path, aFile)
fgdbPortalName = os.path.splitext(aFile)[0]
logging.info("Starting Copy and Publish for " + fgdbPortalName)
print("Starting Copy and Publish for " + fgdbPortalName)
#TAGS FOR EACH DIRECTORY
serviceProp = {}
serviceProp['title'] = fgdbPortalName
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "TEST"
pubProps = {}
pubProps["hasStaticData"] = 'false'
pubProps["name"] =fgdbPortalName
pubProps["maxRecordCount"] = 2000
pubProps["layerInfo"] = {"capabilities":"Query"}
addFGDB = gis.content.add(item_properties=serviceProp, data = fgdbPath)
pubFGDB = addFGDB.publish(publish_parameters = pubProps, file_type = 'filegeodatabase', overwrite=True)
#dual group
pubFGDB.share(org=False, groups=['DM Group'])
print("Finished Copy and Publish for DM " + fgdbPortalName)
logging.info("Copy and Publish Complete for SSN " + fgdbPortalName)
def IENPM():
for dirpath, subdirs, files in os.walk(IEN_ProjMash_Path) :
for aFile in files:
fgdbPath = os.path.join(IEN_ProjMash_Path, aFile)
fgdbPortalName = os.path.splitext(aFile)[0]
logging.info("Starting Copy and Publish for " + fgdbPortalName)
print("Starting Copy and Publish for " + fgdbPortalName)
#TAGS FOR EACH DIRECTORY
serviceProp = {}
serviceProp['title'] = fgdbPortalName
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "IEN"
pubProps = {}
pubProps["hasStaticData"] = 'false'
pubProps["name"] =fgdbPortalName
pubProps["maxRecordCount"] = 2000
pubProps["layerInfo"] = {"capabilities":"Query"}
addFGDB = gis.content.add(item_properties=serviceProp, data = fgdbPath)
pubFGDB = addFGDB.publish(publish_parameters = pubProps, file_type = 'filegeodatabase', overwrite=True)
#dual group
pubFGDB.share(org=False, groups=['IEN Dev','Project Mashup'])
print("Starting Copy and Publish for IEN AND PROJECT MASHUP " + fgdbPortalName)
logging.info("Copy and Publish Complete for SSN " + fgdbPortalName)
def main():
logging.info("START")
AMI()
SSN_SSN_RO()
AICC_DM()
IENPM()
DM()
logging.info("Copy and Publish Complete for all items")
print("Script has completed publishing the items")
except:
logging.info("There is an error publishing " + fgdbPortalName)
e = str(sys.exc_info()[1])
logging.info(e)
print (e)
if __name__ == '__main__':
main()