def initialize(self, **kwargs): self.name = 'pending_api' self.config = config.CONFIG() self.params = kwargs.get("params") udq = UnmanicDataQueues() self.unmanic_data_queues = udq.get_unmanic_data_queues()
def setup_class(self): """ Setup the class state for pytest :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) self.tests_videos_dir = os.path.join(self.project_dir, 'tests', 'support_', 'videos') self.tests_tmp_dir = os.path.join(self.project_dir, 'tests', 'tmp', 'py_test_env') # sys.path.append(self.project_dir) self.logging = unlogger.UnmanicLogger.__call__(False) self.logging.get_logger() # import config from unmanic import config self.settings = config.CONFIG() self.settings.DEBUGGING = True # Create our test queues self.data_queues = { "progress_reports": queue.Queue(), "logging": self.logging } self.task_queue = queue.Queue(maxsize=1) self.complete_queue = queue.Queue()
def initialize(self, data_queues): self.name = 'plugins' self.config = config.CONFIG() self.session = session.Session() self.data_queues = data_queues self.data = { 'plugin_types': [ { 'id': 'library_management_file_test', 'name': 'Library Management - File test', 'plugin_type': 'library_management.file_test', }, { 'id': 'worker_process', 'name': 'Worker - Processing file', 'plugin_type': 'worker.process_item', }, { 'id': 'postprocessor_file_movement', 'name': 'Post-processor - File movements', 'plugin_type': 'postprocessor.file_move', }, { 'id': 'postprocessor_task_results', 'name': 'Post-processor - Marking task success/failure', 'plugin_type': 'postprocessor.task_result', }, ] }
def __init__(self, *args, **kwargs): self.name = 'dashws' self.config = config.CONFIG() self.server_id = str(uuid.uuid4()) self.data_queues = kwargs.pop('data_queues') self.foreman = kwargs.pop('foreman') self.session = session.Session() super(DashboardWebSocket, self).__init__(*args, **kwargs)
def initialize(self, data_queues): self.name = 'settings' self.config = config.CONFIG() self.session = session.Session() self.step = 'general' self.data_queues = data_queues self.components = []
def initialize(self, data_queues): self.name = 'history' self.config = config.CONFIG() self.session = session.Session() # TODO: Fetch data queues from uiserver.py self.data_queues = data_queues self.data = {}
def initialize(self, data_queues, foreman): self.name = 'main' self.config = config.CONFIG() self.session = session.Session() # TODO: Fetch data queues from uiserver.py self.data_queues = data_queues #self.foreman = foreman self.components = []
def __init__(self, plugins_directory=None): # Read settings self.settings = config.CONFIG() # Set plugins directory if not plugins_directory: plugins_directory = os.path.join(os.path.expanduser("~"), '.unmanic', 'plugins') self.plugins_directory = plugins_directory unmanic_logging = unlogger.UnmanicLogger.__call__() unmanic_logging.disable_file_handler() self.logger = unmanic_logging.get_logger(__class__.__name__)
def run(self): # Read settings settings = config.CONFIG() # Create our data queues data_queues = { "scheduledtasks": queue.Queue(), "inotifytasks": queue.Queue(), "progress_reports": queue.Queue(), "logging": unmanic_logging } # Clear cache directory common.clean_files_in_dir(settings.CACHE_PATH) # Setup job queue job_queue = JobQueue(settings, data_queues) # Setup post-processor thread self.start_post_processor(data_queues, settings, job_queue) # Start the worker threads worker_handle = self.start_workers(data_queues, settings, job_queue) # Start new thread to handle messages from service self.start_handler(data_queues, settings, job_queue) # Start new thread to run the web UI self.start_ui_server(data_queues, settings, worker_handle) # Start scheduled thread self.start_library_scanner_manager(data_queues, settings) # Start inotify watch manager self.start_inotify_watch_manager(data_queues, settings) # Watch for the term signal signal.signal(signal.SIGINT, self.sig_handle) signal.signal(signal.SIGTERM, self.sig_handle) while self.run_threads: signal.pause() # Received term signal. Stop everything main_logger.info("Stopping all threads") for thread in self.threads: main_logger.info("Sending thread {} abort signal".format( thread['name'])) thread['thread'].stop() main_logger.info("Waiting for thread {} to stop".format( thread['name'])) thread['thread'].join() main_logger.info("Exit Unmanic")
def setup_class(self): """ Setup the class state for pytest :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) self.tests_videos_dir = os.path.join(self.project_dir, 'tests', 'support_', 'videos') self.tests_tmp_dir = os.path.join(self.project_dir, 'tests', 'tmp', 'py_test_env') # sys.path.append(self.project_dir) self.logging = unlogger.UnmanicLogger.__call__(False) self.logging.get_logger() # Create temp config path config_path = tempfile.mkdtemp(prefix='unmanic_tests_') # Create connection to a test DB from unmanic.libs import unmodels app_dir = os.path.dirname(os.path.abspath(__file__)) database_settings = { "TYPE": "SQLITE", "FILE": os.path.join(config_path, 'unmanic.db'), "MIGRATIONS_DIR": os.path.join(app_dir, 'migrations'), } self.db_connection = unmodels.Database.select_database( database_settings) # Start the database connection self.db_connection.start() self.db_connection.create_tables([ Settings, Tasks, TaskSettings, TaskProbe, TaskProbeStreams, Plugins ]) # import config from unmanic import config self.settings = config.CONFIG(config_path=config_path, db_connection=self.db_connection) self.settings.set_config_item('debugging', True, save_settings=False) # Create our test queues self.data_queues = { "progress_reports": queue.Queue(), "logging": self.logging } self.task_queue = queue.Queue(maxsize=1) self.complete_queue = queue.Queue()
def __init__(self, unmanic_data_queues, foreman, developer): super(UIServer, self).__init__(name='UIServer') self.config = config.CONFIG() self.developer = developer self.data_queues = unmanic_data_queues self.logger = unmanic_data_queues["logging"].get_logger(self.name) self.inotifytasks = unmanic_data_queues["inotifytasks"] # TODO: Move all logic out of template calling to foreman. # Create methods here to handle the calls and rename to foreman self.foreman = foreman self.set_logging() # Add a singleton for handling the data queues for sending data to unmanic's other processes udq = UnmanicDataQueues() udq.set_unmanic_data_queues(unmanic_data_queues)
def __init__(self, plugins_directory=None): # Read settings self.settings = config.CONFIG() # Set plugins directory if not plugins_directory: plugins_directory = os.path.join(os.path.expanduser("~"), '.unmanic', 'plugins') self.plugins_directory = plugins_directory unmanic_logging = unlogger.UnmanicLogger.__call__() unmanic_logging.disable_file_handler(debugging=True) unmanic_logging.stream_handler.setFormatter( logging.Formatter( ' - {}%(asctime)s:%(levelname)s:%(name)s - %(message)s{}' .format(BColours.RESULTS, BColours.ENDC), datefmt='%Y-%m-%dT%H:%M:%S')) self.logger = unmanic_logging.get_logger(__class__.__name__)
def setup_class(self): """ Setup the class state for pytest. :return: """ self.project_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) self.tests_videos_dir = os.path.join(self.project_dir, 'tests', 'support_', 'videos') self.tests_tmp_dir = os.path.join(self.project_dir, 'tests', 'tmp', 'py_test_env') # sys.path.append(self.project_dir) unmanic_logging = unlogger.UnmanicLogger.__call__(False) unmanic_logging.get_logger() # import config from unmanic import config self.settings = config.CONFIG(config_path=tempfile.mkdtemp(prefix='unmanic_tests_')) self.settings.set_config_item('debugging', True, save_settings=False) ffmpeg_settings = build_ffmpeg_handle_settings(self.settings) self.ffmpeg = ffmpeg.FFMPEGHandle(ffmpeg_settings)
def setup_class(self): """ Setup the class state for pytest. :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) self.tests_videos_dir = os.path.join(self.project_dir, 'tests', 'support_', 'videos') self.tests_tmp_dir = os.path.join(self.project_dir, 'tests', 'tmp', 'py_test_env') # sys.path.append(self.project_dir) unmanic_logging = unlogger.UnmanicLogger.__call__(False) unmanic_logging.get_logger() # import config from unmanic import config self.settings = config.CONFIG() self.settings.DEBUGGING = True self.ffmpeg = ffmpeg.FFMPEGHandle(self.settings)
def setup_class(self): """ Setup the class state for pytest :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) self.data_queues = data_queues.data_queues self.scheduledtasks = self.data_queues["scheduledtasks"] self.inotifytasks = self.data_queues["inotifytasks"] self.progress_reports = self.data_queues["progress_reports"] #self.settings = mock_config_class.MockConfig() self.task_queue = mock_jobqueue_class.MockJobQueue() self.task_handler = None # import config from unmanic import config self.settings = config.CONFIG( os.path.join(tempfile.mkdtemp(), 'unmanic_test.db')) self.settings.DEBUGGING = True
def setup_class(self): """ Setup the class state for pytest :return: """ self.project_dir = os.path.dirname( os.path.dirname(os.path.abspath(__file__))) self.data_queues = data_queues.data_queues self.scheduledtasks = self.data_queues["scheduledtasks"] self.inotifytasks = self.data_queues["inotifytasks"] self.progress_reports = self.data_queues["progress_reports"] self.task_queue = mock_jobqueue_class.MockJobQueue() self.task_handler = None # Create temp config path config_path = tempfile.mkdtemp(prefix='unmanic_tests_') # Create connection to a test DB from unmanic.libs import unmodels app_dir = os.path.dirname(os.path.abspath(__file__)) database_settings = { "TYPE": "SQLITE", "FILE": ':memory:', "MIGRATIONS_DIR": os.path.join(app_dir, 'migrations'), } self.db_connection = unmodels.Database.select_database( database_settings) # Start the database connection self.db_connection.start() self.db_connection.create_tables([Settings, Tasks]) # import config from unmanic import config self.settings = config.CONFIG(config_path=config_path, db_connection=self.db_connection) self.settings.set_config_item('debugging', True, save_settings=False)
def run(self): # Init DB if not self.db_connection: self.db_connection = init_db() self.db_connection.start() # Read settings settings = config.CONFIG(db_connection=self.db_connection) # Start all threads self.start_threads(settings) # Watch for the term signal signal.signal(signal.SIGINT, self.sig_handle) signal.signal(signal.SIGTERM, self.sig_handle) while self.run_threads: signal.pause() # Received term signal. Stop everything self.stop_threads() self.db_connection.stop() main_logger.info("Exit Unmanic")
def start_threads(self): # Read settings settings = config.CONFIG() # Create our data queues data_queues = { "scheduledtasks": queue.Queue(), "inotifytasks": queue.Queue(), "progress_reports": queue.Queue(), "logging": unmanic_logging } # Clear cache directory main_logger.info("Clearing previous cache") common.clean_files_in_dir(settings.CACHE_PATH) main_logger.info("Starting all threads") # Setup job queue task_queue = TaskQueue(settings, data_queues) # Setup post-processor thread self.start_post_processor(data_queues, settings, task_queue) # Start the foreman thread foreman = self.start_foreman(data_queues, settings, task_queue) # Start new thread to handle messages from service self.start_handler(data_queues, settings, task_queue) # Start new thread to run the web UI self.start_ui_server(data_queues, settings, foreman) # Start scheduled thread self.start_library_scanner_manager(data_queues, settings) # Start inotify watch manager self.start_inotify_watch_manager(data_queues, settings)
def __init__(self, *args, **kwargs): self.settings = config.CONFIG() unmanic_logging = unlogger.UnmanicLogger.__call__() self.logger = unmanic_logging.get_logger(__class__.__name__)
def __init__(self, app, **kwargs): self.app = app self.config = config.CONFIG()
def register_unmanic(self, uuid, force=False): """ Register Unmanic with site. This sends information about the system that Unmanic is running on. It also sends a unique ID. Based on the return information, this will set the session level Return success status :return: """ # First check if the current session is still valid if not force and self.__check_session_valid(): return True settings = config.CONFIG() try: # Build post data from unmanic.libs.system import System system = System() system_info = system.info() platform_info = system_info.get("platform", None) if platform_info: platform_info = " * ".join(platform_info) post_data = { "uuid": uuid, "version": settings.read_version(), "python_version": system_info.get("python", ''), "system": { "platform": platform_info, "devices": system_info.get("devices", {}), } } # Register Unmanic registration_response = self.api_post(1, 'unmanic-register', post_data) # Save data if registration_response and registration_response.get("success"): registration_data = registration_response.get("data") # Set level from response data (default back to 0) self.level = registration_data.get("level", 0) # Get user data from response data user_data = registration_data.get('user') if user_data: # Set name from user data name = user_data.get("name") self.name = name if name else 'Valued Supporter' # Set avatar from user data picture_uri = user_data.get("picture_uri") self.picture_uri = picture_uri if picture_uri else '/assets/global/img/avatar/avatar_placeholder.png' # Set email from user data email = user_data.get("email") self.email = email if email else '' self.__update_created_timestamp() return True return False except Exception as e: self._log("Exception while registering Unmanic.", str(e), level="debug") return False