def load_or_save_patterns(self, patterns=None): ''' Get (if patterns is None) or Set the patterns in the database in & out = dictionary ''' key = 'api.textseg.%s.patterns' % slugify(unicode(self.namespace)) if patterns: KeyVal.setjs(key, patterns) else: patterns = KeyVal.getjs(key) self.patterns = patterns return patterns
def write_state(self, state): state['updated'] = datetime.now() state['progress'] = 1.0 * sum([idx['progress'] for idx in state['indexes'].values()]) / len(state['indexes'].keys()) state['state'] = None for idx in state['indexes'].values(): if idx['progress'] == 0.0: idx['state'] = 'queued' if idx['progress'] > 0.0: idx['state'] = 'indexing' if idx['progress'] == 1.0: idx['state'] = 'indexed' if state['state'] not in [None, idx['state']]: state['state'] = 'indexing' else: state['state'] = idx['state'] # json conversion doesn't understand python dates self.convert_state_dates_to_strings(state) # print '-' * 20 # print state KeyVal.setjs('indexer', state) self.convert_state_dates_to_objects(state)
def write_state(self, state): state["updated"] = datetime.now() state["progress"] = ( 1.0 * sum([idx["progress"] for idx in state["indexes"].values()]) / len(state["indexes"].keys()) ) state["state"] = None for idx in state["indexes"].values(): if idx["progress"] == 0.0: idx["state"] = "queued" if idx["progress"] > 0.0: idx["state"] = "indexing" if idx["progress"] == 1.0: idx["state"] = "indexed" if state["state"] not in [None, idx["state"]]: state["state"] = "indexing" else: state["state"] = idx["state"] # json conversion doesn't understand python dates self.convert_state_dates_to_strings(state) # print '-' * 20 # print state KeyVal.setjs("indexer", state) self.convert_state_dates_to_objects(state)
def write_state(self, state): state['updated'] = datetime.now() state['progress'] = 1.0 * sum([ idx['progress'] for idx in state['indexes'].values() ]) / len(state['indexes'].keys()) state['state'] = None for idx in state['indexes'].values(): if idx['progress'] == 0.0: idx['state'] = 'queued' if idx['progress'] > 0.0: idx['state'] = 'indexing' if idx['progress'] == 1.0: idx['state'] = 'indexed' if state['state'] not in [None, idx['state']]: state['state'] = 'indexing' else: state['state'] = idx['state'] # json conversion doesn't understand python dates self.convert_state_dates_to_strings(state) # print '-' * 20 # print state KeyVal.setjs('indexer', state) self.convert_state_dates_to_objects(state)
def read_state(self): ret = KeyVal.getjs("indexer") self.convert_state_dates_to_objects(ret) return ret
def clear_state(self): KeyVal.setjs('indexer', {})
def read_state(self): ret = KeyVal.getjs('indexer') self.convert_state_dates_to_objects(ret) return ret