def get_children(C, tid): from couchdb import Task qry = "select t.* from task_hierarchy th,tasks t where %s=any(th.path_info) and th.id<>%s and t.id=th.id" opts = (tid, tid) C.execute(qry, opts) rows = [t['contents'] for t in C.fetchall()] rt = [] for r in rows: r['created_at'] = datetime.strptime( r['created_at'].split('.')[0].split('Z')[0], "%Y-%m-%dT%H:%M:%S") t = Task(**r) rt.append(t) return rt
def notification_logic(P, C, tid, supress, notify): from couchdb import Task from pg import get_children, revfmt pns = get_pending_notifications(C, tid) print('got', len(pns), 'pending notifications.') for pn in pns: frev = revfmt(pn['sys_period'].lower, pn['sys_period'].upper) print('walking pending notification', frev) t = Task.get(C, pn['id']) notifs = parse(C, [t], rev=frev, supress=supress) print('walking', len(notifs), 'notifs') if notify: done = False for nt in notifs: done = t._notify(P, C, user='******', lc=nt) print('done=', done) print('inserting notification confirmation') qry = "insert into task_notifications (task_id,sys_period,created_at,details) values(%s,%s,now(),%s)" args = (t._id, pn['sys_period'], json.dumps(notifs, default=datahandler)) C.execute(qry, args) P.commit()
def imp(): for tfn,tid in [(tf,parse_fn(tf)['id']) for tf in get_fns()]: print tid #handle task t= get_task(tid,read=True) notifications = ask(t['meta'],'notifications',[]) #throw away, for now points = ask(t,'points',None) # throw away branches = ask(t['meta'],'branches',None) # throw away status = ask(t,'status') repobranch = ask(t,'repobranch',[]) links = ask(t,'links',[]) assignee = ask(t,'assigned to') creator = ask(t,'created by') summary = ask(t,'summary') created_at = ask(t,'created at') tags = ask(t,'tags') informed = ask(t,'informed',None) unstructured = ask(t,'unstructured') try: unstructured = unicode(unstructured,'utf-8') except: print type(unstructured),unstructured,'"%s"'%unstructured[10:15] raise try: td = Task.get(tid) if td: td.delete() except ResourceNotFound: pass td = Task(_id=tid, path=[int(tp) for tp in tid.split('/')], created_at=created_at, summary=summary, status=status, creator=creator, assignee=assignee, informed=informed, links=links, branches=repobranch, tags=tags, unstructured=unstructured ) #delete ignored meta keys for dk in ['commits_qty','branchlastcommits','lastcommits','commiters','last_commit']: if dk in t['meta']: del t['meta'][dk] #assert bogus keys are empty for ek in ['meta','created by ','points ','points','assigned to ','created at ','meta']: if ek in t: assert (not t[ek] or t[ek]=='None'),"%s = %s"%(ek,t[ek]) del t[ek] #delete ignored keys for dk in ['story','jpath','path','id','metadata']: del t[dk] if len(t): print dumps(t,indent=True,cls=PythonObjectEncoder); sys.exit(1) #handle journal jfn = tfn.replace('task.org','journal.org') j = read_journal(jfn) #ignored keys print len(j),'journal entries' je = [] for i in j: creator = ask(i,'creator') content = ask(i,'content') attrs = ask(i,'attrs') created_at = ask(i,'created at') assert i['tid']==tid for dk in ['rendered_content','tid']: del i[dk] if len(i): print dumps(j,indent=True,cls=PythonObjectEncoder); sys.exit(1) je.append({'creator':creator, 'content':content, 'attrs':attrs, 'created_at':created_at}) td.journal = je td.save(notify=False,user='******')
import datetime from couchdbkit import * from couchdbkit.designer import push from docs import get_fns,initvars,get_task,parse_fn,read_journal import config as cfg import sys import json initvars(cfg) from couchdb import Task,init_conn if __name__=='__main__': s,d = init_conn() tasks = Task.view('task/all') for t in tasks: #get rid of old id tasks here if len(t._id)==32: print t._id t.delete() continue t.path = [int(tp) for tp in t.path] t.save()
from __future__ import print_function import datetime from couchdbkit import * from couchdbkit.designer import push from docs import get_fns,initvars,get_task,parse_fn,read_journal import config as cfg import sys import json initvars(cfg) from couchdb import Task,init_conn if __name__=='__main__': s,d = init_conn() tasks = Task.view('task/all') for t in tasks: #get rid of old id tasks here if len(t._id)==32: print(t._id) t.delete() continue t.path = [int(tp) for tp in t.path] t.save()
def notifications(adm,tid): from couchdb import Task t = Task.get(tid) t._notify(user=adm)
def get_task(C, tid): from couchdb import Task C.execute("select contents from tasks where id=%s", (tid, )) c = C.fetchall()[0]['contents'] return Task(**c)