Skip to content

Commit bf72a8d

Browse files
committed
convert to toggle_winfile function, use when reading master file
1 parent 8774a01 commit bf72a8d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

larch/xrmmap/gsexrm_utils.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212

1313
from ..xrd import integrate_xrd_row
1414

15+
def toggle_winfile(folder, fname='_tmp.lock', sleep_time=0.05):
16+
"""
17+
toggle a small lock file in a folder on Windows to force an
18+
update of the windows directory. For network-shared folders,
19+
as when collecting data, this can be useful to force file lists
20+
to be up to date.
21+
"""
22+
if os.name == 'nt':
23+
tmpfile = Path(folder, fname)
24+
if tmpfile.exists():
25+
tmpfile.unlink()
26+
else:
27+
with open(tmpfile, 'w') as fh:
28+
fh.write('_tmp\n')
29+
time.sleep(sleep_time)
30+
1531
def fix_xrd1d_filename(xrd_file):
1632
"""check for 1D XRD file from Eiger or other detector --
1733
avoids having to read hdf5 file at all
@@ -194,6 +210,7 @@ def __init__(self, yvalue, xrffile, xrdfile, xpsfile, sisfile, folder,
194210
self.xrdq_wdg = None
195211
self.xrd1d_wdg = None
196212
if masterfile is not None:
213+
toggle_winfile(folder, fname='_tmp.lock')
197214
header, rows = readMasterFile(masterfile)
198215
for row in header:
199216
if row.startswith('#XRF.filetype'): xrftype = row.split()[-1]
@@ -227,14 +244,7 @@ def __init__(self, yvalue, xrffile, xrdfile, xpsfile, sisfile, folder,
227244
# not synced with the files written to the mount by the collection procees.
228245
# toggling a small file in this folder will force a refresh of the
229246
# directory listing, which may help
230-
if os.name == 'nt':
231-
tmpfile = Path(folder, '_wintmp_.txt')
232-
if tmpfile.exists():
233-
tmpfile.unlink()
234-
else:
235-
with open(tmpfile, 'w') as fh:
236-
fh.write('_tmp\n')
237-
time.sleep(0.1)
247+
toggle_winfile(folder)
238248

239249
sis_ok, xps_ok = False, False
240250
gdata, sdata = [], []

0 commit comments

Comments
 (0)