Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. p("?????")
  32. # p("?????")
  33. return flask.send_file('../js_client/jquery-3.5.1.min.js')
  34. @app.route('/viewsrc2/<path:path>')
  35. def view_src2(path):
  36. p(">>>>>>>>>>>>>>>>>>>>????????",path)
  37. # return flask.send_from_directory('templates', path)
  38. # open()
  39. with open(r"../js_client/" + path, "r") as file:
  40. ftxt = file.read()
  41. # r["is_template"] = is_template_ftxt(ftxt)
  42. # ret= flask.send_from_directory(r"../js_client", path)
  43. # p("view_src",type(ret),ret)
  44. return "<plaintext>" + ftxt + "</plaintext>"
  45. return "<xmp>" + ftxt + "</xmp>"
  46. return "<code>" + ftxt + "</code>"
  47. return "<pre><code>" + ftxt + "</code></pre>"
  48. @app.route('/<path:path>')
  49. def send_report(path):
  50. p("????,...",path)
  51. # return flask.send_from_directory('templates', path)
  52. return flask.send_from_directory(r"../js_client", path)
  53. return flask.send_from_directory('./', path)
  54. # '''
  55. @app.route('/viewsrc/<path:path>')
  56. def view_src(path):
  57. p(">>>>>>>>>>>>>>>>>>>>????????")
  58. # return flask.send_from_directory('templates', path)
  59. ret= flask.send_from_directory(r"../js_client", path)
  60. p("view_src",ret)
  61. return ret
  62. @sock.route('/echo')
  63. def echo(sock):
  64. while True:
  65. data = sock.receive()
  66. sock.send(data)
  67. @sock.route('/echo_all')
  68. def echo_all(sock):
  69. gmod.gx.add_to_channel(sock,"echo_all")
  70. # send_to_channel("echo_all",msg,"sender")
  71. while True:
  72. data = sock.receive()
  73. # ws.send(data)
  74. gmod.gx.send_to_channel("echo_all",data,"sender")
  75. # @sock.route('/echo_c1')
  76. # def echo_coll(sock):
  77. # p("echo_coll app")
  78. # while True:
  79. # data = sock.receive()
  80. # sock.send(data)
  81. # @sock.route('/<path:path>')
  82. # def echo23(sock,*a,**kw):
  83. # p("E2",a,kw)
  84. # while True:
  85. # data = sock.receive()
  86. # sock.send(data)
  87. # for en in dir(sock):
  88. # p(en)
  89. # p("echo23",echo23)
  90. # p("~83293298383838383")
  91. r'''
  92. for en in dir(sock):
  93. print(".",en)
  94. for en in dir(app):
  95. print("~",en)
  96. '''
  97. # import inspect
  98. # p(inspect.getsource(app.route))
  99. # generated by bing seems to work
  100. @app.route("/ldir")
  101. def list_directory():
  102. orig_path = os.getcwd()
  103. # Get the list of files and directories
  104. # items = os.listdir(DIRECTORY_PATH)
  105. os.chdir(app.root_path)
  106. items = os.listdir("../js_client")
  107. os.chdir(orig_path)
  108. # Filter out hidden files and directories
  109. items = [item for item in items if not item.startswith(".")]
  110. # Create an HTML string with the list of items as links
  111. html_content = "<h1>Contents of the Directory</h1><ul>"
  112. html_links = ""
  113. html_src_links = ""
  114. other_links = ""
  115. for item in items:
  116. p([item])
  117. if "html" in item:
  118. html_src_links += f"<li><a href='viewsrc2/{item}'>src:{item}</a></li>"
  119. html_links += f"<li><a href='{item}'>{item}</a></li>"
  120. else:
  121. other_links += f"<li><a href='{item}'>{item}</a></li>"
  122. # link = (request.path + '/' if request.path != '/' else '') + item
  123. html_content+=html_links
  124. html_content+="<br>"
  125. html_content+=other_links
  126. html_content+="<br>"
  127. html_content+="VIEW SRC: its actually < pre >"
  128. html_content+="<br>"
  129. html_content+="<br>"
  130. html_content+=html_src_links
  131. html_content += "</ul>"
  132. # Return the HTML content directly
  133. return html_content
  134. # end generated by bing
  135. import inspect
  136. r'''
  137. print("APP_ORIG",sock.route)
  138. print("APP_ORIG",app.route)
  139. print("APP_ORIG",inspect.getfile(app.route))
  140. print("APP_ORIG",app.url_map)
  141. # '''
  142. if __name__ == '__main__':
  143. pass
  144. # socketio.run(app, debug=True)
  145. # app.run(debug=True,host='0.0.0.0')
  146. app.run(debug=True,host='0.0.0.0',port="5000")
  147. # app.run(debug=True,host='0.0.0.0',port="5001")
  148. # sock.run(app,host='0.0.0.0', debug=True,allow_unsafe_werkzeug=True)