|
1 | 1 | # utility functions for scripts that work with GeMS geodatabase schema |
2 | 2 | ## 28 December 2020: added function editSessionActive(gdb) - RH |
3 | 3 | ## 7 March 2021: Extended list of keywords for isPlanar() |
4 | | - |
5 | | -import arcpy, os.path, time |
| 4 | +# 24 August 2021: editSessionActive now looks for ed.lock files in gdb folder. Was running into |
| 5 | +# problems with gdb's that did not have GeoMaterialDict. Though a violation of the schema, discovering |
| 6 | +# that absence is not the point of editSessionActive. Looking for ed.lock files is very easy. This won't |
| 7 | +# be a good method if trying to validate a format other than gdb, but we'll kick the can until then. |
| 8 | + |
| 9 | +import arcpy |
| 10 | +import os.path |
| 11 | +import time |
| 12 | +import glob |
6 | 13 | import requests |
7 | 14 | editPrefixes = ('xxx','edit_','errors_','ed_') |
8 | 15 | debug = False |
@@ -186,36 +193,12 @@ def isPlanar(orientationType): |
186 | 193 | isPlanarType = True |
187 | 194 | return isPlanarType |
188 | 195 |
|
189 | | -def editSessionActive(gdb): |
190 | | - # returns True if edit session active, else False |
191 | | - # test for |
192 | | - if arcpy.Exists(gdb+'/GeoMaterialDict'): |
193 | | - tbl = gdb+'/GeoMaterialDict' |
194 | | - fld = 'GeoMaterial' |
195 | | - elif arcpy.Exists(gdb+'/GeologicMap/MapUnitPolys') and numberOfRows(gdb+'/GeologicMap/MapUnitPolys') > 2: |
196 | | - tbl = gdb+'/GeologicMap/MapUnitPolys' |
197 | | - fld = 'MapUnit' |
| 196 | +def editSessionActive(gdb_path): |
| 197 | + if glob.glob(os.path.join(gdb_path, '*.ed.lock')): |
| 198 | + edit_session = True |
198 | 199 | else: |
199 | | - # doesn't appear to be a GeMS database |
200 | | - # default to no edit session active and bail |
201 | | - return False |
202 | | - ## Following code modified from routine posted by Curtis Price at |
203 | | - ## https://gis.stackexchange.com/questions/61708/checking-via-arcpy-if-arcmap-is-in-edit-session |
204 | | - edit_session = True |
205 | | - try: |
206 | | - # attempt to open two cursors on the input |
207 | | - # this generates a RuntimeError if no edit session is active |
208 | | - with arcpy.da.UpdateCursor(tbl, fld) as rows: |
209 | | - row = next(rows) |
210 | | - with arcpy.da.UpdateCursor(tbl, fld) as rows2: |
211 | | - row2 = next(rows2) |
212 | | - except RuntimeError as e: |
213 | | - if e.message == "workspace already in transaction mode": |
214 | | - # this error means that no edit session is active |
215 | | - edit_session = False |
216 | | - else: |
217 | | - # we have some other error going on, report it |
218 | | - raise |
| 200 | + edit_session = False |
| 201 | + |
219 | 202 | return edit_session |
220 | 203 |
|
221 | 204 | def checkVersion(vString, rawurl, toolbox): |
|
0 commit comments