本文整理汇总了Python中tvb.basic.profile.TvbProfile类的典型用法代码示例。如果您正苦于以下问题:Python TvbProfile类的具体用法?Python TvbProfile怎么用?Python TvbProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TvbProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fake_restart_services
def _fake_restart_services(self, should_reset):
"""
This function will replace the SettingsController._restart_service method,
to avoid problems in tests due to restart.
"""
self.was_reset = should_reset
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
示例2: test_read_stored_settings
def test_read_stored_settings(self):
"""
Test to see that keys from the configuration dict is updated with
the value from the configuration file after store.
"""
initial_configurations = self.settings_service.configurable_keys
to_store_data = {key: value['value'] for key, value in initial_configurations.iteritems()}
for key, value in self.TEST_SETTINGS.iteritems():
to_store_data[key] = value
is_changed, shoud_reset = self.settings_service.save_settings(**to_store_data)
assert shoud_reset and is_changed
# enforce keys to get repopulated:
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
self.settings_service = SettingsService()
updated_configurations = self.settings_service.configurable_keys
for key, value in updated_configurations.iteritems():
if key in self.TEST_SETTINGS:
assert self.TEST_SETTINGS[key] == value['value']
elif key == SettingsService.KEY_ADMIN_PWD:
assert TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD == value['value']
assert TvbProfile.current.web.admin.ADMINISTRATOR_BLANK_PWD == initial_configurations[key]['value']
else:
assert initial_configurations[key]['value'] == value['value']
示例3: setup_test_env
def setup_test_env():
from tvb.basic.profile import TvbProfile
if len(sys.argv) > 1:
profile = sys.argv[1]
else:
profile = TvbProfile.TEST_SQLITE_PROFILE
TvbProfile.set_profile(profile)
示例4: teardown_method
def teardown_method(self):
"""
Restore configuration file
"""
if os.path.exists(TEST_CONFIG_FILE):
os.remove(TEST_CONFIG_FILE)
TvbProfile.current.__class__.TVB_CONFIG_FILE = self.old_config_file
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
示例5: cleanup
def cleanup(self):
"""
Have a different name than transactional_teardown_method so we can use it safely in transactions and it will
not be called after running actual test.
Using transactional_teardown_method here won't WORK!! See TransactionalTest
"""
if os.path.exists(TvbProfile.current.TVB_CONFIG_FILE):
os.remove(TvbProfile.current.TVB_CONFIG_FILE)
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
示例6: setup_method
def setup_method(self):
"""
Prepare the usage of a different config file for this class only.
"""
if os.path.exists(TEST_CONFIG_FILE):
os.remove(TEST_CONFIG_FILE)
self.old_config_file = TvbProfile.current.TVB_CONFIG_FILE
TvbProfile.current.__class__.TVB_CONFIG_FILE = TEST_CONFIG_FILE
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
self.settings_service = SettingsService()
示例7: settings
def settings(self, save_settings=False, **data):
"""Main settings page submit and get"""
template_specification = dict(mainContent="../settings/system_settings", title="System Settings")
if save_settings:
try:
form = SettingsForm()
data = form.to_python(data)
isrestart, isreset = self.settingsservice.save_settings(**data)
if isrestart:
thread = threading.Thread(target=self._restart_services, kwargs={'should_reset': isreset})
thread.start()
common.add2session(common.KEY_IS_RESTART, True)
common.set_important_message('Please wait until TVB is restarted properly!')
raise cherrypy.HTTPRedirect('/tvb')
# Here we will leave the same settings page to be displayed.
# It will continue reloading when CherryPy restarts.
except formencode.Invalid as excep:
template_specification[common.KEY_ERRORS] = excep.unpack_errors()
except InvalidSettingsException as excep:
self.logger.error('Invalid settings! Exception %s was raised' % (str(excep)))
common.set_error_message(excep.message)
template_specification.update({'keys_order': self.settingsservice.KEYS_DISPLAY_ORDER,
'config_data': self.settingsservice.configurable_keys,
common.KEY_FIRST_RUN: TvbProfile.is_first_run()})
return self.fill_default_attributes(template_specification)
示例8: init_test_env
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.
if TvbProfile.CURRENT_PROFILE_NAME is None:
TvbProfile.set_profile(TvbProfile.TEST_SQLITE_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.core.entities.model_manager import reset_database
from tvb.core.services.initializer import initialize
reset_database()
initialize(["tvb.config", "tvb.tests.framework"], skip_import=True)
示例9: initialize
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)
示例10: setup
def setup():
if sys.platform != 'darwin':
unsupport_module('h5py')
import logging
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
from tvb.basic.profile import TvbProfile
TvbProfile.set_profile(TvbProfile.MATLAB_PROFILE)
# MATLAB states the module doesn't exist if not importable and provides no traceback
# to diagnose the import error, so we'll need to workaround this in the future. For now,
# just try to import the simlab and report if it worked or not.
try:
import tvb.simulator.lab
print('TVB modules available.')
except Exception as exc:
#print 'failed to import all TVB modules, not all functionality may be .'
pass
示例11: test_update_settings
def test_update_settings(self):
"""
Test update of settings: correct flags should be returned, and check storage folder renamed
"""
# 1. save on empty config-file:
to_store_data = {key: value['value'] for key, value in self.settings_service.configurable_keys.iteritems()}
for key, value in self.TEST_SETTINGS.iteritems():
to_store_data[key] = value
is_changed, shoud_reset = self.settings_service.save_settings(**to_store_data)
assert shoud_reset and is_changed
# 2. Reload and save with the same values (is_changed expected to be False)
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
self.settings_service = SettingsService()
to_store_data = {key: value['value'] for key, value in self.settings_service.configurable_keys.iteritems()}
is_changed, shoud_reset = self.settings_service.save_settings(**to_store_data)
assert not is_changed
assert not shoud_reset
# 3. Reload and check that changing TVB_STORAGE is done correctly
TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)
self.settings_service = SettingsService()
to_store_data = {key: value['value'] for key, value in self.settings_service.configurable_keys.iteritems()}
to_store_data[SettingsService.KEY_STORAGE] = os.path.join(TvbProfile.current.TVB_STORAGE, 'RENAMED')
# Write a test-file and check that it is moved
file_writer = open(os.path.join(TvbProfile.current.TVB_STORAGE, "test_rename-xxx43"), 'w')
file_writer.write('test-content')
file_writer.close()
is_changed, shoud_reset = self.settings_service.save_settings(**to_store_data)
assert is_changed
assert not shoud_reset
# Check that the file was correctly moved:
data = open(os.path.join(TvbProfile.current.TVB_STORAGE, 'RENAMED', "test_rename-xxx43"), 'r').read()
assert data == 'test-content'
shutil.rmtree(os.path.join(TvbProfile.current.TVB_STORAGE, 'RENAMED'))
os.remove(os.path.join(TvbProfile.current.TVB_STORAGE, "test_rename-xxx43"))
示例12: test_first_run_save
def test_first_run_save(self):
"""
Check that before setting something, all flags are pointing towards empty.
After storing some configurations, check that flags are changed.
"""
initial_configurations = self.settings_service.configurable_keys
first_run = TvbProfile.is_first_run()
assert first_run, "Invalid First_Run flag!!"
assert not os.path.exists(TEST_CONFIG_FILE)
assert len(TvbProfile.current.manager.stored_settings) == 0
to_store_data = {key: value['value'] for key, value in initial_configurations.iteritems()}
for key, value in self.TEST_SETTINGS.iteritems():
to_store_data[key] = value
_, shoud_reset = self.settings_service.save_settings(**to_store_data)
assert shoud_reset
first_run = TvbProfile.is_first_run()
assert not first_run, "Invalid First_Run flag!!"
assert os.path.exists(TEST_CONFIG_FILE)
assert not len(TvbProfile.current.manager.stored_settings) == 0
示例13: __init__
def __init__(self):
self.logger = get_logger(__name__)
first_run = TvbProfile.is_first_run()
storage = TvbProfile.current.TVB_STORAGE if not first_run else TvbProfile.current.DEFAULT_STORAGE
self.configurable_keys = {
self.KEY_STORAGE: {'label': 'Root folder for all projects', 'value': storage,
'readonly': not first_run, 'type': 'text'},
self.KEY_MAX_DISK_SPACE_USR: {'label': 'Max hard disk space per user (MBytes)',
'value': TvbProfile.current.MAX_DISK_SPACE / 2 ** 10, 'type': 'text'},
self.KEY_MATLAB_EXECUTABLE: {'label': 'Optional Matlab or Octave path', 'type': 'text',
'value': TvbProfile.current.MATLAB_EXECUTABLE or get_matlab_executable() or '',
'description': 'Some analyzers will not be available when '
'matlab/octave are not found'},
self.KEY_SELECTED_DB: {'label': 'Select one DB engine', 'value': TvbProfile.current.db.SELECTED_DB,
'type': 'select', 'readonly': not first_run,
'options': TvbProfile.current.db.ACEEPTED_DBS},
self.KEY_DB_URL: {'label': "DB connection URL",
'value': TvbProfile.current.db.ACEEPTED_DBS[TvbProfile.current.db.SELECTED_DB],
'type': 'text', 'readonly': TvbProfile.current.db.SELECTED_DB == 'sqlite'},
self.KEY_PORT: {'label': 'Port to run Cherrypy on',
'value': TvbProfile.current.web.SERVER_PORT, 'dtype': 'primitive', 'type': 'text'},
self.KEY_PORT_MPLH5: {'label': 'Port to run Matplotlib on', 'type': 'text', 'dtype': 'primitive',
'value': TvbProfile.current.web.MPLH5_SERVER_PORT},
self.KEY_URL_WEB: {'label': 'URL for accessing web',
'value': TvbProfile.current.web.BASE_URL, 'type': 'text', 'dtype': 'primitive'},
self.KEY_URL_MPLH5: {'label': 'URL for accessing MPLH5 visualizers', 'type': 'text',
'value': TvbProfile.current.web.MPLH5_SERVER_URL, 'dtype': 'primitive'},
self.KEY_MAX_NR_THREADS: {'label': 'Maximum no. of threads for local installations', 'type': 'text',
'value': TvbProfile.current.MAX_THREADS_NUMBER, 'dtype': 'primitive'},
self.KEY_MAX_RANGE: {'label': 'Maximum no. of operations in one PSE',
'description': "Parameters Space Exploration (PSE) maximum number of operations",
'value': TvbProfile.current.MAX_RANGE_NUMBER, 'type': 'text', 'dtype': 'primitive'},
self.KEY_MAX_NR_SURFACE_VERTEX: {'label': 'Maximum no. of vertices in a surface',
'type': 'text', 'dtype': 'primitive',
'value': TvbProfile.current.MAX_SURFACE_VERTICES_NUMBER},
self.KEY_CLUSTER: {'label': 'Deploy on cluster', 'value': TvbProfile.current.cluster.IS_DEPLOY,
'description': 'Check this only if on the web-server machine OARSUB command is enabled.',
'dtype': 'primitive', 'type': 'boolean'},
self.KEY_ADMIN_NAME: {'label': 'Administrator User Name',
'value': TvbProfile.current.web.admin.ADMINISTRATOR_NAME,
'type': 'text', 'readonly': not first_run,
'description': ('Password and Email can be edited after first run, '
'from the profile page directly.')},
self.KEY_ADMIN_PWD: {'label': 'Password',
'value': TvbProfile.current.web.admin.ADMINISTRATOR_BLANK_PWD if first_run
else TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD,
'type': 'password', 'readonly': not first_run},
self.KEY_ADMIN_EMAIL: {'label': 'Administrator Email',
'value': TvbProfile.current.web.admin.ADMINISTRATOR_EMAIL,
'readonly': not first_run, 'type': 'text'}}
示例14: init_test_env
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.
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.core.entities.model_manager import reset_database
from tvb.core.services.initializer import initialize
reset_database()
initialize(["tvb.config", "tvb.tests.framework"], skip_import=True)
示例15: run_all_updates
def run_all_updates(self):
"""
Upgrade the code to current version.
Go through all update scripts with lower SVN version than the current running version.
"""
if TvbProfile.is_first_run():
## We've just started with a clean TVB. No need to upgrade anything.
return
super(CodeUpdateManager, self).run_all_updates()
if self.checked_version < self.current_version:
TvbProfile.current.manager.add_entries_to_config_file(
{stored.KEY_LAST_CHECKED_CODE_VERSION: TvbProfile.current.version.SVN_VERSION})