Dan Boitnott avatar Dan Boitnott committed e299fcb

Removed "with" statements for compatibility with Python 2.4

Comments (0)

Files changed (3)

     closed = False
 
     def addFile(self, fp):
-        with self.lock:
+        self.lock.acquire()
+        try:
             self.flush()
             self.fps.append(fp)
+        finally:
+            self.lock.release()
 
     def removeFile(self, fp):
-        with self.lock:
+        self.lock.acquire()
+        try:
             self.flush()
             self.fps.remove(fp)
+        finally:
+            self.lock.release()
 
     def write(self, str):
-        with self.lock:
+        self.lock.acquire()
+        try:
             for fp in self.fps:
                 if fp.closed:
                     self.removeFile(fp)
                     continue
                 fp.write(str)
+        finally:
+            self.lock.release()
 
     def writelines(self, seq):
-        with self.lock:
+        self.lock.acquire()
+        try:
             for fp in self.fps:
                 if fp.closed:
                     self.removeFile(fp)
                     continue
                 fp.writelines(seq)
+        finally:
+            self.lock.release()
 
     def flush(self):
-        with self.lock:
+        self.lock.acquire()
+        try:
             for fp in self.fps:
                 if fp.closed:
                     self.removeFile(fp)
                     continue
                 fp.flush()
+        finally:
+            self.lock.release()
 
     def close(self):
-        with self.lock:
+        self.lock.acquire()
+        try:
             for fp in self.fps:
                 fp.close()
             self.closed = True
+        finally:
+            self.lock.release()
 
 class CommandOutput(object):
     def __init__(self, path):
-        with open(path, 'r') as fp:
+    	fp = open(path, 'r')
+    	try:
             lines = [ line.rstrip() for line in fp ]
+        finally:
+        	fp.close()
 
         # Parse header
         self.headers = {}
             closeCmdLog()
 
             # Output any comments and move to an actual command
-            with scriptLock:
+            scriptLock.acquire()
+            try:
                 while scriptIndex < len(script) and type(script[scriptIndex]) is scripts.CommentTask:
                     script[scriptIndex].do()
                     scriptIndex += 1
+            finally:
+            	scriptLock.release()
 
     return str
 
     return currentLine.startswith("prise:")
 
 def closeCmdLog():
-    with curCmdLogLock:
-        global curCmdLog
+    global curCmdLog
+    curCmdLogLock.acquire()
+    try:
         if curCmdLog:
             multiOutput.removeFile(curCmdLog)
             print >>curCmdLog, "\n", util.RULE
             print >>curCmdLog, "Finished:", util.prettyTimestamp()
             curCmdLog.close()
             curCmdLog = None
+    finally:
+        curCmdLogLock.release()
 
 def getCommandOutputPathForKey(key):
     ret = os.path.join(runDir, "cmd.%s.log" % key)
     return getCommandOutputPathForKey(util.cmdHash(cmd.strip()) + "." + ts)
 
 def logCommand(cmd):
-    with curCmdLogLock:
+    curCmdLogLock.acquire()
+    try:
         global curCmdLog
         if curCmdLog:
             closeCmdLog()
                                           "Started" : util.prettyTimestamp(),
                                           "Host" : socket.gethostname()})
         multiOutput.addFile(curCmdLog)
+    finally:
+        curCmdLogLock.release()
 
 def runCommand(cmd):
     logCommand(cmd)
         webServer.shutdown()
 
 def getLastCmdIdx():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         ret = scriptIndex - 1
         while ret >= 0 and type(script[ret]) is scripts.CommentTask:
             ret -= 1
         return ret
+    finally:
+        scriptLock.release()
 
 def runLastCmd():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         idx = getLastCmdIdx()
         if idx < 0:
             printToUser("You are at the first command.")
             return
         script[idx].do()
-
+    finally:
+        scriptLock.release()
+    	
 def showLastCmd():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         idx = getLastCmdIdx()
         if idx < 0:
             printToUser("You are at the first command.")
             return
         printToUser("Last: " + script[idx].content)
-
+    finally:
+        scriptLock.release()
+    	
 def checkScriptIndex():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         global scriptIndex
         if scriptIndex >= len(script):
             printToUser("::: End of script :::")
             scriptIndex = len(script)
             return True
         return False
-
+    finally:
+        scriptLock.release()
+    	
 def incrScriptIndex():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         global scriptIndex
         scriptIndex += 1
         checkScriptIndex()
-
+    finally:
+        scriptLock.release()
+    	
 def skipNextCmd():
     incrScriptIndex()
     showNextCmd()
 
 def runNextCmd():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         if checkScriptIndex():
             return
         script[scriptIndex].do()
         incrScriptIndex()
+    finally:
+        scriptLock.release()
 
 def showNextCmd():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         if checkScriptIndex():
             return
         printToUser("Next: " + script[scriptIndex].content)
+    finally:
+        scriptLock.release()
 
 def hotkeyHelp():
     printToUser("""Hotkey Help:
     printToUser(out)
 
 def writeScript(path):
-    with scriptLock:
-        with open(path, 'w') as fp:
+    scriptLock.acquire()
+    try:
+        fp = open(path, 'w')
+        try:
             for task in script:
                 for line in task.getLines():
                     print >>fp, line
-
+        finally:
+            fp.close()
+    finally:
+        scriptLock.release()
+    	
 def backupScript():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         writeScript(os.path.join(runDir, "script.%s.ise" % util.timestamp()))
+    finally:
+        scriptLock.release()
 
 def saveScript():
-    with scriptLock:
+    scriptLock.acquire()
+    try:
         backupScript()
         writeScript(scriptPath)
+    finally:
+        scriptLock.release()
 
 
 hotkeys = {
             self.send_error(404, "no such file")
             return
 
-        with fp:
+        try:
             type = mimetypes.guess_type(filename)[0]
 
             # Send headers
 
             # Send bytes
             shutil.copyfileobj(fp, self.wfile)
+        finally:
+            fp.close()
 
     def sendTemplate(self, templateName, contentType = "text/html", **args):
         context = {
         idx = int(self.postVars['index'][0]);
         hash = self.postVars['hash'][0];
 
-        with state.scriptLock:
+        state.scriptLock.acquire()
+        try:
             if idx >= len(state.script):
                 self.send_error(500, "invalid script index: " + idx)
                 return
                 state.script = state.script[:idx] + newScript + state.script[idx + 1:]
 
             state.saveScript()
+        finally:
+            state.scriptLock.release()
 
         self.redirect("/")
 
         idx = int(query['index'][0])
         hash = query['hash'][0]
 
-        with state.scriptLock:
+        state.scriptLock.acquire()
+        try:
             if idx >= len(state.script):
                 self.send_error(500, "invalid script index: " + idx)
                 return
 
             state.scriptIndex = idx
             state.runNextCmd()
+        finally:
+            state.scriptLock.release()
 
         # Wait one second for some output
         time.sleep(1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.