You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. from flask import Flask, render_template
  2. from flask_sock import Sock
  3. import flask
  4. import hot_reload_mod_i2
  5. import gmod
  6. import os
  7. # app = Flask(__name__)
  8. app = Flask(__name__,template_folder = r"../js_client")
  9. sock = Sock(app)
  10. gmod.glob["sock"] = sock
  11. gmod.glob["app"] = app
  12. class Eobj():
  13. pass
  14. eobj = Eobj()
  15. gmod.gx =eobj
  16. import rld_m0
  17. import rld_m1
  18. import rld_m2
  19. import rld_m3
  20. # import rld_m4
  21. # import rld_m5
  22. p=print
  23. @app.route('/')
  24. def index():
  25. print("::::::::::::::;")
  26. return render_template('jsyncdb_index_v5.html')
  27. return render_template('index.html')
  28. # r'''
  29. @app.route('/shared_libs/<path:path>')
  30. def send_report2(path):
  31. return flask.send_file('../js_client/jquery-3.5.1.min.js')
  32. @app.route('/<path:path>')
  33. def send_report(path):
  34. # return flask.send_from_directory('templates', path)
  35. return flask.send_from_directory(r"../js_client", path)
  36. return flask.send_from_directory('./', path)
  37. # '''
  38. @sock.route('/echo')
  39. def echo(sock):
  40. while True:
  41. data = sock.receive()
  42. sock.send(data)
  43. @sock.route('/echo_all')
  44. def echo_all(sock):
  45. gmod.gx.add_to_channel(sock,"echo_all")
  46. # send_to_channel("echo_all",msg,"sender")
  47. while True:
  48. data = sock.receive()
  49. # ws.send(data)
  50. gmod.gx.send_to_channel("echo_all",data,"sender")
  51. # @sock.route('/echo_c1')
  52. # def echo_coll(sock):
  53. # p("echo_coll app")
  54. # while True:
  55. # data = sock.receive()
  56. # sock.send(data)
  57. # @sock.route('/<path:path>')
  58. # def echo23(sock,*a,**kw):
  59. # p("E2",a,kw)
  60. # while True:
  61. # data = sock.receive()
  62. # sock.send(data)
  63. # for en in dir(sock):
  64. # p(en)
  65. # p("echo23",echo23)
  66. # p("~83293298383838383")
  67. r'''
  68. for en in dir(sock):
  69. print(".",en)
  70. for en in dir(app):
  71. print("~",en)
  72. '''
  73. # generated by bing seems to work
  74. @app.route("/ldir")
  75. def list_directory():
  76. # Get the list of files and directories
  77. # items = os.listdir(DIRECTORY_PATH)
  78. items = os.listdir("../js_client")
  79. # Filter out hidden files and directories
  80. items = [item for item in items if not item.startswith(".")]
  81. # Create an HTML string with the list of items as links
  82. html_content = "<h1>Contents of the Directory</h1><ul>"
  83. html_links = ""
  84. other_links = ""
  85. for item in items:
  86. p([item])
  87. if "html" in item:
  88. html_links += f"<li><a href='{item}'>{item}</a></li>"
  89. else:
  90. other_links += f"<li><a href='{item}'>{item}</a></li>"
  91. # link = (request.path + '/' if request.path != '/' else '') + item
  92. html_content+=html_links
  93. html_content+="<br>"
  94. html_content+=other_links
  95. html_content += "</ul>"
  96. # Return the HTML content directly
  97. return html_content
  98. # end generated by bing
  99. import inspect
  100. print("APP_ORIG",sock.route)
  101. print("APP_ORIG",app.route)
  102. print("APP_ORIG",inspect.getfile(app.route))
  103. print("APP_ORIG",app.url_map)
  104. if __name__ == '__main__':
  105. pass
  106. # socketio.run(app, debug=True)
  107. # app.run(debug=True,host='0.0.0.0')
  108. app.run(debug=True,host='0.0.0.0')
  109. # sock.run(app,host='0.0.0.0', debug=True,allow_unsafe_werkzeug=True)