Ramesh-vani commited on
Commit
bee7181
·
verified ·
1 Parent(s): edee65d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -22,7 +22,7 @@ class FileHandler(FileSystemEventHandler):
22
  return
23
  with open(event.src_path, 'r', encoding='utf-8') as file:
24
  content = file.read()
25
- print(f'File {event.src_path} has been modified.')
26
  new_event = {
27
  "type": "file-modifie",
28
  "content": content,
@@ -39,19 +39,19 @@ class FileHandler(FileSystemEventHandler):
39
  "path": event.src_path,
40
  "name": event.src_path.split('/')[-1]
41
  }
42
- print(new_event)
43
  websockets.broadcast(self.connected,json.dumps(new_event))
44
  else:
45
  with open(event.src_path, 'r', encoding='utf-8') as file:
46
  content = file.read()
47
- print(f'File {event.src_path} has been created.')
48
  new_event = {
49
  "type": "file-create",
50
  "content": content,
51
  "path": event.src_path,
52
  "name": event.src_path.split('/')[-1]
53
  }
54
- print(new_event)
55
  websockets.broadcast(self.connected,json.dumps(new_event))
56
  # websockets.broadcast(self.connected,f'File {event.src_path} has been created.')
57
 
@@ -65,7 +65,7 @@ class FileHandler(FileSystemEventHandler):
65
  }
66
  websockets.broadcast(self.connected,json.dumps(new_event))
67
  else:
68
- print(f'File {event.src_path} has been deleted.')
69
  new_event = {
70
  "type": "delete",
71
  "name": event.src_path.split('/')[-1],
@@ -85,7 +85,7 @@ class FileHandler(FileSystemEventHandler):
85
  }
86
  websockets.broadcast(self.connected,json.dumps(new_event))
87
  else:
88
- print(f'File {event.src_path} has been renamed to {event.dest_path}.')
89
  new_event = {
90
  "type": "rename",
91
 
@@ -174,7 +174,7 @@ async def delete_item(websocket, key,project_name, path,rpath,targetElementData,
174
  "path":path,
175
  "targetElementData":targetElementData,
176
  }
177
- print(event)
178
  websockets.broadcast(connected,json.dumps(event))
179
  # websockets.broadcast(connected,'success')
180
  else:
@@ -239,7 +239,7 @@ async def create_folder(websocket, key,project_name, path,name,root,targetElemen
239
  "root":root,
240
  "targetElementData":targetElementData,
241
  }
242
- print(folder_path,'created')
243
  websockets.broadcast(connected,json.dumps(event))
244
 
245
 
@@ -266,7 +266,7 @@ async def wirte_file(websocket, key,project_name, path, content, connected):
266
 
267
  async def read_process_output(process, websocket):
268
  async for line in process.stdout:
269
- print('sending line')
270
 
271
  event = {
272
  "type": "terminal-data",
@@ -276,7 +276,7 @@ async def read_process_output(process, websocket):
276
 
277
 
278
  async for line in process.stderr:
279
- print(f'error:{line.strip()}')
280
  event = {
281
  "type": "terminal-error",
282
  "data": line.strip().decode('utf-8'),
@@ -299,7 +299,7 @@ async def handle_user_input(websocket,key, process, connected):
299
  event = json.loads(message)
300
  assert event["type"] == "cmd"
301
  # command = event["command"]
302
- print(f'Received user input: {event}')
303
  try:
304
  if event["command"]["type"]=="shell":
305
  await asyncio.sleep(0.1)
@@ -314,7 +314,7 @@ async def handle_user_input(websocket,key, process, connected):
314
  try:
315
  # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
316
  # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
317
- print(base_path)
318
  mod_command = f'cd {base_path}&& {event["command"]["command"]}'
319
 
320
  try:
@@ -328,7 +328,7 @@ async def handle_user_input(websocket,key, process, connected):
328
  )
329
 
330
  async def send_message(message):
331
- print('sending msg')
332
  # await websocket.send(f'data: {message}')
333
  websockets.broadcast(connected,json.dumps(message) )
334
 
@@ -557,10 +557,10 @@ async def handle_user_input(websocket,key, process, connected):
557
  continue
558
  break
559
  except websockets.ConnectionClosed:
560
- print("WebSocket connection closed")
561
  break
562
  except Exception as e:
563
- print(f"Error in input thread: {str(e)}")
564
 
565
  def process_input(user_input, process):
566
  if process:
@@ -568,9 +568,10 @@ def process_input(user_input, process):
568
  process.stdin.write(user_input.encode('utf-8') + b'\n')
569
  #process.stdin.flush()
570
  except Exception as e:
571
- print(f"Error writing to process stdin: {str(e)}")
572
  else:
573
- print("No process available to write to.")
 
574
 
575
  async def create_file_structure(websocket, data, base_path='.'):
576
  if data['type'] == 'folder':
@@ -607,14 +608,14 @@ async def exe(websocket,connected,key):
607
  Receive and process moves from a player.
608
 
609
  """
610
- print('in exe')
611
  async for message in websocket:
612
  # Parse a "play" event from the UI.
613
- print(message)
614
  event = json.loads(message)
615
  assert event["type"] == "cmd"
616
  # command = event["command"]
617
- print(event)
618
 
619
  try:
620
  if event["command"]["type"]=="shell":
@@ -628,7 +629,7 @@ async def exe(websocket,connected,key):
628
  try:
629
  # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
630
  # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
631
- print(base_path)
632
  mod_command = f'cd {base_path}&& {event["command"]["command"]}'
633
 
634
  try:
@@ -642,7 +643,7 @@ async def exe(websocket,connected,key):
642
  )
643
 
644
  async def send_message(message):
645
- print('sending msg')
646
  # await websocket.send(f'data: {message}')
647
  websockets.broadcast(connected,json.dumps(message) )
648
 
@@ -925,7 +926,7 @@ async def handler(websocket):
925
  # Receive and parse the "init" event from the UI.
926
  message = await websocket.recv()
927
  event = json.loads(message)
928
- print(event)
929
  # project_name = event["project_name"]
930
  # assert event["type"] == "init"
931
  if event["type"] == "init":
@@ -936,7 +937,7 @@ async def handler(websocket):
936
  # First player starts a new game.
937
  await start(websocket, message)
938
  elif event["type"] == "cmd":
939
- print('executing commad')
940
  # Execute a command in the project folder.
941
  await execute_command(websocket, event["project_name"], event["command"])
942
 
 
22
  return
23
  with open(event.src_path, 'r', encoding='utf-8') as file:
24
  content = file.read()
25
+ # print(f'File {event.src_path} has been modified.')
26
  new_event = {
27
  "type": "file-modifie",
28
  "content": content,
 
39
  "path": event.src_path,
40
  "name": event.src_path.split('/')[-1]
41
  }
42
+ # print(new_event)
43
  websockets.broadcast(self.connected,json.dumps(new_event))
44
  else:
45
  with open(event.src_path, 'r', encoding='utf-8') as file:
46
  content = file.read()
47
+ # print(f'File {event.src_path} has been created.')
48
  new_event = {
49
  "type": "file-create",
50
  "content": content,
51
  "path": event.src_path,
52
  "name": event.src_path.split('/')[-1]
53
  }
54
+ # print(new_event)
55
  websockets.broadcast(self.connected,json.dumps(new_event))
56
  # websockets.broadcast(self.connected,f'File {event.src_path} has been created.')
57
 
 
65
  }
66
  websockets.broadcast(self.connected,json.dumps(new_event))
67
  else:
68
+ # print(f'File {event.src_path} has been deleted.')
69
  new_event = {
70
  "type": "delete",
71
  "name": event.src_path.split('/')[-1],
 
85
  }
86
  websockets.broadcast(self.connected,json.dumps(new_event))
87
  else:
88
+ # print(f'File {event.src_path} has been renamed to {event.dest_path}.')
89
  new_event = {
90
  "type": "rename",
91
 
 
174
  "path":path,
175
  "targetElementData":targetElementData,
176
  }
177
+ # print(event)
178
  websockets.broadcast(connected,json.dumps(event))
179
  # websockets.broadcast(connected,'success')
180
  else:
 
239
  "root":root,
240
  "targetElementData":targetElementData,
241
  }
242
+ # print(folder_path,'created')
243
  websockets.broadcast(connected,json.dumps(event))
244
 
245
 
 
266
 
267
  async def read_process_output(process, websocket):
268
  async for line in process.stdout:
269
+ # print('sending line')
270
 
271
  event = {
272
  "type": "terminal-data",
 
276
 
277
 
278
  async for line in process.stderr:
279
+ # print(f'error:{line.strip()}')
280
  event = {
281
  "type": "terminal-error",
282
  "data": line.strip().decode('utf-8'),
 
299
  event = json.loads(message)
300
  assert event["type"] == "cmd"
301
  # command = event["command"]
302
+ # print(f'Received user input: {event}')
303
  try:
304
  if event["command"]["type"]=="shell":
305
  await asyncio.sleep(0.1)
 
314
  try:
315
  # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
316
  # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
317
+ # print(base_path)
318
  mod_command = f'cd {base_path}&& {event["command"]["command"]}'
319
 
320
  try:
 
328
  )
329
 
330
  async def send_message(message):
331
+ # print('sending msg')
332
  # await websocket.send(f'data: {message}')
333
  websockets.broadcast(connected,json.dumps(message) )
334
 
 
557
  continue
558
  break
559
  except websockets.ConnectionClosed:
560
+ # print("WebSocket connection closed")
561
  break
562
  except Exception as e:
563
+ # print(f"Error in input thread: {str(e)}")
564
 
565
  def process_input(user_input, process):
566
  if process:
 
568
  process.stdin.write(user_input.encode('utf-8') + b'\n')
569
  #process.stdin.flush()
570
  except Exception as e:
571
+ # print(f"Error writing to process stdin: {str(e)}")
572
  else:
573
+ # print("No process available to write to.")
574
+ pass
575
 
576
  async def create_file_structure(websocket, data, base_path='.'):
577
  if data['type'] == 'folder':
 
608
  Receive and process moves from a player.
609
 
610
  """
611
+ # print('in exe')
612
  async for message in websocket:
613
  # Parse a "play" event from the UI.
614
+ # print(message)
615
  event = json.loads(message)
616
  assert event["type"] == "cmd"
617
  # command = event["command"]
618
+ # print(event)
619
 
620
  try:
621
  if event["command"]["type"]=="shell":
 
629
  try:
630
  # await execute_command(websocket, key,event["project_name"], event["command"]["command"], connected)
631
  # base_path = os.path.join(os.getcwd(), 'projects', key,event["project_name"])
632
+ # print(base_path)
633
  mod_command = f'cd {base_path}&& {event["command"]["command"]}'
634
 
635
  try:
 
643
  )
644
 
645
  async def send_message(message):
646
+ # print('sending msg')
647
  # await websocket.send(f'data: {message}')
648
  websockets.broadcast(connected,json.dumps(message) )
649
 
 
926
  # Receive and parse the "init" event from the UI.
927
  message = await websocket.recv()
928
  event = json.loads(message)
929
+ # print(event)
930
  # project_name = event["project_name"]
931
  # assert event["type"] == "init"
932
  if event["type"] == "init":
 
937
  # First player starts a new game.
938
  await start(websocket, message)
939
  elif event["type"] == "cmd":
940
+ # print('executing commad')
941
  # Execute a command in the project folder.
942
  await execute_command(websocket, event["project_name"], event["command"])
943