server_now_update.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from .tool.func import *
  2. def server_now_update_2(conn):
  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('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. if platform.system() == 'Linux':
  17. ok = []
  18. ok += [os.system('git remote rm origin')]
  19. ok += [os.system('git remote add origin https://github.com/2DU/opennamu.git')]
  20. ok += [os.system('git fetch origin ' + up_data)]
  21. ok += [os.system('git reset --hard origin/' + up_data)]
  22. if (ok[0] and ok[1] and ok[2] and ok[3]) == 0:
  23. return redirect('/restart')
  24. else:
  25. print('Update error')
  26. elif platform.system() == 'Windows':
  27. urllib.request.urlretrieve('https://github.com/2DU/opennamu/archive/' + up_data + '.zip', 'update.zip')
  28. zipfile.ZipFile('update.zip').extractall('')
  29. ok = os.system('xcopy /y /r opennamu-' + up_data + ' .')
  30. if ok == 0:
  31. os.system('rd /s /q opennamu-' + up_data)
  32. os.system('del update.zip')
  33. return redirect('/restart')
  34. else:
  35. print('Update error')
  36. return easy_minify(flask.render_template(skin_check(),
  37. imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
  38. data = load_lang("update_error") + ' <a href="https://github.com/2DU/opennamu">(Github)</a>',
  39. menu = [['manager/1', load_lang('return')]]
  40. ))
  41. else:
  42. return easy_minify(flask.render_template(skin_check(),
  43. imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
  44. data = '''
  45. ''' + load_lang('update_warring') + '''
  46. <hr class=\"main_hr\">
  47. <a href="https://github.com/2du/openNAMU/blob/master/app.py">(Master)</a> <a href="https://github.com/2du/openNAMU/blob/stable/app.py">(Stable)</a>
  48. <hr class=\"main_hr\">
  49. <form method="post">
  50. <button type="submit">''' + load_lang('update') + '''</button>
  51. </form>
  52. ''',
  53. menu = [['manager', load_lang('return')]]
  54. ))