2
0

main_sys_update.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(conn) != 1:
  8. return re_error(conn, '/error/3')
  9. if flask.request.method == 'POST':
  10. admin_check(conn, 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', 'dont_use'] 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 --depth=1 origin ' + up_data)]
  20. ok += [os.system('git reset --hard origin/' + up_data)]
  21. for for_a in ok[1:]:
  22. if for_a != 0:
  23. break
  24. else:
  25. return redirect(conn, '/restart')
  26. print('Error : update failed')
  27. elif platform.system() == 'Windows':
  28. os.system('rd /s /q route')
  29. urllib.request.urlretrieve('https://github.com/opennamu/opennamu/archive/' + up_data + '.zip', 'update.zip')
  30. zipfile.ZipFile('update.zip').extractall('')
  31. ok = os.system('xcopy /y /s /r opennamu-' + up_data + ' .')
  32. if ok == 0:
  33. os.system('rd /s /q opennamu-' + up_data)
  34. os.system('del update.zip')
  35. return redirect(conn, '/restart')
  36. print('Error : update failed')
  37. return re_error(conn, '/error/34')
  38. else:
  39. return easy_minify(conn, flask.render_template(skin_check(conn),
  40. imp = [get_lang(conn, 'update'), wiki_set(conn), wiki_custom(conn), wiki_css([0, 0])],
  41. data = get_lang(conn, 'update_warning') + '''
  42. <hr class="main_hr">
  43. <ul class="opennamu_ul">
  44. <li id="ver_send_2">''' + get_lang(conn, 'version') + ''' : </li>
  45. <li id="ver_send">''' + get_lang(conn, 'lastest') + ''' : </li>
  46. </ul>
  47. <a href="https://github.com/openNAMU/openNAMU">(Beta)</a> <a href="https://github.com/openNAMU/openNAMU/tree/stable">(Stable)</a>
  48. <hr class="main_hr">
  49. <form method="post">
  50. <button type="submit">''' + get_lang(conn, 'update') + '''</button>
  51. </form>
  52. <!-- JS : opennamu_do_insert_version -->
  53. ''',
  54. menu = [['manager', get_lang(conn, 'return')]]
  55. ))