def get_daum_cookie_by_selenium(notify=False): try: ret = {} ret['ret'] = False from .logic_selenium import SystemLogicSelenium if notify: data = { 'type': 'success', 'msg': u'<strong>사이트 접속중입니다.</strong>' } socketio.emit("notify", data, namespace='/framework', broadcast=True) SystemLogicSelenium.get_pagesoruce_by_selenium( 'https://www.daum.net', '//*[@id="daumFoot"]/div/a[1]/img') if notify: data = {'type': 'success', 'msg': u'쿠키 확인'} socketio.emit("notify", data, namespace='/framework', broadcast=True) driver = SystemLogicSelenium.get_driver() cookies = driver.get_cookies() for tmp in cookies: if tmp['name'] == 'TIARA': ret['ret'] = True ret['data'] = 'TIARA=%s' % tmp['value'] return ret except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return ret
def socketio_callback(cmd, data): if sid_list: running = "실행중" if Logic.is_running() else "실행중이 아닙니다." tmp = {'is_running': running, 'data': data} tmp = json.dumps(tmp, cls=AlchemyEncoder) tmp = json.loads(tmp) socketio.emit(cmd, tmp, namespace='/%s' % package_name, broadcast=True)
def func(): RcloneTool.do_action( ModelSetting.get('rclone_path'), ModelSetting.get('rclone_config_path'), mode, server_type, folder_id, folder_name, server_filename, remote_path, action, folder_id_encrypted=True) if mode == 'upload' and server_type == 'content': tmp = remote_path.split('/') tmp2 = tmp[-1].split('.') if tmp2[-1].lower() in [ 'mp4', 'mkv', 'avi', 'wmv', 'srt' ]: url = SERVER_URL + '/gd_share_server/noapi/av_sub/refresh?folder_name=%s' % folder_name else: #url = SERVER_URL + '/gd_share_server/noapi/av_sub/refresh?folder_name=%s' % tmp[-1] pass data = requests.get(url).json() msg = u'모두 완료되었습니다.\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True)
def gclone_execute(source, target): #./gclone --config ./gclone.conf copy gc:{1Qs6xsVJF7TkMk00s6W28HjdZ8onx2C4O} gc:{1BhTY6WLPRUkqKukNtQTIDMyjLO_UKMzP} --drive-server-side-across-configs -vvv --progress --tpslimit 3 --transfers 3 --stats 1s try: data = {'type': 'success', 'msg': u'Target:%s 작업을 시작합니다.' % target} socketio.emit("notify", data, namespace='/framework', broadcast=True) command = [ ModelSetting.get('gclone_path'), '--config', ModelSetting.get('gclone_config_path'), 'copy', source, target ] is_fclone = LogicGclone.is_fclone() # fclone의 경우 log-level 강제설정 if is_fclone: command += [ '--stats', '1s', '--log-level', 'NOTICE', '--stats-log-level', 'NOTICE' ] else: command += ModelSetting.get_list('gclone_fix_option', ' ') command += ModelSetting.get_list('gclone_user_option', ' ') logger.debug(command) if app.config['config']['is_py2']: LogicGclone.current_process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, bufsize=1) else: LogicGclone.current_process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) LogicGclone.current_data['command'] = ' '.join(command) LogicGclone.current_data['log'] = [] LogicGclone.current_data['files'] = [] LogicGclone.trans_callback('start') if is_fclone: LogicGclone.current_log_thread = threading.Thread( target=LogicGclone.fclone_log_thread_fuction, args=()) else: LogicGclone.current_log_thread = threading.Thread( target=LogicGclone.log_thread_fuction, args=()) LogicGclone.current_log_thread.start() logger.debug('normally process wait()') ret = LogicGclone.current_process.wait() LogicGclone.current_process = None return ret except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return 'fail'
def func(): ret = {'ret': False} page = 1 count = 0 while True: url = SERVER_URL + '/gd_share_server/noapi/av_sub/list?last_updated_time=%s&page=%s' % ( last_updated_time, page) logger.debug(url) data = requests.get(url).json() for item in data['list']: #logger.debug(item) ModelClientAVSubItem.insert(item) count += 1 #if data['paging']['next_page'] == 0 or data['paging']['current_page'] == data['paging']['last_page']: #logger.debug(data['paging']) if data['paging']['current_page'] >= data['paging'][ 'total_page']: break page += 1 ModelSetting.set( 'av_sub_last_updated_time', datetime.now().strftime('%Y-%m-%d %H:%M:%S')) ret['ret'] = True ret['data'] = count if action == 'all': data = { 'type': 'info', 'msg': u'%s개를 업데이트 했습니다.' % count, 'url': '' } socketio.emit("notify", data, namespace='/framework', broadcast=True) return ret
def func(): ret = RcloneTool.do_action(ModelSetting.get('rclone_path'), ModelSetting.get('rclone_config_path'), action, 'category', folder_id, folder_name, '', my_remote_path, 'real', folder_id_encrypted=True, listener=None) msg = u'Percent : %s\n' % ret['percent'] socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) #msg = u'폴더ID : %s\n' % ret['folder_id'] #socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) if ret['percent'] == 100: msg = u'업로드 크기 적용..\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) tmp = ModelSetting.get_int('size_upload') tmp += size ModelSetting.set('size_upload', str(tmp)) logger.debug('폴더ID:%s', ret['folder_id']) if board_type != 'share_private' and ret['folder_id'] != '': msg = u'게시물 등록중...\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) data = {'board_type' : board_type, 'category_type':category_type, 'board_title':board_title, 'board_content':board_content, 'board_daum_url' : board_daum_url, 'folder_name':folder_name, 'size':size, 'daum_info':daum_info, 'folder_id':ret['folder_id'], 'user_id':user_id, 'lsjson' : json.dumps(ret['lsjson'])} LogicUser.site_append(data) else: msg = u'업로드한 폴더ID값을 가져올 수 없어서 사이트 등록에 실패하였습니다.\n관리자에게 등록 요청하세요.\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) msg = u'모두 완료되었습니다.\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True)
def download_thread_function(url, download_path): try: #download_path = ModelSetting.get('qbittorrnet_normal_file_download_path') r = requests.get(url, allow_redirects=True) filename = LogicQbittorrent.get_filename_from_cd( r.headers.get('content-disposition')) if not os.path.exists(download_path): os.makedirs(download_path) filepath = os.path.join(download_path, filename) logger.debug('Direct download : %s', filepath) open(filepath, 'wb').write(r.content) data = {'type': 'success', 'msg': u'다운로드 성공<br>' + filepath} except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) data = { 'type': 'warning', 'msg': u'다운로드 실패<br>' + filepath, 'url': '/downloader/list' } try: logger.error('Exception:%s', e) except: pass #logger.error(traceback.format_exc()) finally: socketio.emit("notify", data, namespace='/framework', broadcast=True)
def run(self): logger.debug('WatchThread.. Start %s', self.package) if self.package is not None: logfile = os.path.join(path_data, 'log', '%s.log' % self.package) key = 'package' value = self.package else: logfile = os.path.join(path_data, 'log', self.filename) key = 'filename' value = self.filename if os.path.exists(logfile): with open(logfile, 'r') as f: f.seek(0, os.SEEK_END) while not self.stop_flag: line = f.readline() if not line: time.sleep(0.1) # Sleep briefly continue socketio.emit("add", { key: value, 'data': line }, namespace='/log', broadcast=True) logger.debug('WatchThread.. End %s', value) else: socketio.emit("add", { key: value, 'data': 'not exist logfile' }, namespace='/log', broadcast=True)
def thread_function(): ret = LogicNormal.make_xml_task.apply_async((call_from, )) #lock 이 걸림 result = ret.get() if show_msg: if result == True: data = { 'type': 'success', 'msg': u'%s EPG 생성이 완료되었습니다.' % call_from } socketio.emit("notify", data, namespace='/framework', broadcast=True) else: data = { 'type': 'warning', 'msg': u'%s EPG 생성이 실패하였습니다.<br>%s' % (call_from, result) } socketio.emit("notify", data, namespace='/framework', broadcast=True)
def socketio_callback(cmd, data, encoding=True): if sid_list: if encoding: data = json.dumps(data, cls=AlchemyEncoder) data = json.loads(data) #logger.debug(cmd) #logger.debug(data) socketio.emit(cmd, data, namespace='/%s/gclone' % package_name, broadcast=True)
def socketio_callback(data): if sid_list: tmp = json.dumps(data, cls=AlchemyEncoder) tmp = json.loads(tmp) socketio.emit('on_status', tmp, namespace='/%s_qbittorrent' % package_name, broadcast=True)
def socketio_callback(data): if sid_list: #logger.debug(data) tmp = json.dumps(data, cls=AlchemyEncoder) tmp = json.loads(tmp) socketio.emit('on_status', tmp, namespace='/%s_aria2' % package_name, broadcast=True)
def func(): count = 0 for tmp in data: add_ret = self.add(tmp) if add_ret.startswith('enqueue'): self.socketio_callback('list_refresh', '') count += 1 notify = {'type':'success', 'msg' : u'%s 개의 에피소드를 큐에 추가 하였습니다.' % count} socketio.emit("notify", notify, namespace='/framework', broadcast=True)
def func(): ret = RcloneTool.do_action(ModelSetting.get('rclone_path'), ModelSetting.get('rclone_config_path'), 'download', '', folder_id, folder_name, '', my_remote_path, 'real', folder_id_encrypted=True, listener=None) if ret['percent'] == 100: tmp = ModelSetting.get_int('size_download') tmp += size ModelSetting.set('size_download', str(tmp)) msg = u'모두 완료되었습니다.' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True)
def func(): LogicGclone.current_data['status'] = 'is_running' while True: count = 0 job_list = ModelSetting.get_list( 'gclone_queue_list', '\n') for job in job_list: try: if LogicGclone.current_data['user_stop']: break tmp = job.split('#')[0].split('|') if len(tmp) == 2: target = tmp[1].strip() target = target.replace( '{}', '{%s}' % ModelSetting.get( 'gclone_default_folderid')) if target.find('{}') != -1: continue if target.find(':') == -1: continue return_code = LogicGclone.gclone_execute( tmp[0].strip(), target) # 0 정상 logger.debug('return_code:%s', return_code) if return_code == 0: tmp2 = ModelSetting.get( 'gclone_queue_list') for t in tmp2.split('\n'): if t.strip().startswith( '%s|%s' % (tmp[0], tmp[1])): ModelSetting.set( 'gclone_queue_list', tmp2.replace(t, '')) socketio_callback( 'refresh_queue', ModelSetting.get( 'gclone_queue_list')) count += 1 except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) if LogicGclone.current_data['user_stop']: break if count == 0: break LogicGclone.current_data['status'] = 'ready' LogicGclone.current_data['user_stop'] = False data = {'type': 'success', 'msg': u'gclone 작업을 완료하였습니다.'} socketio.emit("notify", data, namespace='/framework', broadcast=True)
def thread_function(): if package is not None: logfile = os.path.join(path_data, 'log', '%s.log' % package) else: logfile = os.path.join(path_data, 'log', filename) if os.path.exists(logfile): ins_file = open(logfile, 'r', encoding='utf8') ## 3) line = ins_file.read() socketio.emit("on_start", {'data': line}, namespace='/log') logger.debug('on_start end') else: socketio.emit("on_start", {'data': 'not exist logfile'}, namespace='/log')
def send_queue_thread_function(): logger.debug('send_queue_thread_function START') while LogicNormal.command_queue: line = LogicNormal.command_queue.get() if line == '<END>': socketio.emit("end", None, namespace='/%s' % package_name, broadcast=True) break else: socketio.emit("add", line, namespace='/%s' % package_name, broadcast=True) LogicNormal.send_queue_thread = None LogicNormal.command_queue = None LogicNormal.foreground_process = None logger.debug('send_queue_thread_function END')
def func(): for i in range(1, 21): logger.debug('토렌트 다운로드 시도 : %s %s', i, folder_id) ret = RcloneTool.do_action(ModelSetting.get('rclone_path'), ModelSetting.get('rclone_config_path'), 'download', '', folder_id, '', '', my_remote_path, 'real', folder_id_encrypted=True, listener=None) logger.debug(ret) if ret['percent'] == 0: msg = u'아직 토렌트 파일을 받지 못했습니다. 30초 후 다시 시도합니다. (%s/20)' % i socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) time.sleep(30) else: msg = u'모두 완료되었습니다.' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) break logger.debug(msg)
def task_interface2(self): func = LogicPMDbCopyMake.start if app.config['config']['use_celery']: result = func.apply_async() ret = result.get() else: ret = func() msg = f"{ret}<br>파일 생성을 완료하였습니다." socketio.emit("modal", { 'title': 'DB 생성 완료', 'data': msg }, namespace='/framework', broadcast=True)
def func(): ret = RcloneTool2.do_user_upload(ModelSetting.get('rclone_path'), ModelSetting.get('rclone_config_path'), my_remote_path, folder_name, upload_folderid, board_type, category_type, is_move=(action=='move')) if ret['completed']: if board_type != 'share_private' and ret['folder_id'] != '': msg = u'6. 게시물 등록중...\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) data = {'board_type' : board_type, 'category_type':category_type, 'board_title':board_title, 'board_content':board_content, 'board_daum_url' : board_daum_url, 'folder_name':folder_name, 'size':ret['size'], 'daum_info':daum_info, 'folder_id':ret['folder_id'], 'user_id':user_id, 'lsjson' : json.dumps(ret['lsjson'])} self.site_append(data) else: msg = u'업로드한 폴더ID값을 가져올 수 없어서 사이트 등록에 실패하였습니다.\n관리자에게 등록 요청하세요.\n' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True) else: socketio.emit("command_modal_add_text", u'업로드가 완료되지 않아 게시글이 등록되지 않습니다.\n', namespace='/framework', broadcast=True) socketio.emit("command_modal_add_text", u'확인 후 다시 시도하세요.\n', namespace='/framework', broadcast=True) socketio.emit("command_modal_add_text", u'\n모두 완료되었습니다.\n', namespace='/framework', broadcast=True)
def output_emit(fd, room): try: max_read_bytes = 1024 * 20 while True: socketio.sleep(0.01) if select.select([fd], [], [], 0)[0]: output = os.read(fd, max_read_bytes).decode() socketio.emit('output', output, namespace=f'/{package_name}', room=room) except OSError as e: # 터미널 종료 pass except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def task(): try: logger.debug('[tv_schedule] start tv scheduler') service = None service = LibGdrive.sa_authorize(ModelSetting.get('gdrive_auth_path'), return_service=True) if service == None: data = {'type':'warning', 'msg':u'서비스계정 인증에 실패하여 스케쥴러를 실행할 수 없습니다.'} socketio.emit("notify", data, namespace='/framework', broadcate=True) logger.error('[tv_schdule]: failed to authorize sa accounts(%s)', ModelSetting.get('gdrive_auth_path')) entities = ModelTvMvItem.get_onair_entities_with_shortcut() count = len(entities) logger.debug('[tv_schedule] target onair item: %d', count) for entity in entities: children = LibGdrive.get_children(entity.folder_id, time_after=entity.updated_time, service=service) if children == None: logger.error('failed to get children files: skip!') continue logger.debug(u'[tv_schedule] title:{}, 에피소드 추가 내역: {}'.format(entity.title, u'없음' if len(children) == 0 else '{} 건'.format(len(children)))) if len(children) > 0: logger.debug('[tv_schedule] new episode found, send_scan(%s)', entity.title) fpath = os.path.join(entity.plex_path, children[0]['name']) LogicBase.PlexScannerQueue.put({'id':entity.id, 'agent_type':entity.agent_type, 'path':fpath, 'action':'REFRESH', 'now':datetime.now()}) if os.path.isfile(ModelSetting.get('rclone_bin_path')): from system.logic_command import SystemLogicCommand # /usr/bin/rclone rc vfs/refresh recursive=true --rc-addr 127.0.0.1:5572 _async=true rc_path = ScmUtil.get_rc_path(entity.plex_path) command = [ModelSetting.get('rclone_bin_path'), 'rc', 'vfs/refresh', '--rc-addr', ModelSetting.get('rclone_rc_addr'), 'dir='+rc_path, '_async=true'] logger.debug('[tv_schedule] rc vfs/refresh: %s', rc_path) data = SystemLogicCommand.execute_command_return(command) if data.find('jobid') == -1: data = {'type':'warning', 'msg':u'마운트 경로 갱신이 실패하였습니다.(mount rc확인필요)'} socketio.emit("notify", data, namespace='/framework', broadcate=True) logger.error('[tv_schdule]: failed to vfs/refresh(%s/%s)', ModelSetting.get('rclone_bin_path'), ModelSetting.get('rclone_rc_addr')) logger.debug('[tv_schedule] end tv scheduler') except Exception as e: logger.debug('Exception:%s', e) logger.debug(traceback.format_exc())
def start(self): try: if self.show_modal: if self.clear: socketio.emit("command_modal_clear", None, namespace='/framework', broadcast=True) self.thread = threading.Thread(target=self.execute_thread_function, args=()) self.thread.setDaemon(True) self.thread.start() if self.wait: time.sleep(1) self.thread.join() return self.return_log except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def send_to_ui_thread_function(): #logger.debug('send_queue_thread_function START') if self.show_modal: socketio.emit("command_modal_show", self.title, namespace='/framework', broadcast=True) while self.stdout_queue: line = self.stdout_queue.get() #logger.debug('Send to UI :%s', line) if line == '<END>': if self.show_modal: socketio.emit("command_modal_add_text", "\n", namespace='/framework', broadcast=True) break else: if self.show_modal: socketio.emit("command_modal_add_text", line, namespace='/framework', broadcast=True) self.send_to_ui_thread = None self.stdout_queue = None self.process = None
def func(): from system.logic_command2 import SystemLogicCommand2 return_log = SystemLogicCommand2(f"{module_name} 모듈 삭제", [ ['msg', u'잠시만 기다려주세요.'], ], wait=True, show_modal=True, clear=True).start() mod_data = self.find_module_from_total(module_name) if mod_data is None: socketio.emit("command_modal_add_text", f"{module_name} 정보 없음\n\n", namespace='/framework', broadcast=True) else: mod_root_path = ModelSetting.get(f'{name}_mod_root_path') mod_path = os.path.join(mod_root_path, module_name) if os.path.exists(mod_path): socketio.emit("command_modal_add_text", f"{mod_path} 폴더 삭제\n\n", namespace='/framework', broadcast=True) shutil.rmtree(mod_path) mod_order = ModelSetting.get_list(f"{name}_mod_order", ',') new = [] for tmp in mod_order: if module_name != tmp: new.append(tmp) ModelSetting.set(f"{name}_mod_order", ','.join(new)) return_log = SystemLogicCommand2(f"{module_name} 모듈 삭제", [ ['msg', '재시작 후 적용됩니다.'], ['msg', u'\n삭제 완료..'], ], wait=True, show_modal=True, clear=False).start()
def start(title, commands, clear=True, wait=False, show_modal=True): try: if show_modal: if clear: socketio.emit("command_modal_clear", None, namespace='/framework', broadcast=True) SystemLogicCommand.return_log = [] SystemLogicCommand.title = title SystemLogicCommand.commands = commands SystemLogicCommand.thread = threading.Thread( target=SystemLogicCommand.execute_thread_function, args=(show_modal, )) SystemLogicCommand.thread.setDaemon(True) SystemLogicCommand.thread.start() if wait: time.sleep(1) SystemLogicCommand.thread.join() return SystemLogicCommand.return_log except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def socketio_callback(cmd, data): if sid_list: tmp = json.dumps(data, cls=AlchemyEncoder) tmp = json.loads(tmp) socketio.emit(cmd, tmp , namespace='/%s' % package_name, broadcast=True)
def func(): ret = RcloneTool.do_action(ModelSetting.get('rclone_path'), ModelSetting.get('rclone_config_path'), 'download', '', folder_id, '', '', my_remote_path, 'real', folder_id_encrypted=True, listener=None) msg = u'모두 완료되었습니다.' socketio.emit("command_modal_add_text", str(msg), namespace='/framework', broadcast=True)
def task_interface2(self, command, *args): logger.warning(command) if command == 'size' or command == 'size_ret': func = Task.get_size elif command == 'backup': func = Task.backup elif command == 'clear' or command == 'clear_ret': func = Task.clear elif command == 'empty_episode_process': func = Task.empty_episode_process #ret = func(*args) if app.config['config']['use_celery']: result = func.apply_async(args) ret = result.get() else: ret = func(*args) if command == 'size': #noti_data = {'type':'info', 'msg' : f"경로 : {ret['target']}<br>크기 : {ret['sizeh']}"} #socketio.emit("notify", noti_data, namespace='/framework', broadcast=True) modal_data = { 'title': 'Size', 'data': f"경로 : {ret['target']}\n크기 : {ret['sizeh']}", } logger.debug(d(modal_data)) socketio.emit("modal", modal_data, namespace='/framework', broadcast=True) elif command == 'size_ret': return ret elif command == 'backup': if ret['ret'] == 'success': noti_data = { 'type': 'info', 'msg': f"경로 : {ret['target']}<br>복사하였습니다." } else: noti_data = { 'type': 'danger', 'msg': f"백업에 실패하였습니다.<br>{ret['log']}" } socketio.emit("notify", noti_data, namespace='/framework', broadcast=True) elif command == 'clear': noti_data = { 'type': 'info', 'msg': f"경로 : {ret['target']}<br>크기 : {ret['sizeh']}" } socketio.emit("notify", noti_data, namespace='/framework', broadcast=True) elif command == 'clear_ret': return ret elif command == 'empty_episode_process': noti_data = {'type': 'info', 'msg': f"썸네일 처리 완료"} return
def execute_thread_function(self): try: #if wait: if self.show_modal: socketio.emit("command_modal_show", self.title, namespace='/framework', broadcast=True) socketio.emit("loading_hide", None, namespace='/framework', broadcast=True) for command in self.commands: if command[0] == 'msg': if self.show_modal: socketio.emit("command_modal_add_text", '%s\n\n' % command[1], namespace='/framework', broadcast=True) elif command[0] == 'system': if self.show_modal: socketio.emit("command_modal_add_text", '$ %s\n\n' % command[1], namespace='/framework', broadcast=True) os.system(command[1]) else: show_command = True if command[0] == 'hide': show_command = False command = command[1:] #self.process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, bufsize=1) self.process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf8') self.start_communicate(command, show_command=show_command) self.send_queue_start() if self.process is not None: self.process.wait() time.sleep(1) except Exception as exception: if self.show_modal: socketio.emit("command_modal_show", self.title, namespace='/framework', broadcast=True) socketio.emit("command_modal_add_text", str(exception), namespace='/framework', broadcast=True) socketio.emit("command_modal_add_text", str(traceback.format_exc()), namespace='/framework', broadcast=True)