Remove magic INC number in resource_locking.py 63/91463/1
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 7 Oct 2016 15:21:21 +0000 (17:21 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 7 Oct 2016 15:29:16 +0000 (17:29 +0200)
Change-Id: I25ada81e4f2224f8ec23d43c960ff435ad201397
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
tct/resource_locking.py

index bb0b44b..5183411 100755 (executable)
@@ -111,8 +111,9 @@ class UUIDlist(object):
         return ret
 
 class UUIDmanager:
-    def __init__(self, target):
+    def __init__(self, target, inc):
         self.target = target
+        self.inc = inc
 
     def lock(self):
         # go through the list of not locked uuid files and stop on the first successfully locked
@@ -156,11 +157,11 @@ class UUIDmanager:
         return True
 
     def unlockfailed(self):
-        # unlock target as usual and increase its counter by 10
+        # unlock target as usual and increase its counter by self.inc
         if not self.unlock():
             logging.warn("Unlock failed: %s", self.target)
         uuid = UUID_PREFIX + self.target
-        UUIDlist.set_cnt(uuid, UUIDlist.get_cnt(uuid)+10)
+        UUIDlist.set_cnt(uuid, UUIDlist.get_cnt(uuid) + self.inc)
 
 def parse_arguments():
     parser = argparse.ArgumentParser(description="Manager of locks on UUID files")
@@ -184,7 +185,11 @@ def parse_arguments():
 
     group.add_argument("-f", "--unlockfailed",
             action="store_true", default=False, dest="unlockfailed",
-            help="Unlock a device and increment counter by 10")
+            help="Unlock a device and increment counter by INC")
+
+    parser.add_argument("--inc", type=int,
+            action="store", default=10, dest="inc",
+            help="Set INC value (default: 10)")
 
     parser.add_argument("-L", "--log",
             action="store", dest="loglevel",
@@ -202,7 +207,7 @@ def main():
             raise ValueError('Invalid log level: %s' % args.loglevel)
         logging.basicConfig(format='%(asctime)s %(message)s',level=numeric_level)
     logging.debug("Begin")
-    uuid_man = UUIDmanager(args.target)
+    uuid_man = UUIDmanager(args.target, args.inc)
     if args.lock:
         if not uuid_man.lock():
             logging.warn("File locking unsuccessful!")