def plugin_uninstall(plugin_name): logger.debug('plugin_name : %s', plugin_name) try: mod = __import__('%s' % (plugin_name), fromlist=[]) mod_plugin_unload = getattr(mod, 'plugin_unload') mod_plugin_unload() time.sleep(1) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) try: custom_path = os.path.join(path_data, 'custom') plugin_path = os.path.join(custom_path, plugin_name) if os.path.exists(plugin_path): try: import framework.common.celery as celery_task celery_task.rmtree(plugin_path) except Exception as exception: try: logger.debug('plugin_uninstall') os.system('rmdir /S /Q "%s"' % plugin_path) except: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) if os.path.exists(plugin_path): return 'fail' else: return 'success' except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def delete_file(): web_path = request.args.get('path') if not web_path: return error('No path in query') if web_path == '/': return error('Can\'t delete root') response = get_file(web_path) os_path = web_path_to_os_path(web_path) if not os.path.exists(os_path): return error('File %s doesn\'t exist' % web_path) if os.path.isdir(os_path): try: log.info('Deleting directory: {}'.format(os_path)) import framework.common.celery as celery_task celery_task.rmtree(os_path) except Exception as e: return error('Operation failed: %s' % e) else: try: log.info('Deleting file: {}'.format(os_path)) os.remove(os_path) except Exception as e: return error('Operation failed: %s' % e) return response
def run(self): # import youtube_dl from .plugin import YOUTUBE_DL_PACKAGE youtube_dl = __import__('%s' % YOUTUBE_DL_PACKAGE) import glob2 try: self.start_time = datetime.now() self.status = Status.START # headers는 전역으로 계속 사용하기 때문에 매번 세팅 youtube_dl.utils.std_headers = self.headers # 동영상 정보 가져오기 info_dict = MyYoutubeDL.get_info_dict(self.url, self.opts.get('proxy'), self.opts.get('cookiefile')) if info_dict is None: self.status = Status.ERROR return self.info_dict['extractor'] = info_dict['extractor'] self.info_dict['title'] = info_dict.get('title', info_dict['id']) self.info_dict['uploader'] = info_dict.get('uploader', '') self.info_dict['uploader_url'] = info_dict.get('uploader_url', '') ydl_opts = { 'logger': MyLogger(), 'progress_hooks': [self.my_hook], # 'match_filter': self.match_filter_func, 'outtmpl': os.path.join(self.temp_path, self.filename), 'ignoreerrors': True, 'cachedir': False } ydl_opts.update(self.opts) with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([self.url]) if self.status in (Status.START, Status.FINISHED): # 다운로드 성공 for i in glob2.glob(self.temp_path + '/**/*'): path = i.replace(self.temp_path, self.save_path, 1) if os.path.isdir(i): if not os.path.isdir(path): os.mkdir(path) continue celery_shutil.move(i, path) self.status = Status.COMPLETED except Exception as e: self.status = Status.ERROR logger.error('Exception:%s', e) logger.error(traceback.format_exc()) finally: # 임시폴더 삭제 celery_shutil.rmtree(self.temp_path) if self.status != Status.STOP: self.end_time = datetime.now()