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(): 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 get_user_copy_dest(category): try: if ModelSetting.get_bool('use_user_setting'): rule_list = ModelSetting.get_list('user_copy_dest_rules', '\n') for rule in rule_list: orig, converted = rule.split('|') if orig.endswith('*'): orig = orig.replace('*', '') logger.debug('orig(%s), category(%s)', orig, category) if category.startswith(orig): return converted return category except Exception as e: logger.error('Exception %s', e) logger.error(traceback.format_exc()) return None
def scheduled_copy(sheet_id): try: wsentity = WSModelItem.get(sheet_id) wsentity.is_running = True wsentity.save() # COPY items succeed = 0 failed = 0 copy_mode = ModelSetting.get_int('copy_mode') if copy_mode == 0: return # keyword rule 적용: 미사용-너무느림 #rules = ModelSetting.get_list('keyword_rules', '|') if copy_mode == 1 else ModelSetting.get_list('except_keyword_rules', '|') # TODO:Plex 연동저건에 따른 처리: 0 연동안함, 1: 있으면 skip, 2: 용량크면복사 #plex_condition = ModelSetting.get_int('plex_condition') for entity in ListModelItem.get_schedule_target_items(sheet_id): # keyword rule 적용: 파일타입의 경우만 if entity.mimetype == 1: rules = ModelSetting.get_list( 'keyword_rules', '|') if copy_mode == 1 else ModelSetting.get_list( 'except_keyword_rules', '|') copy_flag = True for rule in rules: copy_flag = False if copy_mode == 1 else True if entity.title.find(rule) != -1: copy_flag = not copy_flag logger.debug( 'keyword(%s) is matched, copy_flag(%s)', rule, copy_flag) break if not copy_flag: continue if entity.copy_count > 1: continue # keyword rule 적용: 미사용-너무느림 """ from gd_share_client.model import ModelSetting as gscModelSetting remote_path = 'gc:{%s}' % entity.folder_id ret = RcloneTool.lsjson(gscModelSetting.get('rclone_path'), gscModelSetting.get('rclone_config_path'), remote_path) if len(ret) == 0: continue for f in ret: mtype = f['MimeType'] if not mtype.startswith('video/'): continue fname = f['Name'] # copy_mode: 1-whitelist, 2-blacklist for rule in rules: copy_flag = False if copy_mode == 1 else True if fname.find(rule) != -1: copy_flag = not copy_flag logger.debug('keyword(%s) is matched, copy_flag(%s)', rule, copy_flag) break if not copy_flag: continue """ # TODO: Plex 연동 조건에 따른 복사 처리: 20.09.10 #if not LogicGSeet.check_plex_condition(entity): #continue logger.info( 'copy target: %s, %s, %s, %s', entity.title2 if entity.title2 != u"" else entity.title, entity.folder_id, entity.category, entity.str_size) ret = LogicGSheet.gclone_copy(entity.id) logger.info(ret['data']) if ret['ret']: succeed += 1 else: failed += 1 total = succeed + failed logger.info('scheduled_copy: total(%d), succeed(%d), failed(%d)', total, succeed, failed) ret = { 'ret': True, 'data': 'copy result: total({total}), succeed({succeed}), failed({failed})' .format(total=total, succeed=succeed, failed=failed) } except Exception as e: logger.error('Exception %s', e) logger.error(traceback.format_exc()) ret = {'ret': False, 'data': 'Exception'} finally: wsentity.is_running = False wsentity.save() return ret