def mountServer(path, database=None, fuseOptions=None, quiet=False, plugins=None): """ Perform the mount. :param path: the mount location. :param database: a database connection URI, if it contains '://'. Otherwise, the default database is used. :param fuseOptions: a comma-separated string of options to pass to the FUSE mount. A key without a value is taken as True. Boolean values are case insensitive. For instance, 'foreground' or 'foreground=True' will keep this program running until the SIGTERM or unmounted. :param quiet: if True, suppress Girder logs. :param plugins: an optional list of plugins to enable. If None, use the plugins that are configured. """ if quiet: curConfig = config.getConfig() curConfig.setdefault('logging', {})['log_quiet'] = True curConfig.setdefault('logging', {})['log_level'] = 'FATAL' girder._setupLogger() if database and '://' in database: cherrypy.config['database']['uri'] = database if plugins is not None: plugins = plugins.split(',') webroot, appconf = configureServer(plugins=plugins) girder._setupCache() opClass = ServerFuse(stat=os.stat(path)) options = { # By default, we run in the background so the mount command returns # immediately. If we run in the foreground, a SIGTERM will shut it # down 'foreground': False, # Cache files if their size and timestamp haven't changed. # This lets the OS buffer files efficiently. 'auto_cache': True, # We aren't specifying our own inos 'use_ino': False, # read-only file system 'ro': True, } if sys.platform != 'darwin': # Automatically unmount when we try to mount again options['auto_unmount'] = True if fuseOptions: for opt in fuseOptions.split(','): if '=' in opt: key, value = opt.split('=', 1) value = (False if value.lower() == 'false' else True if value.lower() == 'true' else value) else: key, value = opt, True if key in ('use_ino', 'ro', 'rw') and options.get(key) != value: logprint.warning('Ignoring the %s=%r option' % (key, value)) continue options[key] = value Setting().set(SettingKey.GIRDER_MOUNT_INFORMATION, {'path': path, 'mounttime': time.time()}) FUSELogError(opClass, path, **options)
def mountServer(path, database=None, fuseOptions=None, quiet=False, plugins=None): """ Perform the mount. :param path: the mount location. :param database: a database connection URI, if it contains '://'. Otherwise, the default database is used. :param fuseOptions: a comma-separated string of options to pass to the FUSE mount. A key without a value is taken as True. Boolean values are case insensitive. For instance, 'foreground' or 'foreground=True' will keep this program running until the SIGTERM or unmounted. :param quiet: if True, suppress Girder logs. :param plugins: an optional list of plugins to enable. If None, use the plugins that are configured. """ if quiet: curConfig = config.getConfig() curConfig.setdefault('logging', {})['log_quiet'] = True curConfig.setdefault('logging', {})['log_level'] = 'FATAL' girder._attachFileLogHandlers() if database and '://' in database: cherrypy.config['database']['uri'] = database if plugins is not None: plugins = plugins.split(',') webroot, appconf = configureServer(plugins=plugins) girder._setupCache() opClass = ServerFuse(stat=os.stat(path)) options = { # By default, we run in the background so the mount command returns # immediately. If we run in the foreground, a SIGTERM will shut it # down 'foreground': False, # Cache files if their size and timestamp haven't changed. # This lets the OS buffer files efficiently. 'auto_cache': True, # We aren't specifying our own inos 'use_ino': False, # read-only file system 'ro': True, } if sys.platform != 'darwin': # Automatically unmount when we try to mount again options['auto_unmount'] = True if fuseOptions: for opt in fuseOptions.split(','): if '=' in opt: key, value = opt.split('=', 1) value = (False if value.lower() == 'false' else True if value.lower() == 'true' else value) else: key, value = opt, True if key in ('use_ino', 'ro', 'rw') and options.get(key) != value: logprint.warning('Ignoring the %s=%r option' % (key, value)) continue options[key] = value Setting().set(SettingKey.GIRDER_MOUNT_INFORMATION, {'path': path, 'mounttime': time.time()}) FUSELogError(opClass, path, **options)
def main(plugins): if plugins is not None: plugins = plugins.split(',') webroot, appconf = configureServer(plugins=plugins) _launchShell({ 'webroot': webroot, 'appconf': appconf })
def main(plugins, script, args): if plugins is not None: plugins = plugins.split(',') webroot, appconf = configureServer(plugins=plugins) if script is None: _launchShell({ 'webroot': webroot, 'appconf': appconf }) else: globals_ = {k: v for k, v in six.viewitems(globals()) if k not in {'__file__', '__name__'}} sys.argv = [script] + list(args) six.exec_(open(script, 'rb').read(), dict( webroot=webroot, appconf=appconf, __name__='__main__', __file__=script, **globals_))
def main(plugins, script, args): if plugins is not None: plugins = plugins.split(',') webroot, appconf = configureServer(plugins=plugins) if script is None: _launchShell({ 'webroot': webroot, 'appconf': appconf }) else: globals_ = {k: v for k, v in six.viewitems(globals()) if k not in {'__file__', '__name__'}} sys.argv = [script] + list(args) exec(open(script, 'rb').read(), dict( webroot=webroot, appconf=appconf, __name__='__main__', __file__=script, **globals_))
# This ensures that: # - Worker settings are correct # - there is at least one admin user # - there is a default task folder # - there is at least one assetstore from girder.models.assetstore import Assetstore from girder.models.collection import Collection from girder.models.folder import Folder from girder.models.setting import Setting from girder.models.user import User from girder.utility.server import configureServer # This loads plugins, allowing setting validation configureServer() # Ensure worker settings are correct Setting().set('worker.broker', 'amqp://*****:*****@rabbitmq/') Setting().set('worker.backend', 'rpc://*****:*****@rabbitmq/') Setting().set('worker.api_url', 'http://*****:*****@nowhere.nil') adminUser = User().findOne({'admin': True}) # Make sure we have an assetstore if Assetstore().findOne() is None: Assetstore().createFilesystemAssetstore('Assetstore', '/assetstore') # If we don't have a default task folder, make a task collection and folder if not Setting().get('slicer_cli_web.task_folder'):
from girder.utility import server as girder_server girder_server.configureServer() from girder.models.file import File # noqa: E402, I100 from girder.models.folder import Folder # noqa: E402 from girder.models.item import Item # noqa: E402 from girder.plugins.isic_archive.models.dataset import Dataset # noqa: E402 for dataset in Dataset().find(): print(dataset['name']) for registration in dataset['metadataFiles']: metadataFile = File().load(registration['fileId'], force=True) item = Item().load(metadataFile['itemId'], force=True) folder = Folder().load(item['folderId'], force=True) print(' ', metadataFile['name']) del metadataFile['itemId'] metadataFile['attachedToType'] = ['dataset', 'isic_archive'] metadataFile = File().save(metadataFile) File().propagateSizeChange(item, -metadataFile['size']) Item().remove(item) Folder().remove(folder)
def setup(config, store): config = {"server": {"api_root": "/plugin/girder/girder/api/v1", "static_root": "/plugin/girder/girder/static"}} girder_app, config = configureServer(curConfig=config) return {"apps": [(girder_app, config, "girder")]}
import pprint import re from bson.objectid import ObjectId from girder.utility import server as girder_server # noqa girder_server.configureServer() # noqa from girder.models.file import File # noqa from girder.models.item import Item # noqa from isic_archive.models.dataset import Dataset # noqa: E402 for image in Item().find( {'baseParentId': ObjectId('55943cff9fc3c13155bcad5e')} ): dataset = Dataset().find({'_id': image['meta']['datasetId']}) print(f'{image["name"]}, {image["_id"]}, {next(dataset)["name"]}') files = list(File().find({'itemId': image['_id']})) taken_file_ids = set() # already migrated if [f for f in files if 'imageRole' in f]: continue superpixel_file_ids = [ f['_id'] for f in files if 'superpixels' in f['name'] and f['size'] > 0 and f['_id'] not in taken_file_ids
from girder.utility import server as girder_server girder_server.configureServer() from girder.models.file import File # noqa: E402, I100 from girder.models.folder import Folder # noqa: E402 from girder.models.item import Item # noqa: E402 from isic_archive.models.dataset import Dataset # noqa: E402 for dataset in Dataset().find(): print(dataset['name']) for registration in dataset['metadataFiles']: metadataFile = File().load(registration['fileId'], force=True) item = Item().load(metadataFile['itemId'], force=True) folder = Folder().load(item['folderId'], force=True) print(' ', metadataFile['name']) del metadataFile['itemId'] metadataFile['attachedToType'] = ['dataset', 'isic_archive'] metadataFile = File().save(metadataFile) File().propagateSizeChange(item, -metadataFile['size']) Item().remove(item) Folder().remove(folder)