Enable BytesWarnings.
[portage.git] / bin / clean_locks
1 #!/usr/bin/python -bbO
2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 from __future__ import print_function
6
7 import sys, errno
8 from os import path as osp
9 pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")
10 sys.path.insert(0, pym_path)
11 import portage
12 portage._internal_caller = True
13
14 if not sys.argv[1:] or "--help" in sys.argv or "-h" in sys.argv:
15         print()
16         print("You must specify directories with hardlink-locks to clean.")
17         print("You may optionally specify --force, which will remove all")
18         print("of the locks, even if we can't establish if they are in use.")
19         print("Please attempt cleaning without force first.")
20         print()
21         print("%s %s/.locks" % (sys.argv[0], portage.settings["DISTDIR"]))
22         print("%s --force %s/.locks" % (sys.argv[0], portage.settings["DISTDIR"]))
23         print()
24         sys.exit(1)
25
26 force = False
27 if "--force" in sys.argv[1:]:
28         force=True
29
30 for x in sys.argv[1:]:
31         if x == "--force":
32                 continue
33         try:
34                 for y in portage.locks.hardlock_cleanup(x, remove_all_locks=force):
35                         print(y)
36                 print()
37
38         except OSError as e:
39                 if e.errno in (errno.ENOENT, errno.ENOTDIR):
40                         print("!!! %s is not a directory or does not exist" % x)
41                 else:
42                         raise
43                 sys.exit(e.errno)