Browse Source

updated to comply with python 3

lookup-tables
Stephan Richter 8 years ago
parent
commit
09a15a4c4e
  1. 19
      src/web4rail.client.py
  2. 29
      src/web4rail.server.py

19
src/web4rail.client.py

@ -5,26 +5,27 @@ from FileDialog import * @@ -5,26 +5,27 @@ from FileDialog import *
from TrackPlan import *
from YesNoDialog import *
def readline(socket):
buffer = socket.recv(4096)
buff = socket.recv(4096)
buffering = True
while buffering:
if "\n" in buffer:
(line, buffer) = buffer.split("\n", 1)
if "\n" in buff:
(line, buff) = buff.split("\n", 1)
yield line
else:
more = socket.recv(4096)
if not more:
buffering = False
else:
buffer += more
if buffer:
yield buffer
buff += more
if buff:
yield buff
conn_dlg = ConnectDialog()
conn_dlg.run()
if conn_dlg.port != None:
if conn_dlg.port is not None:
client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_sock.connect((conn_dlg.host, conn_dlg.port))
client = readline(client_sock)
@ -57,7 +58,7 @@ if conn_dlg.port != None: @@ -57,7 +58,7 @@ if conn_dlg.port != None:
continue
if 'does not exist. Create' in line:
dir = line.split('does not exist')[0].strip()
directory = line.split('does not exist')[0].strip()
dialog = YesNoDialog(line)
if dialog.answer:
client_sock.send("yes\n")
@ -65,5 +66,5 @@ if conn_dlg.port != None: @@ -65,5 +66,5 @@ if conn_dlg.port != None:
client_sock.send("no\n")
continue
print line
print(line)
print "Test"

29
src/web4rail.server.py

@ -1,8 +1,11 @@ @@ -1,8 +1,11 @@
#!/usr/bin/python
import socket,sys,os
import socket
import sys
import os
from thread import *
class web4rail_server:
system = None
@ -13,23 +16,24 @@ class web4rail_server: @@ -13,23 +16,24 @@ class web4rail_server:
try:
self.socket.bind(('', port))
except socket.error as msg:
print 'Bind failed. Error ('+str(msg[0])+'): '+str(msg[1])
print('Bind failed. Error (' + str(msg[0]) + '): ' + str(msg[1]))
sys.exit(-1)
print 'Bound to socket at port '+str(port)
print('Bound to socket at port ' + str(port))
def client(self, conn):
if self.system == None:
if self.system is None:
self.select_system(conn)
conn.close
def create_system(self, path):
print 'creating new system at '+path
print('creating new system at ' + path)
os.mkdir(path, 0755)
file = open(path+'/plan.json', 'w+')
json_file = open(path + '/plan.json', 'w+')
json_file.close()
def load_system(self, path, conn):
print 'loading system from '+path
print('loading system from ' + path)
with open(path + '/plan.json', 'r') as plan_file:
plan = plan_file.read()
conn.send("PLAN:\n")
@ -37,7 +41,7 @@ class web4rail_server: @@ -37,7 +41,7 @@ class web4rail_server:
def select_system(self, conn):
path = '/'
conn.send("Welcome to the Web2Rail server. Please select a SYSTEM first:\n");
conn.send("Welcome to the Web2Rail server. Please select a SYSTEM first:\n")
while True:
conn.send('current dir: ' + path + "\n")
contents = sorted(os.listdir(path))
@ -53,22 +57,21 @@ class web4rail_server: @@ -53,22 +57,21 @@ class web4rail_server:
path += entry + '/'
else:
conn.send(path + entry + ' does not exist. Create (yes/no/abort)?\n')
input = conn.recv(1024).strip()
if input == 'yes':
response = conn.recv(1024).strip()
if response == 'yes':
path += entry
self.create_system(path)
break
if input == 'abort':
if response == 'abort':
path = None
break
path = '/'
if path == None:
if path is None:
return
self.load_system(path, conn)
def start(self):
self.socket.listen(10)
print 'Server started.'

Loading…
Cancel
Save