Eran Goldman-Malka 5 лет назад
Родитель
Сommit
998807c960
2 измененных файлов с 49 добавлено и 0 удалено
  1. 49 0
      p.py
  2. BIN
      websocketd

+ 49 - 0
p.py

@@ -0,0 +1,49 @@
+#!/usr/bin/python
+from sys import stdout, stdin, exit
+import sys
+import traceback
+
+import os
+
+lockFile = "/var/lock/socketLock"
+c = ""
+
+exists = os.path.isfile(lockFile)
+if exists:
+    stdout.write("socket is already connected.")
+    stdout.flush()
+    exit()
+else:
+    with open(lockFile, 'a'):
+        os.utime(lockFile, None)
+    # Store configuration file values
+
+while True:
+    s = stdin.readline().replace('\n','')  #  raw_input()
+    if s == 'exit':
+        os.remove(lockFile)
+        exit()
+    if s == 'go':
+        description='source string'
+        try:
+            exec(c)
+            stdout.flush()
+            c = ""
+        except SyntaxError as err:
+            error_class = err.__class__.__name__
+            detail = err.args[0]
+            line_number = err.lineno
+            stdout.write(("%s at line %d of %s: %s\n\n" % (error_class, line_number, description, detail)))
+            stdout.flush()
+            c = ""
+        except Exception as err:
+            error_class = err.__class__.__name__
+            detail = err.args[0]
+            cl, exc, tb = sys.exc_info()
+            line_number = traceback.extract_tb(tb)[-1][1]
+            stdout.write(("%s at line %d of %s: %s\n\n" % (error_class, line_number, description, detail)))
+            stdout.flush()
+            c = ""
+    else:
+        s.replace('print','stdout.write')
+        c += s + '\n'