server_now_update.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from .tool.func import *
  2. def server_now_update_2(conn, r_ver):
  3. curs = conn.cursor()
  4. if admin_check() != 1:
  5. return re_error('/error/3')
  6. if flask.request.method == 'POST':
  7. admin_check(None, 'update')
  8. curs.execute(db_change('select data from other where name = "update"'))
  9. up_data = curs.fetchall()
  10. if up_data:
  11. up_data = up_data[0][0]
  12. else:
  13. up_data = 'stable'
  14. print('----')
  15. print('Update')
  16. print('----')
  17. if platform.system() == 'Linux':
  18. ok = []
  19. ok += [os.system('git remote rm origin')]
  20. ok += [os.system('git remote add origin https://github.com/2DU/opennamu.git')]
  21. ok += [os.system('git fetch origin ' + up_data)]
  22. ok += [os.system('git reset --hard origin/' + up_data)]
  23. if (ok[0] and ok[1] and ok[2] and ok[3]) == 0:
  24. return redirect('/restart')
  25. else:
  26. print('Error : update failed')
  27. elif platform.system() == 'Windows':
  28. os.system('rd /s /q route')
  29. urllib.request.urlretrieve('https://github.com/2DU/opennamu/archive/' + up_data + '.zip', 'update.zip')
  30. zipfile.ZipFile('update.zip').extractall('')
  31. ok = os.system('xcopy /y /s /r opennamu-' + up_data + ' .')
  32. if ok == 0:
  33. os.system('rd /s /q opennamu-' + up_data)
  34. os.system('del update.zip')
  35. return redirect('/restart')
  36. else:
  37. print('Error : update failed')
  38. return re_error('/error/34')
  39. else:
  40. return easy_minify(flask.render_template(skin_check(),
  41. imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
  42. data = load_lang('update_warring') + '''
  43. <hr class=\"main_hr\">
  44. <ul>
  45. <li>''' + load_lang('version') + ' : ' + r_ver + '''</li>
  46. <li id="ver_send" style="display: none;">''' + load_lang('lastest') + ''' : </li>
  47. </ul>
  48. <a href="https://github.com/2du/openNAMU">(Master)</a> <a href="https://github.com/2du/openNAMU/tree/stable">(Stable)</a>
  49. <hr class=\"main_hr\">
  50. <form method="post">
  51. <button type="submit">''' + load_lang('update') + '''</button>
  52. </form>
  53. <script>load_ver();</script>
  54. ''',
  55. menu = [['manager', load_lang('return')]]
  56. ))