class MongoHandler(logging.Handler): """ Custom log handler Logs all messages to a mongo collection. This handler is designed to be used with the standard python logging mechanism. """ @classmethod def to(cls, db, collection, host='localhost', port=None, level=logging.NOTSET): """ Create a handler for a given """ return cls(Connection(host, port)[db][collection], level) def __init__(self, collection, db='mongolog', host='localhost', port=None, level=logging.NOTSET): """ Init log handler and store the collection handle """ logging.Handler.__init__(self, level) if (type(collection) == str): self.collection = Connection(host, port)[db][collection] else: self.collection = collection self.collection.ensure_index([("time", -1)]) self.collection.ensure_index([("levelname", 1), ("time", -1)]) self.formatter = MongoFormatter() def emit(self, record): """ Store the record to the collection. Async insert """ try: self.collection.save(self.format(record)) except InvalidDocument, e: logging.error("Unable to save log record: %s", e.message, exc_info=True)
class MongoHandler(logging.Handler): """ Custom log handler Logs all messages to a mongo collection. This handler is designed to be used with the standard python logging mechanism. """ @classmethod def to(cls, db, collection, host='localhost', port=None, level=logging.NOTSET): """ Create a handler for a given """ return cls(Connection(host, port)[db][collection], level) def __init__(self, collection, db='mongolog', host='localhost', port=None, level=logging.NOTSET): """ Init log handler and store the collection handle """ logging.Handler.__init__(self, level) if (type(collection) == str): self.collection = Connection(host, port)[db][collection] else: self.collection = collection self.formatter = MongoFormatter() def emit(self, record): """ Store the record to the collection. Async insert """ try: self.collection.save(self.format(record)) except InvalidDocument, e: logging.error("Unable to save log record: %s", e.message, exc_info=True)
'b7':b7, 'ae2':ae2, 'be2':be2, 'ae3':ae3, 'be3':be3, 'ae5':ae5, 'be5':be5, 'ae7':ae7, 'be7':be7, 'coeffs':coeffs, 'cond':cond } #index = 1 #is_new = True #holdfield = '' #for field in fields.find({'degree': d, # 'signature': data['signature'], # 'disc_abs_key': dstr}): # index += 1 # if field['coeffs'] == data['coeffs']: # holdfield = field # is_new = False # break #if is_new: #print "new field" #label = base_label(d, sig[0], absD, index) #info = {'label': label} hgm.save(data)
# for F in li[0:1]: count += 1 print "%d of %d: %s" % (count, tot, F) degree, weight, A, B, hodge, gal2, gal3, gal5, gal7 = F Astr = '.'.join([str(x) for x in A]) Bstr = '.'.join([str(x) for x in B]) label = "A%s_B%s" % (Astr, Bstr) data = { 'label': label, 'degree': degree, 'weight': weight, 'A': A, 'B': B, 'hodge': hodge, 'gal2': gal2, 'gal3': gal3, 'gal5': gal5, 'gal7': gal7 } is_new = True for field in hgm.find({'label': label}): is_new = False break if is_new: print "new family" hgm.save(data) else: print "Have this one"
data = { "degree": d, "signature": sig, "discriminant": D, "coefficients": coeffs, "class_number": h, "class_group": cyc, "galois_group": GG, } index = 1 is_new = True for field in fields.find({"degree": d, "signature": sig, "discriminant": D}): index += 1 if field["coefficients"] == coeffs: is_new = False break if is_new: print "new field" label = base_label(d, sig[0], absD, index) info = {"label": label} info.update(data) print "entering %s into database" % info fields.save(info) else: print "field already in database" if time.time() - t > 5: print "\t", label t = time.time()
'coefficients': coeffs, 'class_number': h, 'class_group': cyc, 'galois_group': GG } index = 1 is_new = True for field in fields.find({ 'degree': d, 'signature': sig, 'discriminant': D }): index += 1 if field['coefficients'] == coeffs: is_new = False break if is_new: print "new field" label = base_label(d, sig[0], absD, index) info = {'label': label} info.update(data) print "entering %s into database" % info fields.save(info) else: print "field already in database" if time.time() - t > 5: print "\t", label t = time.time()
'cyc': cyc, 'ab': ab, 'solv': solv, 'prim': prim, 'parity': gal[2], 'order': gal[1], 'name': gal[4], 'auts': gal[3], 'repns': gal[6], 'resolve': gal[5], 'subs': gal[7], 'pretty': pretty } label = base_label(n, t) group = groups.find_one({'label': label}) if group: print "old group" if 'pretty' in group: del data['pretty'] group.update(data) print "entering %s" % group groups.save(group) else: print "new group" info = {'label': label} info.update(data) print "entering %s into database" % info groups.save(info)
'hw': hw, 'gms': gms, 'aut': aut, 'galT': galT } index = 1 is_new = True holdfield = {} for field in fields.find({'p': p, 'n': n, 'c': c}): index += 1 if field['coeffs'] == coeffs: is_new = False holdfield = field break if is_new: print "new field" label = base_label(p, n, c, index) info = {'label': label} info.update(data) print "entering %s into database" % info fields.save(info) else: holdfield.update(data) print "field already in database, updating with %s" % holdfield fields.save(holdfield) # if time.time() - t > 5: # print "\t", label # t = time.time()
'aut': aut, 'galT': galT } index = 1 is_new = True holdfield = {} for field in fields.find({'p': p, 'n': n, 'c': c}): index += 1 if field['coeffs'] == coeffs: is_new = False holdfield = field break if is_new: print "new field" label = base_label(p, n, c, index) info = {'label': label} info.update(data) print "entering %s into database" % info fields.save(info) else: holdfield.update(data) print "field already in database, updating with %s" % holdfield fields.save(holdfield) # if time.time() - t > 5: # print "\t", label # t = time.time()
'cyc': cyc, 'ab': ab, 'solv': solv, 'prim': prim, 'parity': gal[2], 'order': gal[1], 'name': gal[4], 'auts': gal[3], 'repns': gal[6], 'resolve': gal[5], 'subs': gal[7], 'pretty': pretty } label = base_label(n, t) group = groups.find_one({'label': label}) if group: print "old group" if 'pretty' in group: del data['pretty'] group.update(data) print "entering %s" % group groups.save(group) else: print "new group" info = {'label': label} info.update(data) print "entering %s into database" % info groups.save(info)