From 1f120980a3217289f4bad02b813053664732e4bf Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 11 Jun 2012 20:11:44 -0700 Subject: Rename sem class to file sem class, add clear_all methods, add empty methods to dummy sem class. --- cloudinit/helpers.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index 16548001..e5f33a26 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -49,8 +49,14 @@ class DummySemaphores(object): def has_run(self, _name, _freq): return False + def clear(self, _name, _freq): + return True + + def clear_all(self): + pass + -class Semaphores(object): +class FileSemaphores(object): def __init__(self, sem_path): self.sem_path = sem_path @@ -71,6 +77,12 @@ class Semaphores(object): return False return True + def clear_all(self): + try: + util.del_dir(self.sem_path) + except (IOError, OSError): + pass + def _acquire(self, name, freq): if self.has_run(name, freq): return None @@ -117,7 +129,7 @@ class Runners(object): if not sem_path: return None if sem_path not in self.sems: - self.sems[sem_path] = Semaphores(sem_path) + self.sems[sem_path] = FileSemaphores(sem_path) return self.sems[sem_path] def run(self, name, functor, args, freq=None, clear_on_fail=False): -- cgit v1.2.3