main_sys_update.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import zipfile
  2. import urllib.request
  3. from .tool.func import *
  4. def main_sys_update():
  5. with get_db_connect() as conn:
  6. curs = conn.cursor()
  7. if admin_check() != 1:
  8. return re_error('/error/3')
  9. if flask.request.method == 'POST':
  10. admin_check(None, 'update')
  11. curs.execute(db_change('select data from other where name = "update"'))
  12. up_data = curs.fetchall()
  13. up_data = up_data[0][0] if up_data and up_data[0][0] in ['stable', 'beta', 'dev'] else 'stable'
  14. print('Update')
  15. if platform.system() == 'Linux':
  16. ok = []
  17. ok += [os.system('git remote rm origin')]
  18. ok += [os.system('git remote add origin https://github.com/opennamu/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. print('Error : update failed')
  25. elif platform.system() == 'Windows':
  26. os.system('rd /s /q route')
  27. urllib.request.urlretrieve('https://github.com/opennamu/opennamu/archive/' + up_data + '.zip', 'update.zip')
  28. zipfile.ZipFile('update.zip').extractall('')
  29. ok = os.system('xcopy /y /s /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('Error : update failed')
  36. return re_error('/error/34')
  37. else:
  38. return easy_minify(flask.render_template(skin_check(),
  39. imp = [load_lang('update'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  40. data = load_lang('update_warning') + '''
  41. <hr class="main_hr">
  42. <ul class="opennamu_ul">
  43. <li id="ver_send_2">''' + load_lang('version') + ''' : </li>
  44. <li id="ver_send">''' + load_lang('lastest') + ''' : </li>
  45. </ul>
  46. <a href="https://github.com/openNAMU/openNAMU">(Beta)</a> <a href="https://github.com/openNAMU/openNAMU/tree/stable">(Stable)</a>
  47. <hr class="main_hr">
  48. <form method="post">
  49. <button type="submit">''' + load_lang('update') + '''</button>
  50. </form>
  51. <!-- JS : opennamu_do_insert_version -->
  52. ''',
  53. menu = [['manager', load_lang('return')]]
  54. ))