Use normpath from support
[catalyst.git] / catalyst / lock.py
index ef00b49c52133dccef8a202aff6ff0207942570b..764c11e690248232e783550a018f96c7ea0115e6 100644 (file)
@@ -1,10 +1,15 @@
 #!/usr/bin/python
+
+
 import os
 import fcntl
 import errno
 import sys
 import time
-from catalyst.support import CatalystError
+
+
+from catalyst.support import CatalystError, normpath
+
 
 def writemsg(mystr):
        sys.stderr.write(mystr)
@@ -80,7 +85,7 @@ class LockDir:
                        if not self.islocked():
                                if lockdir[-1] == "/":
                                        lockdir=lockdir[:-1]
-                               self.lockdir=normpath(lockdir)
+                               self.lockdir = normpath(lockdir)
 #                              if "DEBUG" in self.settings:
 #                                      print "setting lockdir to", self.lockdir
                else:
@@ -94,7 +99,7 @@ class LockDir:
 
        def set_lockfile(self):
                if not self.islocked():
-                       self.lockfile=normpath(self.lockdir+'/'+self.lockfilename)
+                       self.lockfile = normpath(self.lockdir+'/'+self.lockfilename)
 #                      if "DEBUG" in self.settings:
 #                              print "setting lockfile to", self.lockfile
 
@@ -122,7 +127,7 @@ class LockDir:
                if self.myfd==None:
                        if not os.path.exists(os.path.dirname(self.lockdir)):
                                raise CatalystError("DirectoryNotFound: %s"
-                                       % os.path.dirname(self.lockdir))
+                                       % os.path.dirname(self.lockdir), print_traceback=True)
                        if not os.path.exists(self.lockfile):
                                old_mask=os.umask(000)
                                self.myfd = os.open(self.lockfile, os.O_CREAT|os.O_RDWR,0660)
@@ -265,7 +270,8 @@ class LockDir:
                        self.add_hardlock_file_to_cleanup()
                        if not os.path.exists(self.myhardlock):
                                raise CatalystError("FileNotFound: Created lockfile is missing: "
-                                       "%(filename)s" % {"filename":self.myhardlock})
+                                       "%(filename)s" % {"filename":self.myhardlock},
+                                       print_traceback=True)
                        try:
                                os.link(self.myhardlock, self.lockfile)
                        except SystemExit:
@@ -429,12 +435,12 @@ if __name__ == "__main__":
                        print i,time.time()
                        time.sleep(1)
                print
-       def normpath(mypath):
-               newpath = os.path.normpath(mypath)
-               if len(newpath) > 1:
-                       if newpath[1] == "/":
-                               newpath = "/"+newpath.lstrip("/")
-               return newpath
+       #def normpath(mypath):
+               #newpath = os.path.normpath(mypath)
+               #if len(newpath) > 1:
+                       #if newpath[1] == "/":
+                               #newpath = "/"+newpath.lstrip("/")
+               #return newpath
 
        print "Lock 5 starting"
        Lock1=LockDir("/tmp/lock_path")
@@ -473,9 +479,3 @@ if __name__ == "__main__":
        Lock1.unlock()
        print "Lock1 unlock"
 
-#Lock1.write_lock()
-#time.sleep(2)
-#Lock1.unlock()
-    ##Lock1.write_lock()
-    #time.sleep(2)
-    #Lock1.unlock()