now_update.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from .tool.func import *
  2. def now_update_2(conn):
  3. curs = conn.cursor()
  4. if admin_check(None, 'update') != 1:
  5. return re_error('/error/3')
  6. curs.execute('select data from other where name = "update"')
  7. up_data = curs.fetchall()
  8. if up_data:
  9. up_data = up_data[0][0]
  10. else:
  11. up_data = 'stable'
  12. if platform.system() == 'Linux':
  13. print('Update')
  14. os.system('git remote rm origin')
  15. os.system('git remote add origin https://github.com/2DU/opennamu.git')
  16. ok = os.system('git fetch origin ' + up_data)
  17. ok = os.system('git reset --hard origin/' + up_data)
  18. if ok == 0:
  19. return redirect('/restart')
  20. else:
  21. if platform.system() == 'Windows':
  22. print('Update')
  23. urllib.request.urlretrieve('https://github.com/2DU/opennamu/archive/' + up_data + '.zip', 'update.zip')
  24. zipfile.ZipFile('update.zip').extractall('')
  25. ok = os.system('xcopy /y /r opennamu-' + up_data + ' .')
  26. if ok == 0:
  27. print('Remove')
  28. os.system('rd /s /q opennamu-' + up_data)
  29. os.system('del update.zip')
  30. return redirect('/restart')
  31. return easy_minify(flask.render_template(skin_check(),
  32. imp = [load_lang('update'), wiki_set(), custom(), other2([0, 0])],
  33. data = load_lang("update_error") + ' <a href="https://github.com/2DU/opennamu">(Github)</a>',
  34. menu = [['manager/1', load_lang('return')]]
  35. ))