Example #1
0
def disconnect():
    try:
        LogViewer.instance().disconnect(request.sid)
        logger.debug('disconnect sid:%s', request.sid)
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Example #2
0
    def copy_section(cls, source_file, target_file, section_name):
        try:
            if os.path.exists(source_file) == False:
                return 'not_exist_source_file'
            if os.path.exists(target_file) == False:
                return 'not_exist_target_file'
            lines = ToolBaseFile.read(source_file).split('\n')
            section = {}
            current_section_name = None
            current_section_data = None

            for line in lines:
                line = line.strip()
                if line.startswith('# SECTION START : '):
                    current_section_name = line.split(':')[1].strip()
                    current_section_data = []
                if current_section_data is not None:
                    current_section_data.append(line)
                if line.startswith('# SECTION END'):
                    section[current_section_name] = current_section_data
                    current_section_name = current_section_data = None

            if section_name not in section:
                return 'not_include_section'
            
            data = '\n'.join(section[section_name])
            source_data = ToolBaseFile.read(target_file)
            source_data = source_data + f"\n{data}\n"
            ToolBaseFile.write(source_data, target_file)
            return 'success'
        except Exception as exception: 
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
            return 'exception'
Example #3
0
def is_linux():
    try:
        #return (app.config['config']['running_type'] == 'native' and platform.system() == 'Linux')
        return (platform.system() == 'Linux')
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Example #4
0
    def search_imdb(title, year):
        try:
            year = int(year)
            title = title.replace(' ', '_')
            url = 'https://v2.sg.media-imdb.com/suggestion/%s/%s.json' % (
                title[0], title)
            tmp = requests.get(url).json()
            if 'd' in tmp:
                for t in tmp['d']:
                    title_imdb = t['l'].lower().replace("'", '').replace(
                        ':', '').replace('&', 'and').replace('?', '')
                    if title.lower().replace("'", '').replace(
                            '.', ' ').replace(
                                '_', ' '
                            ) == title_imdb and 'y' in t and t['y'] == year:
                        return {
                            'id': t['id'],
                            'title': t['l'],
                            'year': year,
                            'score': 100
                        }

        except Exception as e:
            logger.error('Exception:%s', e)
            logger.error(traceback.format_exc())
Example #5
0
    def check_filename(filename):
        logger.debug('check_filename filename : %s', filename)
        try:
            ret = None
            match1 = re.compile(_REGEX_FILENAME).match(filename)
            match2 = re.compile(_REGEX_FILENAME_NO_EPISODE_NUMBER).match(
                filename)

            for regex in [_REGEX_FILENAME, _REGEX_FILENAME_NO_EPISODE_NUMBER]:
                match = re.compile(regex).match(filename)
                if match:
                    logger.debug('QQQQQQQQQQQ')
                    ret = {}
                    ret['title'] = match1.group('name')
                    ret['no'] = match1.group('no')
                    ret['date'] = match1.group('date')
                    ret['etc'] = match1.group('etc').replace('.', '')
                    ret['quality'] = match1.group('quality')
                    ret['release'] = None
                    if 'release' in match1.groupdict():
                        ret['release'] = match1.group('release')
                    else:
                        ret['release'] = None
                    if ret['no'] is not None and ret['no'] != '':
                        ret['no'] = int(ret['no'])
                    else:
                        ret['no'] = -1
                    return DaumTV.change_filename_continous_episode(ret)
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
Example #6
0
def _remove_task(remove_path):
    try:
        os.remove(remove_path)
        return True
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return False
Example #7
0
 def get_config(cls, remote_name, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         data = cls.config_list(rclone_path=rclone_path, config_path=config_path, option=option)
         return data.get(remote_name, None)
         
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #8
0
def rc():
    try:
        logger.debug('XXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
        logger.debug(path)
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return jsonify('fail')
Example #9
0
def _copytree_task(source_path, target_path):
    try:
        shutil.copytree(source_path, target_path)
        return True
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return False
Example #10
0
def read_file(filename):
    try:
        import codecs
        ifp = codecs.open(filename, 'r', encoding='utf8')
        data = ifp.read()
        ifp.close()
        return data
    except Exception as exception: 
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Example #11
0
 def size(cls, remote_path, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         command = [rclone_path, '--config', config_path, 'size', remote_path, '--json']
         if option is not None:
             command += option
         ret = ToolSubprocess.execute_command_return(command, format='json')
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #12
0
 def purge(cls, remote_path, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         command = [rclone_path, '--config', config_path, 'purge', remote_path, '-vv']#, '--drive-use-trash=false', '-vv']
         if option is not None:
             command += option
         ret = ToolSubprocess.execute_command_return(command)
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #13
0
def _move_task(source_path, target_path):
    try:
        logger.debug('_move_task:%s %s', source_path, target_path)
        shutil.move(source_path, target_path)
        logger.debug('_move_task end')
        return True
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return False
Example #14
0
 def copy_server_side(cls, source, target, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         command = [rclone_path, '--config', config_path, 'copy', source, target, '--drive-server-side-across-configs=true', '--drive-stop-on-upload-limit', '-vv']
         if option is not None:
             command += option
         logger.debug(' '.join(command))
         ret = ToolSubprocess.execute_command_return(command)
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #15
0
 def rmtree(source_path):
     try:
         if app.config['config']['use_celery']:
             result = ToolShutil._rmtree_task.apply_async((source_path, ))
             return result.get()
         else:
             return ToolShutil._rmtree_task(source_path)
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
         return ToolShutil._rmtree_task(source_path)
Example #16
0
def copy(source_path, target_path):
    try:
        if app.config['config']['use_celery']:
            result = _copy_task.apply_async((source_path, target_path))
            return result.get()
        else:
            return _copy_task(source_path, target_path)
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return _copy_task(source_path, target_path)
Example #17
0
def move(source_path, target_path, run_in_celery=False):
    try:
        if app.config['config']['use_celery'] and run_in_celery == False:
            result = _move_task.apply_async((source_path, target_path))
            return result.get()
        else:
            return _move_task(source_path, target_path)
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return _move_task(source_path, target_path)
Example #18
0
 def getid(cls, remote_path, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         command = [rclone_path, '--config', config_path, 'backend', 'getid', remote_path]
         if option is not None:
             command += option
         ret = ToolSubprocess.execute_command_return(command)
         if ret is not None and (len(ret.split(' ')) > 1 or ret == ''):
             ret = None
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #19
0
def socket_file(data):
    try:
        package = filename = None
        if 'package' in data:
            package = data['package']
        else:
            filename = data['filename']
        LogViewer.instance().start(package, filename, request.sid)
        logger.debug('start package:%s filename:%s sid:%s', package, filename,
                     request.sid)
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Example #20
0
    def get_html(url):
        try:
            from framework.common.daum import headers, session
            from system.logic_site import SystemLogicSite
            res = session.get(url,
                              headers=headers,
                              cookies=SystemLogicSite.get_daum_cookies())
            data = res.text
            return data

        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
Example #21
0
 def lsjson(cls, remote_path, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         command = [rclone_path, '--config', config_path, 'lsjson', remote_path]
         if option is not None:
             command += option
         logger.warning(' '.join(command))
         ret = ToolSubprocess.execute_command_return(command, format='json')
         if ret is not None:
             ret = list(sorted(ret, key=lambda k:k['Path']))
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #22
0
 def config_list(cls, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None):
     try:
         command = [rclone_path, '--config', config_path, 'config', 'dump']#, '--drive-use-trash=false', '-vv']
         if option is not None:
             command += option
         ret = ToolSubprocess.execute_command_return(command, format='json')
         for key, value in ret.items():
             if 'token' in value and value['token'].startswith('{'):
                 value['token'] = json.loads(value['token'])
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #23
0
 def movie_append(movie_list, data):
     try:
         exist_data = None
         for tmp in movie_list:
             if tmp['id'] == data['id']:
                 #flag_exist = True
                 exist_data = tmp
                 break
         if exist_data is not None:
             movie_list.remove(exist_data)
         movie_list.append(data)
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())    
Example #24
0
    def get_show_info_on_home_title(title, daum_id=None):
        try:
            title = title.replace(u'[종영]', '')
            if daum_id is None:
                url = 'https://search.daum.net/search?q=%s' % (py_urllib.quote(
                    title.encode('utf8')))
            else:
                url = 'https://search.daum.net/search?q=%s&irk=%s&irt=tv-program&DA=TVP' % (
                    py_urllib.quote(title.encode('utf8')), daum_id)

            return DaumTV.get_lxml_by_url(url)
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
Example #25
0
def remove(remove_path):
    try:
        logger.debug('CELERY os.remove start : %s', remove_path)
        if app.config['config']['use_celery']:
            result = _remove_task.apply_async((remove_path, ))
            return result.get()
        else:
            return _remove_task(remove_path)
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return _remove_task(remove_path)
    finally:
        logger.debug('CELERY os.remove end : %s', remove_path)
Example #26
0
 def ffprobe(cls, filepath, ffprobe_path='ffprobe', option=None):
     try:
         command = [
             ffprobe_path, '-v', 'quiet', '-print_format', 'json',
             '-show_format', '-show_streams', filepath
         ]
         if option is not None:
             command += option
         logger.warning(' '.join(command))
         ret = ToolSubprocess.execute_command_return(command, format='json')
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #27
0
 def get_show_info(title, no=None, date=None):
     try:
         # Home
         title = DaumTV.get_search_name_from_original(title)
         url = 'https://search.daum.net/search?q=%s' % (py_urllib.quote(
             title.encode('utf8')))
         data = DaumTV.get_html(url)
         root = lxml.html.fromstring(data)
         home_info = DaumTV.get_show_info_on_home(root)
         tv = DaumTV.get_daum_tv_info(title)
         ret = {'home': home_info, 'tv': tv}
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #28
0
 def change_filename_continous_episode(ret):
     try:
         if ret['title'].find(u'합') == -1:
             return ret
         match = re.compile(_REGEX_FILENAME_RENAME).match(ret['title'])
         if match:
             logger.debug(u'합본 : %s', ret['filename'])
             ret['title'] = match.group('title').strip()
             # 기존 규칙으로 매칭되어있다면 굳이 바꿀 필요는 없다.
             if ret['no'] == -1:
                 ret['no'] = int(match.group('no'))
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Example #29
0
def upload():
    # curl -F file=@downloader_video.tar https://dev.soju6jan.com/up
    # 
    try:
        if request.method == 'POST':
            f = request.files['file']
            from werkzeug import secure_filename
            tmp = secure_filename(f.filename)
            logger.debug('upload : %s', tmp)
            f.save(os.path.join(path_data, 'upload', tmp))
            return jsonify('success')
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return jsonify('fail')
Example #30
0
def _move_exist_remove_task(source_path, target_path):
    try:
        target_file_path = os.path.join(target_path,
                                        os.path.basename(source_path))
        if os.path.exists(target_file_path):
            os.remove(source_path)
            return True
        logger.debug('_move_exist_remove:%s %s', source_path, target_path)
        shutil.move(source_path, target_path)
        logger.debug('_move_exist_remove end')
        return True
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
        return False