Rely on PYTHONPATH instead of PORTAGE_PYM_PATH for locating portage's python modules...
[portage.git] / bin / clean_locks
1 #!/usr/bin/python -O
2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Id$
5
6 import os,sys,errno
7 try:
8         import portage_locks
9 except ImportError:
10         sys.path.insert(0, "/usr/lib/portage/pym")
11         import portage_locks
12
13 if not sys.argv[1:] or "--help" in sys.argv or "-h" in sys.argv:
14         import portage
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, 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)