| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import zipfile
- import urllib.request
- from .tool.func import *
- from .main_sys_restart import main_sys_restart_do
- async def main_sys_update(golang_process):
- with get_db_connect() as conn:
- curs = conn.cursor()
- if await acl_check('', 'owner_auth', '', '') == 1:
- return await re_error(conn, 3)
- if flask.request.method == 'POST':
- await acl_check(tool = 'owner_auth', memo = 'update')
- curs.execute(db_change('select data from other where name = "update"'))
- up_data = curs.fetchall()
- up_data = up_data[0][0] if up_data and up_data[0][0] in ['stable', 'beta', 'dev', 'dont_use'] else 'stable'
- print('Update')
-
- if golang_process.poll() is None:
- golang_process.terminate()
- try:
- golang_process.wait(timeout = 5)
- except subprocess.TimeoutExpired:
- golang_process.kill()
- try:
- golang_process.wait(timeout = 5)
- except subprocess.TimeoutExpired:
- print('Golang process not terminated properly.')
-
- if platform.system() == 'Linux' or platform.system() == 'Darwin':
- ok = []
- ok += [os.system('git remote rm origin')]
- ok += [os.system('git remote add origin https://github.com/opennamu/opennamu.git')]
- ok += [os.system('git fetch --depth=1 origin ' + up_data)]
- ok += [os.system('git reset --hard origin/' + up_data)]
- for for_a in ok[1:]:
- if for_a != 0:
- break
- else:
- linux_exe_chmod()
- threading.Thread(target = main_sys_restart_do).start()
- return flask.Response(await get_lang("warning_restart"), status = 200)
-
- print('Error : update failed')
- elif platform.system() == 'Windows':
- os.system('rd /s /q route')
- urllib.request.urlretrieve('https://github.com/opennamu/opennamu/archive/' + up_data + '.zip', 'update.zip')
-
- zipfile.ZipFile('update.zip').extractall('')
-
- ok = os.system('xcopy /y /s /r opennamu-' + up_data + ' .')
- if ok == 0:
- os.system('rd /s /q opennamu-' + up_data)
- os.system('del update.zip')
-
- threading.Thread(target = main_sys_restart_do).start()
- return flask.Response(await get_lang("warning_restart"), status = 200)
-
- print('Error : update failed')
- return await re_error(conn, 34)
- else:
- return await render_template(
- await get_lang('update'),
- await get_lang('update_warning') + '''
- <hr class="main_hr">
- <ul>
- <li id="ver_send_2">''' + await get_lang('version') + ''' : </li>
- <li id="ver_send">''' + await get_lang('lastest') + ''' : </li>
- </ul>
- <a href="https://github.com/openNAMU/openNAMU">(Beta)</a> <a href="https://github.com/openNAMU/openNAMU/tree/stable">(Stable)</a>
- <hr class="main_hr">
- <form method="post">
- <button type="submit">''' + await get_lang('update') + '''</button>
- </form>
- <!-- JS : opennamu_do_insert_version -->
- ''',
- 0,
- [['manager', await get_lang('return')]]
- )
|