|
12 | 12 |
|
13 | 13 | from ..xrd import integrate_xrd_row |
14 | 14 |
|
| 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 | + |
15 | 31 | def fix_xrd1d_filename(xrd_file): |
16 | 32 | """check for 1D XRD file from Eiger or other detector -- |
17 | 33 | avoids having to read hdf5 file at all |
@@ -194,6 +210,7 @@ def __init__(self, yvalue, xrffile, xrdfile, xpsfile, sisfile, folder, |
194 | 210 | self.xrdq_wdg = None |
195 | 211 | self.xrd1d_wdg = None |
196 | 212 | if masterfile is not None: |
| 213 | + toggle_winfile(folder, fname='_tmp.lock') |
197 | 214 | header, rows = readMasterFile(masterfile) |
198 | 215 | for row in header: |
199 | 216 | if row.startswith('#XRF.filetype'): xrftype = row.split()[-1] |
@@ -227,14 +244,7 @@ def __init__(self, yvalue, xrffile, xrdfile, xpsfile, sisfile, folder, |
227 | 244 | # not synced with the files written to the mount by the collection procees. |
228 | 245 | # toggling a small file in this folder will force a refresh of the |
229 | 246 | # 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) |
238 | 248 |
|
239 | 249 | sis_ok, xps_ok = False, False |
240 | 250 | gdata, sdata = [], [] |
|
0 commit comments