diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 63fa9274..6645543a 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -193,6 +193,20 @@ If run without parameters, it prints the general help.""" self.finalize() +class Clean(Command): + """Clean stale locks.""" + + __metaclass__ = autocommand + + def __init__(self): + super(Clean, self).__init__() + + name = ("clean", None) + + def run(self): + self.init() + pisi.util.clean_locks() + self.finalize() def buildno_opts(self): self.parser.add_option("", "--ignore-build-no", action="store_true", diff --git a/pisi/util.py b/pisi/util.py index c939086b..33564318 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -358,6 +358,14 @@ def partition_freespace(directory): st = os.statvfs(directory) return st[statvfs.F_BSIZE] * st[statvfs.F_BFREE] +def clean_locks(top = '.'): + for root, dirs, files in os.walk(top): + for fn in files: + if fn.endswith('.lock'): + path = os.path.join(root, fn) + ctx.ui.info('Removing lock %s\n', path) + os.unlink(path) + ######################################## # Package/Repository Related Functions # ########################################