소스 검색

Update to pycl from Phil Pennock

* Made the GET handler deal with /status explicitly.
* Deal with text-editor returning non-zero, so that I can :cq from
  vim to exit non-zero and not have the text area updated
Alex Bennee 14 년 전
부모
커밋
21d37462d9
1개의 변경된 파일22개의 추가작업 그리고 8개의 파일을 삭제
  1. 22 8
      pycl.py

+ 22 - 8
pycl.py

@@ -26,7 +26,13 @@ class Handler(BaseHTTPRequestHandler):
     global temp_has_delete
 
     def do_GET(self):
-        self.send_error(404, "Not Found: %s" % self.path)
+	if self.path == '/status':
+		self.send_response(200)
+		self.send_header('Content-Type', 'text/plain; charset=utf-8')
+		self.end_headers()
+		self.wfile.write('edit-server is running.\n')
+		return
+        self.send_error(404, "GET Not Found: %s" % self.path)
 
     def do_POST(self):
         try:
@@ -72,16 +78,24 @@ class Handler(BaseHTTPRequestHandler):
             print "Spawning editor... ", fname
 
             p = subprocess.Popen(["/usr/bin/emacsclient", "-c", fname], close_fds=True)
+            #p = subprocess.Popen(["/usr/local/bin/mvim", "--remote-wait", fname], close_fds=True)
 
             # hold connection open until editor finishes
-            p.wait()
+            rc = p.wait()
 
-            self.send_response(200)
-            self.end_headers()
+            if not rc:
+                    self.send_response(200)
+                    self.end_headers()
 
-            f = file(fname, 'r')
-            s = f.read()
-            f.close()
+                    f = file(fname, 'r')
+                    s = f.read()
+                    f.close()
+            else:
+                    if rc > 0:
+                            msg = 'text editor returned %d' % rc
+                    elif rc < 0:
+                            msg = 'text editor died on signal %d' % -rc
+                    self.send_error(404, msg)
 
             try:
                 os.unlink(fname)
@@ -93,7 +107,7 @@ class Handler(BaseHTTPRequestHandler):
         except :
             print "Error: ", sys.exc_info()[0]
             self.send_error(404, "Not Found: %s" % self.path)
-    
+
 def main():
     global temp_has_delete
     import platform