def runCommand(self, args, program, core): args = [ 'find', 'timers', '--inactive', '--with-ticket', '-i', args['id'], '-n', args['name'], '-p', args['project'], '-t', args['ticket'] ] args = program.parseArgs(args) timers = program.executeCommand(args) updatedTimers = [] for timer in timers: try: core.plugin.postTimer( projectId=timer.ticket.project.id, ticketId=timer.ticket.ticket_id, data=timer ) updatedTimers.append(timer.id) except: LOGGER.exception('Could not post timer.') if not updatedTimers: return values = { 'posted': True, } with autocommit(core.session) as session: session.query(Timer).filter(Timer.id.in_(updatedTimers)).update(values)
def sync(self): accountType = self.config.account.type accountUrl = self.config.account.url CoreLogger.info(strings['old_data'], accountType, accountUrl) self.session.execute('PRAGMA foreign_keys=OFF') # Prevent exceptions from destroying our foreign key support try: with autocommit(self.session) as session: # Truncate tables for new data, this is faster than merging session.query(Project).delete() session.query(Ticket).delete() CoreLogger.debug('Getting list of projects from remote') projects = self.plugin.listProjects() for project in projects: session.add(project) CoreLogger.debug( "Getting list of tickets for pid '%s' from remote", project.id) tickets = self.plugin.listTickets(project.id) for ticket in tickets: session.add(ticket) lastSynced = PersistentVar(name='internal.lastSynced', value=datetime.utcnow()) session.merge(lastSynced) except: CoreLogger.exception('Could not sync with remote source %s:%s', accountType, accountUrl) self.session.execute('PRAGMA foreign_keys=ON')
def sync(self): accountType = self.config.account.type accountUrl = self.config.account.url CoreLogger.info(strings['old_data'], accountType, accountUrl) self.session.execute('PRAGMA foreign_keys=OFF') # Prevent exceptions from destroying our foreign key support try: with autocommit(self.session) as session: # Truncate tables for new data, this is faster than merging session.query(Project).delete() session.query(Ticket).delete() CoreLogger.debug('Getting list of projects from remote') projects = self.plugin.listProjects() for project in projects: session.add(project) CoreLogger.debug("Getting list of tickets for pid '%s' from remote", project.id) tickets = self.plugin.listTickets(project.id) for ticket in tickets: session.add(ticket) lastSynced = PersistentVar( name='internal.lastSynced', value=datetime.utcnow() ) session.merge(lastSynced) except: CoreLogger.exception('Could not sync with remote source %s:%s', accountType, accountUrl) self.session.execute('PRAGMA foreign_keys=ON')
def runCommand(self, args, program, core): args = [ 'find', 'timers', '--inactive', '--with-ticket', '-i', args['id'], '-n', args['name'], '-p', args['project'], '-t', args['ticket'] ] args = program.parseArgs(args) timers = program.executeCommand(args) updatedTimers = [] for timer in timers: try: core.plugin.postTimer(projectId=timer.ticket.project.id, ticketId=timer.ticket.ticket_id, data=timer) updatedTimers.append(timer.id) except: LOGGER.exception('Could not post timer.') if not updatedTimers: return values = { 'posted': True, } with autocommit(core.session) as session: session.query(Timer).filter( Timer.id.in_(updatedTimers)).update(values)
def runCommand(self, args, program, core): session = Session(start=core.roundTime(datetime.utcnow())) timer = Timer(name=args['name'], ticket_id=args['ticket'], sessions=[session]) with autocommit(core.session) as sql: sql.add(timer) args = program.parseArgs(['show']) program.executeCommand(args) return timer
def runCommand(self, args, program, core): values = { Session.end: core.roundTime(datetime.utcnow()) } with autocommit(core.session) as session: session.query(Session).filter(Session.timer_id == args['id'])\ .filter(Session.end == None).update(values) args = program.parseArgs([ 'find', 'timers', '--id', str(args['id']) ]) return program.executeCommand(args)
def runCommand(self, args, program): with autocommit(program.session) as session: q = session.query(Timer).filter(Timer.name.like('%' + args['name'] + '%')) values = {} if args['start']: values[Timer.start] = args['start'] if args['end']: values[Timer.end] = args['end'] if args['ticket']: values[Timer.ticket_id] = args['ticket'] return q.update(values)
def runCommand(self, args, program, core): ''' Required. Perform the business logic associated with this command. You are given the args you added to the parser in addArguments as well as the program to run database commands, and access global data ''' timer = core.session.query(Timer).filter(Timer.id == args['id']).one() session = Session(timer_id=timer.id, start=core.roundTime(datetime.utcnow())) with autocommit(core.session) as sql: sql.add(session) args = program.parseArgs([ 'find', 'timers', '--id', str(args['id']) ]) return program.executeCommand(args)
def runCommand(self, args, program, core): ''' Required. Perform the business logic associated with this command. You are given the args you added to the parser in addArguments as well as the program to run database commands, and access global data ''' timer = core.session.query(Timer).filter(Timer.id == args['id']).one() session = Session(timer_id=timer.id, start=core.roundTime(datetime.utcnow())) with autocommit(core.session) as sql: sql.add(session) args = program.parseArgs(['find', 'timers', '--id', str(args['id'])]) return program.executeCommand(args)
def runCommand(self, args, program, core): with autocommit(core.session) as session: q = session.query(Timer).filter(Timer.id == args['id']) values = {} if args['start']: values[Timer.start] = args['start'] if args['end']: values[Timer.end] = args['end'] if args['ticket']: values[Timer.ticket_id] = args['ticket'] q.update(values) args = program.parseArgs(['find', 'timers', '--id', str(args['id'])]) return program.executeCommand(args)
def runCommand(self, args, program, core): with autocommit(core.session) as session: q = session.query(Timer).filter(Timer.id == args['id']) values = {} if args['start']: values[Timer.start] = args['start'] if args['end']: values[Timer.end] = args['end'] if args['ticket']: values[Timer.ticket_id] = args['ticket'] q.update(values) args = program.parseArgs([ 'find', 'timers', '--id', str(args['id']) ]) return program.executeCommand(args)
def runCommand(self, args, program): with autocommit(program.session) as session: values = { Session.end: program.roundTime(datetime.utcnow()) } remove_tuples = lambda row: row[0] ids = map(remove_tuples, session.query(Timer.id).filter( Timer.name.like('%' + args['name'] + '%')).all()) session.query(Session).filter(Session.timer_id.in_(ids))\ .filter(Session.end == None).update(values, 'fetch') args = program.parseArgs([ 'find', 'timers', '-n', args['name'] ]) return program.executeCommand(args)
def sync(self): CoreLogger.info(strings["old_data"], self.config.account.type, self.config.account.url) with autocommit(self.session) as session: project_ids = [] ticket_ids = [] session.query(Project).delete() session.query(Ticket).delete() projects = self.plugin.listProjects() for project in projects: project_ids.append(project.id) session.add(project) tickets = self.plugin.listTickets(project.id) for ticket in tickets: ticket_ids.append(ticket.id) session.add(ticket) lastSynced = PersistentVar(name="internal.lastSynced", value=datetime.utcnow()) session.merge(lastSynced)
def runCommand(self, args, program, core): with autocommit(core.session) as session: timer = session.query(Timer).filter(Timer.id == args['id']).filter(Timer.posted == False).one() session.query(Session).filter(Session.timer_id == timer.id).delete() session.delete(timer)
def runCommand(self, args, program, core): with autocommit(core.session) as session: timer = session.query(Timer).filter(Timer.id == args["id"]).filter(Timer.posted == False).one() session.query(Session).filter(Session.timer_id == timer.id).delete() session.delete(timer)