Skip to content

Commit 45b89a7

Browse files
committed
editSessionActive now looks for ed.lock files
1 parent aebf786 commit 45b89a7

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

Scripts/GeMS_utilityFunctions.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# utility functions for scripts that work with GeMS geodatabase schema
22
## 28 December 2020: added function editSessionActive(gdb) - RH
33
## 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
613
import requests
714
editPrefixes = ('xxx','edit_','errors_','ed_')
815
debug = False
@@ -186,36 +193,12 @@ def isPlanar(orientationType):
186193
isPlanarType = True
187194
return isPlanarType
188195

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
198199
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+
219202
return edit_session
220203

221204
def checkVersion(vString, rawurl, toolbox):

0 commit comments

Comments
 (0)