def custom_plugin_update(): try: if os.environ.get('UPDATE_STOP') == 'true': return if os.environ.get('PLUGIN_UPDATE_FROM_PYTHON') == 'false': return custom_path = os.path.join(path_data, 'custom') tmps = os.listdir(custom_path) for t in tmps: plugin_path = os.path.join(custom_path, t) try: if t == 'torrent_info': os.remove(os.path.join(plugin_path, 'info.json')) except: pass if t.startswith('_'): continue if os.path.exists(os.path.join(plugin_path, '.git')): command = [ 'git', '-C', plugin_path, 'reset', '--hard', 'HEAD' ] ret = Util.execute_command(command) command = ['git', '-C', plugin_path, 'pull'] ret = Util.execute_command(command) logger.debug("%s\n%s", plugin_path, ret) else: logger.debug(f"plugin_path is not git repo") except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def git_pull(): try: php_path = '/www/ivViewer' if os.path.exists(php_path): command = ['git', '-C', php_path, 'reset', '--hard', 'HEAD'] ret = Util.execute_command(command) command = ['git', '-C', php_path, 'pull'] ret = Util.execute_command(command) else: return os.system("chmod 777 -R %s" % php_path) return True except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return False
def kill(): try: command = ['/app/data/custom/launcher_ivViewer/files/kill.sh'] if not os.path.exists(command[0]): return Util.execute_command(command) if Logic.current_process is not None and Logic.current_process.poll( ) is None: import psutil process = psutil.Process(Logic.current_process.pid) for proc in process.children(recursive=True): proc.kill() process.kill() Logic.current_process = None except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def get_binary(): try: import framework.common.util as CommonUtil bin_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bin') ret = '' import platform if CommonUtil.is_termux( ) and platform.platform().find('arch') != -1: ret = os.path.join(bin_path, 'termux', 'aria2c') elif CommonUtil.is_windows(): ret = os.path.join(bin_path, 'Windows', 'aria2c.exe') elif CommonUtil.is_mac(): ret = os.path.join(bin_path, 'Darwin', 'aria2c') elif CommonUtil.is_docker() or CommonUtil.is_linux(): command = ['which', 'aria2c'] log = Util.execute_command(command) if log: ret = log[0].strip() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return ret
def plugin_install_by_api(plugin_git, zip_url, zip_filename): logger.debug('plugin_git : %s', plugin_git) logger.debug('zip_url : %s', zip_url) logger.debug('zip_filename : %s', zip_filename) is_git = True if plugin_git != None and plugin_git != '' else False ret = {} try: if is_git: name = plugin_git.split('/')[-1] else: name = zip_filename.split('.')[0] custom_path = os.path.join(path_data, 'custom') plugin_path = os.path.join(custom_path, name) logger.debug(plugin_path) plugin_info = None if os.path.exists(plugin_path): ret['ret'] = 'already_exist' ret['log'] = '이미 설치되어 있습니다.' else: if plugin_git and plugin_git.startswith('http'): for tag in ['main', 'master']: try: info_url = plugin_git.replace( 'github.com', 'raw.githubusercontent.com' ) + '/%s/info.json' % tag plugin_info = requests.get(info_url).json() if plugin_info is not None: break except: pass if zip_filename and zip_filename != '': import zipfile from tool_base import ToolBaseFile zip_filepath = os.path.join(path_data, 'tmp', zip_filename) extract_filepath = os.path.join(path_data, 'tmp', name) logger.error(zip_url) logger.warning(zip_filepath) if ToolBaseFile.download(zip_url, zip_filepath): #logger.warning(os.path.exists(zip_filepath)) with zipfile.ZipFile(zip_filepath, 'r') as zip_ref: zip_ref.extractall(extract_filepath) plugin_info_filepath = os.path.join( extract_filepath, 'info.json') if os.path.exists(plugin_info_filepath): plugin_info = ToolBaseFile.read_json( plugin_info_filepath) if plugin_info == None: plugin_info = {} flag = True if 'platform' in plugin_info: if platform.system() not in plugin_info['platform']: ret['ret'] = 'not_support_os' ret['log'] = '설치 가능한 OS가 아닙니다.' flag = False if flag and 'running_type' in plugin_info: if app.config['config']['running_type'] not in plugin_info[ 'running_type']: ret['ret'] = 'not_support_running_type' ret['log'] = '설치 가능한 실행타입이 아닙니다.' flag = False if flag and 'policy_level' in plugin_info: if plugin_info['policy_level'] > app.config['config'][ 'level']: ret['ret'] = 'policy_level' ret['log'] = '설치 가능 회원등급보다 낮습니다.' flag = False if flag and 'policy_point' in plugin_info: if plugin_info['policy_level'] > app.config['config'][ 'point']: ret['ret'] = 'policy_level' ret['log'] = '설치 가능 포인트보다 낮습니다.' flag = False if flag: if plugin_git and plugin_git.startswith('http'): command = [ 'git', '-C', custom_path, 'clone', plugin_git + '.git', '--depth', '1' ] log = Util.execute_command(command) if zip_filename and zip_filename != '': import shutil if os.path.exists(plugin_path) == False: shutil.move(extract_filepath, plugin_path) else: for tmp in os.listdir(extract_filepath): shutil.move( os.path.join(extract_filepath, tmp), plugin_path) log = '' logger.debug(plugin_info) # 2021-12-31 if 'dependency' in plugin_info: for dep in plugin_info['dependency']: for key, value in LogicPlugin.get_plugin_list( ).items(): if key == dep['name']: logger.debug( f"Dependency 설치 - 이미 설치됨 : {dep['name']}" ) break else: logger.debug(f"Dependency 설치 : {dep['home']}") LogicPlugin.plugin_install_by_api( dep['home'], dep.get('zip_url'), dep.get('zip_filename')) #command = ['git', '-C', custom_path, 'clone', dep['home'], '--depth', '1'] #ret = Util.execute_command(command) ret['ret'] = 'success' ret['log'] = [u'정상적으로 설치하였습니다. 재시작시 적용됩니다.', log] ret['log'] = '<br>'.join(ret['log']) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) ret['ret'] = 'exception' ret['log'] = str(exception) return ret