sapling/tests/waitforfile.py
Saurabh Singh 5a62bbf298 fastmanifest: move fastmanifest tests from fb-hgext/tests to tests/
Summary: Now that D6685044 moved fastmanifest, we can also move the tests. Note
that test-fb-hgext-fastmanifest.t was moved seprately by Durham.

Test Plan: Ran all the tests.

Reviewers: quark, #mercurial, #sourcecontrol

Reviewed By: quark

Subscribers: durham, quark

Differential Revision: https://phabricator.intern.facebook.com/D6686584

Signature: 6686584:1515531785:3a9fa022f443faed6f3110eeef22d8ea72fcee3f
2018-01-09 14:21:39 -08:00

38 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python
from optparse import OptionParser
import os
import sys
import time
if __name__ == '__main__':
parser = OptionParser()
parser.add_option('--created', dest='created',
type='string', default=[],
action='append',
help='wait for <FILE> to be created', metavar='FILE')
parser.add_option('--deleted', dest='deleted',
type='string', default=[],
action='append',
help='wait for <FILE> to be deleted', metavar='FILE')
parser.add_option('--sleep-interval-ms', dest='sleep_interval_ms',
type='int', default=100,
help='time in MS to sleep between checks')
parser.add_option('--max-time', dest='max_time',
type='int',
help='maximum time in seconds to wait for all the files to '
'reach the desired state')
(options, args) = parser.parse_args()
start = time.time()
while options.max_time is None or time.time() < start + options.max_time:
if (not all(os.access(f, os.F_OK) for f in options.created) or
any(os.access(f, os.F_OK) for f in options.deleted)):
time.sleep(options.sleep_interval_ms / 1000.0)
continue
sys.exit(0)
sys.exit(1)