Ramesh-vani commited on
Commit
815659a
·
verified ·
1 Parent(s): 186ae69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -9
app.py CHANGED
@@ -38,9 +38,9 @@ async def generate_file_structure(path, encoding='utf-8'):
38
 
39
  return file_structure
40
 
41
- async def rename_item(websocket, key,project_name, path,new_name, connected):
42
 
43
- old_path = os.path.join(os.getcwd(),'projects', key,project_name, path)
44
  new_name = new_name
45
 
46
  try:
@@ -55,8 +55,10 @@ async def rename_item(websocket, key,project_name, path,new_name, connected):
55
  event = {
56
  "type": "rename-success",
57
  "data": f'{old_path}-->{new_path}',
58
- "old_path": path,
59
- "new_name": new_name,
 
 
60
  }
61
  websockets.broadcast(connected,json.dumps(event))
62
  else:
@@ -70,10 +72,10 @@ async def rename_item(websocket, key,project_name, path,new_name, connected):
70
  except Exception as e:
71
  websockets.broadcast(connected,str(e))
72
 
73
- async def delete_item(websocket, key,project_name, path, connected):
74
  try:
75
 
76
- item_path = os.path.join(os.getcwd(), 'projects', key,project_name, path)
77
 
78
  if os.path.exists(item_path):
79
  if os.path.isdir(item_path):
@@ -84,6 +86,7 @@ async def delete_item(websocket, key,project_name, path, connected):
84
  event = {
85
  "type": "delete-success",
86
  "data": path,
 
87
  }
88
  websockets.broadcast(connected,json.dumps(event))
89
  # websockets.broadcast(connected,'success')
@@ -346,13 +349,13 @@ async def exe(websocket,connected,key):
346
 
347
  elif event["command"]["type"]=="delete":
348
 
349
- await delete_item(websocket, key,event["project_name"], event["path"], connected)
350
  elif event["command"]["type"]=="get_content":
351
 
352
  await get_file_content(websocket, key,event["project_name"],event["filePath"], event["rfilePath"],event["fileName"] ,connected)
353
  elif event["command"]["type"]=="rename":
354
 
355
- await rename_item(websocket, key,event["project_name"], event["path"], event["name"], connected)
356
  elif event["command"]["type"]=="join":
357
  await join(websocket, event["join"])
358
  elif event["command"]["type"]=="sendDir":
@@ -367,13 +370,50 @@ async def exe(websocket,connected,key):
367
  # websockets.broadcast(connected,json.dumps(event))
368
  websockets.broadcast(connected, json.dumps(event))
369
  elif event["command"]["type"]=="createItemUI":
370
- data=json.loads(event["file_structure"])
371
  event = {
372
  "type": "createItemUI",
373
 
374
  'targetElementData':event['targetElementData'],
375
  'data':event['data']
376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  }
378
  # websockets.broadcast(connected,json.dumps(event))
379
  websockets.broadcast(connected, json.dumps(event))
 
38
 
39
  return file_structure
40
 
41
+ async def rename_item(websocket, key,project_name, path,rpath,new_name,root, connected):
42
 
43
+ old_path = os.path.join(os.getcwd(),'projects', key,project_name, rpath)
44
  new_name = new_name
45
 
46
  try:
 
55
  event = {
56
  "type": "rename-success",
57
  "data": f'{old_path}-->{new_path}',
58
+ "path": path,
59
+ "new_rpath":rpath
60
+ "name": new_name,
61
+ "root":root
62
  }
63
  websockets.broadcast(connected,json.dumps(event))
64
  else:
 
72
  except Exception as e:
73
  websockets.broadcast(connected,str(e))
74
 
75
+ async def delete_item(websocket, key,project_name, path,rpath connected):
76
  try:
77
 
78
+ item_path = os.path.join(os.getcwd(), 'projects', key,project_name, rpath)
79
 
80
  if os.path.exists(item_path):
81
  if os.path.isdir(item_path):
 
86
  event = {
87
  "type": "delete-success",
88
  "data": path,
89
+ "path":path
90
  }
91
  websockets.broadcast(connected,json.dumps(event))
92
  # websockets.broadcast(connected,'success')
 
349
 
350
  elif event["command"]["type"]=="delete":
351
 
352
+ await delete_item(websocket, key,event["project_name"], event["path"],event['rpath'], connected)
353
  elif event["command"]["type"]=="get_content":
354
 
355
  await get_file_content(websocket, key,event["project_name"],event["filePath"], event["rfilePath"],event["fileName"] ,connected)
356
  elif event["command"]["type"]=="rename":
357
 
358
+ await rename_item(websocket, key,event["project_name"], event["path"],event['rpath'], event["name"], event["root"], connected)
359
  elif event["command"]["type"]=="join":
360
  await join(websocket, event["join"])
361
  elif event["command"]["type"]=="sendDir":
 
370
  # websockets.broadcast(connected,json.dumps(event))
371
  websockets.broadcast(connected, json.dumps(event))
372
  elif event["command"]["type"]=="createItemUI":
373
+
374
  event = {
375
  "type": "createItemUI",
376
 
377
  'targetElementData':event['targetElementData'],
378
  'data':event['data']
379
 
380
+ }
381
+ # websockets.broadcast(connected,json.dumps(event))
382
+ websockets.broadcast(connected, json.dumps(event))
383
+
384
+ elif event["command"]["type"]=="renameItemInUI":
385
+
386
+ event = {
387
+ "type": "renameItemInUI",
388
+
389
+ 'path':event['path'],
390
+ 'new_path':event['new_path'],
391
+ 'name':event['name'],
392
+ 'new_rpath':event['new_rpath'],
393
+
394
+ }
395
+ # websockets.broadcast(connected,json.dumps(event))
396
+ websockets.broadcast(connected, json.dumps(event))
397
+ elif event["command"]["type"]=="createFolderUI":
398
+
399
+ event = {
400
+ "type": "createFolderUI",
401
+
402
+ 'targetElementData':event['targetElementData'],
403
+ 'data':event['data']
404
+
405
+ }
406
+ # websockets.broadcast(connected,json.dumps(event))
407
+ websockets.broadcast(connected, json.dumps(event))
408
+
409
+ elif event["command"]["type"]=="removeItemFromUI":
410
+
411
+ event = {
412
+ "type": "removeItemFromUI",
413
+
414
+ 'targetElementData':event['targetElementData'],
415
+ 'path':event['path']
416
+
417
  }
418
  # websockets.broadcast(connected,json.dumps(event))
419
  websockets.broadcast(connected, json.dumps(event))