def __init__(self, params): # Load configfile if isinstance(params, dict): self.params = params elif isinstance(params, config.ConfigParser): self.params = config.as_dict(params) elif isinstance(params, (str, unicode)): self.params = config.as_dict(config.from_path(params)) else: raise ValueError( "Invalid params - must be a dict, ConfigParser, or path to configfile" ) _run = 'run' _name = 'name' self.name = self.params[_run][_name] self.version = self.params['run']['version'] if self.name is None: raise ValueError( "Entry '%s' in section '%s' is None - can't construct fullname" % (_name, _run)) self.fullname = self.params['run'].get( 'fullname', '_'.join([ getpass.getuser(), datetime.utcnow().strftime('%Y%m%d'), self.name, '%s' % self.version ])) # TODO: Migrate from run_dir to gs_run_dir for final output self.run_dir = os.path.join(self.params['run']['process_runs'], self.fullname) self.gs_run_dir = self.run_dir
def __init__(self, params): # Load configfile if isinstance(params, dict): self.params = params elif isinstance(params, config.ConfigParser): self.params = config.as_dict(params) elif isinstance(params, (str, unicode)): self.params = config.as_dict(config.from_path(params)) else: raise ValueError("Invalid params - must be a dict, ConfigParser, or path to configfile") _run = 'run' _name = 'name' self.name = self.params[_run][_name] self.version = self.params['run']['version'] if self.name is None: raise ValueError("Entry '%s' in section '%s' is None - can't construct fullname" % (_name, _run)) self.fullname = self.params['run'].get( 'fullname', '_'.join( [ getpass.getuser(), datetime.utcnow().strftime('%Y%m%d'), self.name, '%s' % self.version ] ) ) # TODO: Migrate from run_dir to gs_run_dir for final output self.run_dir = os.path.join(self.params['run']['process_runs'], self.fullname) self.gs_run_dir = self.run_dir
def make_celery(): celery = Celery(__name__, broker=config.CELERY_BROKER) celery.conf.update(config.as_dict()) uds_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: uds_socket.connect(config.AGENT_SOCK) except socket.error as error: logger.warning(error) return celery, uds_socket
def make_celery(): celery = Celery(__name__, broker=config.CELERY_BROKER) celery.conf.update(config.as_dict()) return celery
def test_as_dict(): res = config.as_dict() assert res assert type(res) is dict