From de48d164bfd90b0bca74f73e60214d1d2fcf1ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Wed, 14 Sep 2005 10:43:38 +0000 Subject: [PATCH] * start a clean command to remove somehow stale locks --- pisi/cli/commands.py | 14 ++++++++++++++ pisi/util.py | 8 ++++++++ 2 files changed, 22 insertions(+) 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 # ########################################