diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-02-04 18:07:32 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-02-04 18:07:32 +0100 |
commit | da981e78253ab2b8715f4e10e175be4bea43c133 (patch) | |
tree | 20ecc711861fdaf6e3676b5110fd6ac9d589da73 /scripts/flock.py | |
parent | b56b618abf0b15025b61ab96dcc873cf7af82450 (diff) | |
download | qtlocation-mapboxgl-da981e78253ab2b8715f4e10e175be4bea43c133.tar.gz |
move config files to config/ folder
Diffstat (limited to 'scripts/flock.py')
-rwxr-xr-x | scripts/flock.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/flock.py b/scripts/flock.py new file mode 100755 index 0000000000..6ceb585cdc --- /dev/null +++ b/scripts/flock.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +import fcntl, os, subprocess, sys, errno + +# from http://stackoverflow.com/a/600612 +def mkdir_p(path): + try: + os.makedirs(path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): + pass + else: raise + +def flock(lockfile, cmd_list, verbose = False): + mkdir_p(os.path.dirname(lockfile)) + fd = os.open(lockfile, os.O_RDONLY | os.O_NOCTTY | os.O_CREAT, 0o666) + fcntl.flock(fd, fcntl.LOCK_EX) + if verbose: + print(' '.join(cmd_list)) + return subprocess.call(cmd_list) + +if '__main__' == __name__: + try: + if sys.argv[1] == '-v': + sys.exit(flock(sys.argv[2], sys.argv[3:], True)) + else: + sys.exit(flock(sys.argv[1], sys.argv[2:])) + except KeyboardInterrupt: + sys.exit(1) |