forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait_for_file.py
More file actions
35 lines (31 loc) · 842 Bytes
/
wait_for_file.py
File metadata and controls
35 lines (31 loc) · 842 Bytes
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
import os.path
import sys
import time
try:
_, filename = sys.argv
except ValueError:
_, filename, outfile = sys.argv
sys.stdout = open(outfile, 'w')
print('waiting for file {!r}'.format(filename))
# We use sys.stdout.write() instead of print() because Python 2...
if not os.path.exists(filename):
time.sleep(0.1)
sys.stdout.write('.')
sys.stdout.flush()
i = 1
while not os.path.exists(filename):
time.sleep(0.1)
if i % 10 == 0:
sys.stdout.write(' ')
if i % 600 == 0:
if i == 600:
sys.stdout.write('\n = 1 minute =\n')
else:
sys.stdout.write('\n = {} minutes =\n'.format(i // 600))
elif i % 100 == 0:
sys.stdout.write('\n')
sys.stdout.write('.')
sys.stdout.flush()
i += 1
print('\nfound file {!r}'.format(filename))
print('done!')