def __init__(self, genomeId, context=None, communityIndex='0'): ''' Initialize object. @param genomeId: Genome ID string for genome being annotated @param context: User context when used in a server @param communityIndex: Index number of model in a community model @return Nothing ''' # Save the genome ID (used for messages and temporary file names). self.genomeId = genomeId self.communityIndex = communityIndex # Get the configuration variables. serviceName = os.environ.get('KB_SERVICE_NAME', 'ProbModelSEED') cfg = ConfigParser() cfg.read(os.path.join(os.environ.get('KB_TOP'), 'deployment.cfg')) self.config = dict() for nameval in cfg.items(serviceName): self.config[nameval[0]] = nameval[1] # Use the context from the server or build a context when used outside of a server. if context is not None: self.ctx = context else: self.ctx = dict() self.ctx['client_ip'] = '127.0.0.1' self.ctx['user_id'] = '-' self.ctx['module'] = serviceName self.ctx['method'] = '-' self.ctx['call_id'] = '-' # Create a logger. self.logger = log.log(serviceName, ip_address=True, authuser=True, module=True, method=True, call_id=True, logfile=self.config['mlog_log_file']) self.logger.set_log_level(int(self.config['mlog_log_level'])) # Create a ProbAnnotationParser object for working with the static database files. self.dataParser = ProbAnnotationParser(self.config) # Get the static database files. If the files do not exist and they are downloaded # from Shock, it can take a few minutes before they are ready. self.dataParser.getDatabaseFiles(self.logger, '') # Create a work directory for storing temporary files. if not os.path.exists(self.config['work_dir']): os.makedirs(self.config['work_dir'], 0775) self.workFolder = tempfile.mkdtemp(dir=self.config['work_dir'], prefix='') return
config = dict() for nameval in cfg.items(serviceName): config[nameval[0]] = nameval[1] # Create a logger. logger = log.log(serviceName, ip_address=True, authuser=True, module=True, method=True, call_id=True, logfile=config['mlog_log_file']) logger.set_log_level(int(config['mlog_log_level'])) # Create a ProbAnnotationParser object for working with the static data files. dataParser = ProbAnnotationParser(config) # Load the static data files from Shock. if args.action == 'load': print 'Started loading data files from Shock ...' dataParser.writeStatusFile('running') try: dataParser.loadDatabaseFiles(logger) dataParser.writeStatusFile('ready') print 'Finished loading data files' except: dataParser.writeStatusFile('failed') print 'Failed to load static data files from Shock' traceback.print_exc(file=sys.stderr) exit(1)