server_now_update.py 2.2 KB

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