Exemplo n.º 1
0
 def _test_gmip(self):
     print("Testing get_modules_in_path")
     full_path = path.join(getcwd(), "vibhaga", "test")
     modules = Inspector.get_modules_in_path(full_path)
     for module in modules:
         print("- Found module: " + module)
     print("Testing get_modules_in_path with tester filter")
     modules = Inspector.get_modules_in_path(full_path, ["tester"])
     for module in modules:
         print("- Found module: " + module)
Exemplo n.º 2
0
    def create_database(
            self,  # pylint: disable=R0913
            p_module: str,
            p_client_id: str,
            p_log: Log,
            p_passenger_factory: AbstractPassengerFactory,
            p_arguments: dict) -> AbstractDatabase:
        """ Default method for database creation """
        if p_module == "" or p_module is None:
            raise DatabaseCreationError(
                DatabaseCreationError.ErrorCode.parameter_missing)

        if p_client_id is None:
            client_id = ""
        else:
            client_id = p_client_id

        candidates = Inspector.get_classes_in_module(
            p_module, exclude_classes=["AbstractDatabase", "datetime"])

        for candidate in candidates:
            try:
                obj_instance = candidate(client_id, p_log, p_passenger_factory,
                                         p_arguments)
                if isinstance(obj_instance, AbstractDatabase):
                    return obj_instance
            except Exception:  # pylint: disable=W0703
                continue

        raise DatabaseCreationError(
            DatabaseCreationError.ErrorCode.cant_create_instance,
            p_module=p_module,
            p_client_id=p_client_id)
Exemplo n.º 3
0
    def create_driver(
            self,  # pylint: disable=R0913
            p_module: str,
            p_queue_factory: AbstractQueueFactory,
            p_processor_factory: AbstractProcessorFactory,
            p_puller_factory: AbstractPullerFactory,
            p_pusher_factory: AbstractPusherFactory) -> AbstractDriver:
        """ Creates a new driver object """
        if p_module == "" or p_module is None:
            raise DriverCreationError(
                DriverCreationError.ErrorCode.parameter_missing)

        candidates = Inspector.get_classes_in_module(
            p_module, exclude_classes=["AbstractDriver"])
        for candidate in candidates:
            try:
                obj_instance = candidate(p_queue_factory, p_processor_factory,
                                         p_puller_factory, p_pusher_factory)
                if isinstance(obj_instance, AbstractDriver):
                    return obj_instance
            except Exception:  # pylint: disable=W0703
                pass

        raise DriverCreationError(
            DriverCreationError.ErrorCode.cant_create_instance,
            p_module=p_module)
Exemplo n.º 4
0
    def create_dispatcher(
            self,
            p_module: str = None,
            p_ticket: DispatcherTicket = None) -> AbstractDispatcher:
        """ Dispatcher factory """

        if p_module == "" or p_module is None:
            dispatcher_module = PrimalDispatcherFactory._DEFAULT_DISPATCHER
        else:
            dispatcher_module = p_module

        if p_ticket is None:
            dispatcher_ticket = DispatcherTicket()
        else:
            dispatcher_ticket = p_ticket

        candidates = Inspector.get_classes_in_module(
            dispatcher_module, exclude_classes=["AbstractDispatcher"])

        for candidate in candidates:
            try:
                obj_instance = candidate(dispatcher_ticket)
                if isinstance(obj_instance, AbstractDispatcher):
                    return obj_instance
            except Exception:  # pylint: disable=W0703
                pass

        raise DispatcherCreationError(
            DispatcherCreationError.ErrorCode.cant_create_instance,
            p_module=dispatcher_module)
Exemplo n.º 5
0
    def create_pusher(self, p_module: str, p_log: Log) -> AbstractPusher:
        """ Creates a new pusher object """
        if p_module == "" or p_module is None:
            raise PusherCreationError(
                PusherCreationError.ErrorCode.parameter_missing)

        candidates = Inspector.get_classes_in_module(
            p_module, exclude_classes=["AbstractPusher"])
        for candidate in candidates:
            try:
                obj_instance = candidate(p_log)
                if isinstance(obj_instance, AbstractPusher):
                    return obj_instance
            except Exception:  # pylint: disable=W0703
                pass

        raise PusherCreationError(
            PusherCreationError.ErrorCode.cant_create_instance,
            p_module=p_module)
Exemplo n.º 6
0
    def create_passenger(self, p_module: str) -> AbstractPassenger:
        """ Default passenger factory """
        if p_module == "" or p_module is None:
            raise PassengerCreationError(PassengerCreationError.ErrorCode.parameter_missing)

        candidates = Inspector.get_classes_in_module(p_module, exclude_classes=["AbstractPassenger"]) # pylint: disable=C0301
        for candidate in candidates:
            try:
                obj_instance = candidate(p_passenger_module=p_module)
                if obj_instance.__module__ != p_module:
                    continue
                if isinstance(obj_instance, AbstractPassenger):
                    return obj_instance
            except Exception: # pylint: disable=W0703
                pass

        raise PassengerCreationError(
            PassengerCreationError.ErrorCode.cant_create_instance,
            p_module=p_module)
Exemplo n.º 7
0
    def create_puller(self, p_module: str, p_log: Log) -> AbstractPuller:
        """ Puller factory """
        if p_module == "" or p_module is None:
            raise PullerCreationError(PullerCreationError.ErrorCode.parameter_missing)

        candidates = Inspector.get_classes_in_module(p_module, exclude_classes=["AbstractPuller"])

        for candidate in candidates:
            try:
                obj_instance = candidate(p_log)
                if isinstance(obj_instance, AbstractPuller) and obj_instance.__module__ == p_module:
                    return obj_instance
            except AbstractPullerError as puller_error:
                raise puller_error
            except Exception: # pylint: disable=W0703
                continue

        raise PullerCreationError(
            PullerCreationError.ErrorCode.cant_create_instance,
            p_module=p_module)
Exemplo n.º 8
0
    def create_queue(self, p_module: str, p_database: AbstractDatabase,
                     p_log: Log) -> AbstractQueue:
        """ Queue factory """

        if p_module == "" or p_module is None or p_database is None or p_log is None:
            raise QueueCreationError(
                QueueCreationError.ErrorCode.parameter_missing,
                p_module=str(p_module))

        candidates = Inspector.get_classes_in_module(
            p_module, exclude_classes=["AbstractQueue"])
        for candidate in candidates:
            try:
                obj_instance = candidate(p_database, p_log)
                if isinstance(obj_instance, AbstractQueue):
                    return obj_instance
            except Exception:  # pylint: disable=W0703
                continue

        raise QueueCreationError(
            QueueCreationError.ErrorCode.cant_create_instance,
            p_module=p_module)
    def get_workout(self, guitar: dict = None) -> workout.WorkOut:
        """ Returns a new workout containing all practices """
        exercises = []
        practice_objects = Inspector.get_classes_in_container(
            Container(["practice"]), ["abstract"], [
                "AbstractPractice", "AbstractUrlList", "PracticeCategory",
                "PracticeCategoryGroup", "Position", "Guitar",
                "SupportPractice", "Accent"
            ])

        AllPractices._delete_duplicates(practice_objects)

        if "only_select" in self._config["practice_selection"]:
            only_select = self._config["practice_selection"]["only_select"]
            if only_select != "":
                for practice_object in practice_objects:
                    if practice_object.__module__ == only_select:
                        random_step_count = self._get_random_step_count()
                        produced_exercise = practice_object().get_exercise(
                            random_step_count, guitar)
                        exercises.append(produced_exercise)
                        output = workout.WorkOut(exercises)
                        return output

        while len(practice_objects) > 0:
            random_practice_index = random.randint(0,
                                                   len(practice_objects) - 1)
            practice_object = practice_objects[random_practice_index]

            random_step_count = self._get_random_step_count()
            produced_exercise = practice_object().get_exercise(
                random_step_count, guitar)
            if produced_exercise is not None:
                exercises.append(produced_exercise)
            practice_objects.pop(random_practice_index)

        output = workout.WorkOut(exercises)
        return output
Exemplo n.º 10
0
 def _test_gcic(self):
     print("Testing get_classes_in_container")
     classes = Inspector.get_classes_in_container(self._container)
     for class_name in classes:
         print("- Found class: " + class_name.__module__)
Exemplo n.º 11
0
 def _test_gmicc(self):
     print("Testing get_modules_in_cwd_container")
     modules = Inspector.get_modules_in_cwd_container(self._container)
     for module in modules:
         print("- Found module: " + module)
Exemplo n.º 12
0
def get_all_languages() -> []:
    """ Returns all language modules dynamically """
    return Inspector().get_modules_in_cwd_path(_PACKAGE,
                                               ["factory", "abstract"])