Пример #1
0
def initialize(introspected_modules, load_xml_events=True):
    """
    Initialize when Application is starting.
    Check for new algorithms or new DataTypes.
    """
    SettingsService().check_db_url(TvbProfile.current.db.DB_URL)

    ## Initialize DB
    is_db_empty = initialize_startup()

    ## Create Projects storage root in case it does not exist.
    initialize_storage()

    ## Populate DB algorithms, by introspection
    event_folders = []
    start_introspection_time = datetime.datetime.now()
    for module in introspected_modules:
        introspector = Introspector(module)
        # Introspection is always done, even if DB was not empty.
        introspector.introspect(True)
        event_path = introspector.get_events_path()
        if event_path:
            event_folders.append(event_path)

    # Now remove or mark as removed any unverified Algo-Group, Algo-Category or Portlet
    to_invalidate, to_remove = dao.get_non_validated_entities(
        start_introspection_time)
    for entity in to_invalidate:
        entity.removed = True
    dao.store_entities(to_invalidate)
    for entity in to_remove:
        dao.remove_entity(entity.__class__, entity.id)

    ## Populate events
    if load_xml_events:
        read_events(event_folders)

    if not TvbProfile.is_first_run():
        ## Create default users.
        if is_db_empty:
            dao.store_entity(
                model.User(TvbProfile.current.web.admin.SYSTEM_USER_NAME, None,
                           None, True, None))
            UserService().create_user(
                username=TvbProfile.current.web.admin.ADMINISTRATOR_NAME,
                password=TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD,
                email=TvbProfile.current.web.admin.ADMINISTRATOR_EMAIL,
                role=model.ROLE_ADMINISTRATOR)

        ## In case actions related to latest code-changes are needed, make sure they are executed.
        CodeUpdateManager().run_all_updates()

        ## In case the H5 version changed, run updates on all DataTypes
        if TvbProfile.current.version.DATA_CHECKED_TO_VERSION < TvbProfile.current.version.DATA_VERSION:
            thread = threading.Thread(
                target=FilesUpdateManager().run_all_updates)
            thread.start()

        ## Clean tvb-first-time-run temporary folder, as we are no longer at the first run:
        shutil.rmtree(TvbProfile.current.FIRST_RUN_STORAGE, True)
    def setUp(self):
        """
        Introspect supplementary folder:
        """
        core_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        TvbProfile.current.web.CURRENT_DIR = os.path.dirname(core_path)

        self.introspector = Introspector("tvb.tests.framework")
        self.introspector.introspect(True)
Пример #3
0
    def setUp(self):
        """
        Introspect supplementary folder:
        """
        core_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        TvbProfile.current.web.CURRENT_DIR = os.path.dirname(core_path)
        adapters_init.__xml_folders__ = [os.path.join("core", "adapters")]

        self.introspector = Introspector("tvb.tests.framework")
        self.introspector.introspect(True)
Пример #4
0
 def setUp(self):
     """
     Reset the database before each test.
     """
     self.reset_database()
     #tvb_test path
     core_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     self.old_path = cfg.CURRENT_DIR
     cfg.CURRENT_DIR = os.path.dirname(core_path)
     self.introspector = Introspector("tvb_test")
Пример #5
0
 def setUp(self):
     """
     This method sets up the necessary paths for testing.
     """
     self.folder_path = os.path.dirname(__file__)
     #tvb_test path
     core_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     self.old_path = cfg.CURRENT_DIR
     cfg.CURRENT_DIR = os.path.dirname(core_path)
     adapters_init.__xml_folders__ = [os.path.join('core', 'adapters')]
     self.introspector = Introspector("tvb_test")
     self.introspector.introspect(True)
     xml_group_path = os.path.join('core', 'adapters', "test_group.xml")
     algo_group = dao.find_group('tvb_test.adapters.testgroupadapter', 'TestGroupAdapter', xml_group_path)
     self.xml_group_adapter = ABCAdapter.build_adapter(algo_group)
     self.xml_group_reader = self.xml_group_adapter.xml_reader
Пример #6
0
def initialize(introspected_modules, load_xml_events=True):
    """
    Initialize when Application is starting.
    Check for new algorithms or new DataTypes.
    """
    SettingsService().check_db_url(cfg.DB_URL)

    ## Initialize DB
    is_db_empty = initialize_startup()

    ## Create Projects storage root in case it does not exist.
    initialize_storage()

    ## Populate DB algorithms, by introspection
    event_folders = []
    start_introspection_time = datetime.datetime.now()
    for module in introspected_modules:
        introspector = Introspector(module)
        # Introspection is always done, even if DB was not empty.
        introspector.introspect(True)
        event_path = introspector.get_events_path()
        if event_path:
            event_folders.append(event_path)
    # Now remove any unverified Algo-Groups, categories or Portlets
    invalid_stored_entities = dao.get_non_validated_entities(
        start_introspection_time)
    for entity in invalid_stored_entities:
        dao.remove_entity(entity.__class__, entity.id)

    ## Populate events
    if load_xml_events:
        eventhandler.read_events(event_folders)

    ## Make sure DB events are linked.
    db_events.attach_db_events()

    ## Create default users.
    if is_db_empty:
        dao.store_entity(
            model.User(cfg.SYSTEM_USER_NAME, None, None, True, None))
        UserService().create_user(username=cfg.ADMINISTRATOR_NAME,
                                  password=cfg.ADMINISTRATOR_PASSWORD,
                                  email=cfg.ADMINISTRATOR_EMAIL,
                                  role=ROLE_ADMINISTRATOR)

    ## In case actions related to latest code-changes are needed, make sure they are executed.
    CodeUpdateManager().update_all()
Пример #7
0
    def setUp(self):
        """
        Set up any additionally needed parameters.
        """
        super(GenshiTestGroup, self).setUp()

        core_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        self.old_path = cfg.CURRENT_DIR
        cfg.CURRENT_DIR = os.path.dirname(core_path)

        adapters_init.__xml_folders__ = [os.path.join('interfaces', 'web')]
        self.introspector = Introspector("tvb_test")
        self.introspector.introspect(True)

        xml_group_path = os.path.join('interfaces', 'web', "test_group.xml")
        algo_group = dao.find_group('tvb_test.adapters.testgroupadapter',
                                    'TestGroupAdapter', xml_group_path)
        self.xml_group_adapter = ABCAdapter.build_adapter(algo_group)
        input_tree = self.xml_group_adapter.get_input_tree()
        input_tree = ABCAdapter.prepare_param_names(input_tree)
        self.template_specification['inputList'] = input_tree
        self.template_specification[base.KEY_PARAMETERS_CONFIG] = False
        resulted_html = _template2string(self.template_specification)
        self.soup = BeautifulSoup(resulted_html)