def options(*args, **kwargs): """ Set options for the current session. Args: kwargs (dict): List of arbitrary config items to set. Examples: >>> # set options to defaults >>> coda.options() >>> coda.find_one({'name': 'test'}).path '/file/on/localhost/server' >>> >>> # connect to a database for a different host >>> coda.options({'host': 'remote'}) >>> coda.find_one({'name': 'test'}).path '/file/on/remote/server' """ global session, __default_config__, __user_config__ with open(__default_config__, 'r') as cfig: config = composite(cfig) if os.path.exists(__user_config__): with open(__user_config__, 'r') as cfig: config = config + composite(cfig) if len(kwargs) != 0: config = config + composite(kwargs) try: session = Session(**config._dict) except TypeError: raise AssertionError('Something is wrong with your coda configuration' ' -- check your config file for valid parameters.') return config.json()
def options(**kwargs): """ Set options for the current session. Args: kwargs (dict): List of arbitrary config items to set. """ global session, __default_config__, __user_config__ # read default config with open(__default_config__, 'r') as cfig: config = composite.load(cfig) # read and add user config if os.path.exists(__user_config__): with open(__user_config__, 'r') as cfig: config = config + composite.load(cfig) if len(kwargs) != 0: config = config + composite(kwargs) # update session try: session = Session(**config._dict) except TypeError: raise exc.SettingsError() return config.json()
def __init__(self, path, metadata={}): assert os.path.exists(path), 'Specified file path does not exist!' assert not os.path.isdir( path ), 'Specified file is not a file! Use the Collection object for a directory.' self.path = os.path.realpath(path) self._metadata = composite(metadata) return
def __init__(self, files, metadata={}): if isinstance(files, str): ft = filetree(files) self.files = [self.__file_base__(x) for x in ft.filelist()] if len(self.files) == 0: raise AssertionError( 'Could not find any files for collection!') else: self.files = files self._metadata = composite(metadata) return
__config__ = os.path.join(__base__, 'config.json') __db__ = os.environ.get('PETRI_DATA', '/data/petri') __data__ = os.path.join(__db__, 'collections') # instantiate session # ------------------- default_dict = { 'data_home': __data__, 'resource_home': __resources__, 'host': 'localhost', 'port': 27017, 'write': True, 'genome': 'hg19' } defaults = composite(default_dict) if os.path.exists(__config__): with open(__config__, 'r') as config_reader: config = composite(config_reader) config_reader.close() defaults = defaults + config if not os.path.exists(defaults['data_home']): os.makedirs(defaults['data_home']) global session session = Session(**defaults) # get rest of petri imports # -------------------------