main_update.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from .tool.func import *
  2. def main_update_2(conn, r_ver):
  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(db_change('select data from other where name = "update"'))
  9. up_data = curs.fetchall()
  10. up_data = up_data[0][0] if up_data and up_data[0][0] in ['stable', 'beta', 'dev'] else 'stable'
  11. print('----')
  12. print('Update')
  13. print('----')
  14. if platform.system() == 'Linux':
  15. ok = []
  16. ok += [os.system('git remote rm origin')]
  17. ok += [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] and ok[1] and ok[2] and ok[3]) == 0:
  21. return redirect('/restart')
  22. else:
  23. print('Error : update failed')
  24. elif platform.system() == 'Windows':
  25. os.system('rd /s /q route')
  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 /s /r opennamu-' + up_data + ' .')
  29. if ok == 0:
  30. os.system('rd /s /q opennamu-' + up_data)
  31. os.system('del update.zip')
  32. return redirect('/restart')
  33. else:
  34. print('Error : update failed')
  35. return re_error('/error/34')
  36. else:
  37. return easy_minify(flask.render_template(skin_check(),
  38. imp = [load_lang('update'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  39. data = load_lang('update_warning') + '''
  40. <hr class=\"main_hr\">
  41. <ul class="inside_ul">
  42. <li>''' + load_lang('version') + ' : ' + r_ver + '''</li>
  43. <li id="ver_send" style="display: none;">''' + load_lang('lastest') + ''' : </li>
  44. </ul>
  45. <a href="https://github.com/2du/openNAMU">(Beta)</a> <a href="https://github.com/2du/openNAMU/tree/stable">(Stable)</a>
  46. <hr class=\"main_hr\">
  47. <form method="post">
  48. <button type="submit">''' + load_lang('update') + '''</button>
  49. </form>
  50. <script>load_ver();</script>
  51. ''',
  52. menu = [['manager', load_lang('return')]]
  53. ))