main_sys_update.py 3.0 KB

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