lock-helper.py: make locks quiet
[portage.git] / bin / lock-helper.py
1 #!/usr/bin/python
2 # Copyright 2010 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 import os
6 import sys
7 sys.path.insert(0, os.environ['PORTAGE_PYM_PATH'])
8 import portage
9
10 def main(args):
11
12         if args and sys.hexversion < 0x3000000 and not isinstance(args[0], unicode):
13                 for i, x in enumerate(args):
14                         args[i] = portage._unicode_decode(x, errors='strict')
15
16         # Make locks quiet since unintended locking messages displayed on
17         # stdout would corrupt the intended output of this program.
18         portage.locks._quiet = True
19         lock_obj = portage.locks.lockfile(args[0], wantnewlockfile=True)
20         sys.stdout.write('\0')
21         sys.stdout.flush()
22         sys.stdin.read(1)
23         portage.locks.unlockfile(lock_obj)
24         return portage.os.EX_OK
25
26 if __name__ == "__main__":
27         rval = main(sys.argv[1:])
28         sys.exit(rval)