2
0

main_sys_update.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import zipfile
  2. import urllib.request
  3. from .tool.func import *
  4. from .main_sys_restart import main_sys_restart_do
  5. async def main_sys_update(golang_process):
  6. with get_db_connect() as conn:
  7. curs = conn.cursor()
  8. if await acl_check('', 'owner_auth', '', '') == 1:
  9. return await re_error(conn, 3)
  10. if flask.request.method == 'POST':
  11. await acl_check(tool = 'owner_auth', memo = 'update')
  12. curs.execute(db_change('select data from other where name = "update"'))
  13. up_data = curs.fetchall()
  14. up_data = up_data[0][0] if up_data and up_data[0][0] in ['stable', 'beta', 'dev', 'dont_use'] else 'stable'
  15. print('Update')
  16. if golang_process.poll() is None:
  17. golang_process.terminate()
  18. try:
  19. golang_process.wait(timeout = 5)
  20. except subprocess.TimeoutExpired:
  21. golang_process.kill()
  22. if platform.system() == 'Linux' or platform.system() == 'Darwin':
  23. ok = []
  24. ok += [os.system('git remote rm origin')]
  25. ok += [os.system('git remote add origin https://github.com/opennamu/opennamu.git')]
  26. ok += [os.system('git fetch --depth=1 origin ' + up_data)]
  27. ok += [os.system('git reset --hard origin/' + up_data)]
  28. for for_a in ok[1:]:
  29. if for_a != 0:
  30. break
  31. else:
  32. linux_exe_chmod()
  33. threading.Thread(target = main_sys_restart_do).start()
  34. return flask.Response(get_lang(conn, "warning_restart"), status = 200)
  35. print('Error : update failed')
  36. elif platform.system() == 'Windows':
  37. os.system('rd /s /q route')
  38. urllib.request.urlretrieve('https://github.com/opennamu/opennamu/archive/' + up_data + '.zip', 'update.zip')
  39. zipfile.ZipFile('update.zip').extractall('')
  40. ok = os.system('xcopy /y /s /r opennamu-' + up_data + ' .')
  41. if ok == 0:
  42. os.system('rd /s /q opennamu-' + up_data)
  43. os.system('del update.zip')
  44. threading.Thread(target = main_sys_restart_do).start()
  45. return flask.Response(get_lang(conn, "warning_restart"), status = 200)
  46. print('Error : update failed')
  47. return await re_error(conn, 34)
  48. else:
  49. return easy_minify(conn, flask.render_template(skin_check(conn),
  50. imp = [get_lang(conn, 'update'), wiki_set(conn), await wiki_custom(conn), wiki_css([0, 0])],
  51. data = get_lang(conn, 'update_warning') + '''
  52. <hr class="main_hr">
  53. <ul>
  54. <li id="ver_send_2">''' + get_lang(conn, 'version') + ''' : </li>
  55. <li id="ver_send">''' + get_lang(conn, 'lastest') + ''' : </li>
  56. </ul>
  57. <a href="https://github.com/openNAMU/openNAMU">(Beta)</a> <a href="https://github.com/openNAMU/openNAMU/tree/stable">(Stable)</a>
  58. <hr class="main_hr">
  59. <form method="post">
  60. <button type="submit">''' + get_lang(conn, 'update') + '''</button>
  61. </form>
  62. <!-- JS : opennamu_do_insert_version -->
  63. ''',
  64. menu = [['manager', get_lang(conn, 'return')]]
  65. ))