now_update.py 2.1 KB

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