def init_test_env(): """ This method prepares all necessary data for tests execution """ # Set a default test profile, for when running tests from dev-env. from tvb.basic.profile import TvbProfile if TvbProfile.CURRENT_PROFILE_NAME is None: profile = TvbProfile.TEST_SQLITE_PROFILE if len(sys.argv) > 1: for i in range(1, len(sys.argv) - 1): if "--profile=" in sys.argv[i]: profile = sys.argv[i].split("=")[1] TvbProfile.set_profile(profile) print("Not expected to happen except from PyCharm: setting profile", TvbProfile.CURRENT_PROFILE_NAME) db_file = TvbProfile.current.db.DB_URL.replace('sqlite:///', '') if os.path.exists(db_file): os.remove(db_file) from tvb.config.init.model_manager import reset_database from tvb.config.init.initializer import initialize reset_database() initialize(skip_import=True) # Add Dummy DataType REGISTRY.register_datatype(DummyDataType, DummyDataTypeH5, DummyDataTypeIndex) REGISTRY.register_datatype(None, None, DummyDataType2Index)
def initialize_tvb(arguments): if not os.path.exists(TvbProfile.current.TVB_STORAGE): try: os.makedirs(TvbProfile.current.TVB_STORAGE) except Exception: sys.exit("You do not have enough rights to use TVB storage folder:" + str(TvbProfile.current.TVB_STORAGE)) try: initialize(arguments) except InvalidSettingsException as excep: LOGGER.exception(excep) sys.exit()
def start_tvb(arguments, browser=True): """ Fire CherryPy server and listen on a free port """ if PARAM_RESET_DB in arguments: # When specified, clean everything in DB reset() arguments.remove(PARAM_RESET_DB) if not os.path.exists(TvbProfile.current.TVB_STORAGE): try: os.makedirs(TvbProfile.current.TVB_STORAGE) except Exception: sys.exit( "You do not have enough rights to use TVB storage folder:" + str(TvbProfile.current.TVB_STORAGE)) try: initialize(arguments) except InvalidSettingsException as excep: LOGGER.exception(excep) sys.exit() # Mark that the interface is Web ABCDisplayer.VISUALIZERS_ROOT = TvbProfile.current.web.VISUALIZERS_ROOT init_cherrypy(arguments) if StorageInterface.encryption_enabled( ) and StorageInterface.app_encryption_handler(): storage_interface = StorageInterface() storage_interface.start() storage_interface.startup_cleanup() # Fire a browser page at the end. if browser: run_browser() expose_rest_api() # Launch CherryPy loop forever. LOGGER.info("Finished starting TVB version %s in %.3f s", TvbProfile.current.version.CURRENT_VERSION, time.time() - STARTUP_TIC) cherrypy.engine.block() cherrypy.log.error_log
import sys from tvb.basic.profile import TvbProfile from tvb.config.init.initializer import initialize from tvb.core.entities.file.files_update_manager import FilesUpdateManager if __name__ == '__main__': """ Script written for testing the migration from version 1.5.8 to 2.1.0. """ # set web profile TvbProfile.set_profile(TvbProfile.WEB_PROFILE) # migrate the database and h5 files h5_migrating_thread = initialize() # wait for thread to finish before processing h5_migrating_thread.join() # copy files in tvb_root folder so Jenkins can find them shutil.copytree( TvbProfile.current.TVB_LOG_FOLDER, os.path.join(TvbProfile.current.EXTERNALS_FOLDER_PARENT, 'logs')) # test if there are any files which were not migrated number_of_unmigrated_files = len(FilesUpdateManager.get_all_h5_paths()) if number_of_unmigrated_files != 0: sys.exit(-1) sys.exit(0)