def update_trac_components(self, group, env): if self.dummy_run: self.note("Would update Trac components for group '%s'" % group.acronym) else: self.note("Updating Trac componets for group '%s'" % group.acronym) components = Component.select(env) comp_names = [c.name for c in components] group_docs = group.document_set.filter(states__slug='active', type_id='draft').distinct() group_comp = [] for doc in group_docs: if not doc.name.startswith('draft-'): self.log( "While adding components: unexpectd %s group doc name: %s" % (group.acronym, doc.name)) continue name = doc.name[len('draft-'):] if name.startswith('ietf-'): name = name[len('ietf-'):] elif name.startswith('irtf-'): name = name[len('ietf-'):] if name.startswith(group.acronym + '-'): name = name[len(group.acronym + '-'):] group_comp.append(name) if not name in comp_names and not doc.name in comp_names: self.note(" Group draft: %s" % doc.name) self.note(" Adding component %s" % name) comp = Component(env) comp.name = name comp.owner = "*****@*****.**" % doc.name comp.insert()
def post_process_request(self, req, template, data, content_type): if req.path_info.startswith('/ticket'): ticket = data['ticket'] # add custom fields to the ticket template context data data['milestones'] = self._sorted_milestones() data['components'] = [c.name for c in Component.select(self.env)] data['split_options'] = self._ticket_split_options(ticket) data['split_history'] = self._ticket_split_history(ticket) return template, data, content_type
def process_admin_request(self, req, cat, page, path_info): envs = DatamoverSystem(self.env).all_environments() components = [c.name for c in TicketComponent.select(self.env)] if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('component', 'all'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy':'Copied', 'move':'Moved'}[action] comp_filter = None if source_type == 'component': in_components = req.args.getlist('component') comp_filter = lambda c: c in in_components elif source_type == 'all': comp_filter = lambda c: True try: sel_components = [c for c in components if comp_filter(c)] dest_db = _open_environment(dest).get_db_cnx() for comp in sel_components: copy_component(self.env, dest, comp, dest_db) dest_db.commit() if action == 'move': for comp in sel_components: TicketComponent(self.env, comp).delete() req.hdf['datamover.message'] = '%s components %s'%(action_verb, ', '.join(sel_components)) except TracError, e: req.hdf['datamover.message'] = "An error has occured: \n"+str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)
def test_exists(self): """ http://trac.edgewall.org/ticket/4247 """ for c in Component.select(self.env): self.assertEqual(c.exists, True)
def process_admin_request(self, req, cat, page, path_info): components = [c.name for c in TicketComponent.select(self.env)] envs = DatamoverSystem(self.env).all_environments() if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('component', 'ticket', 'all', 'query'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy':'Copied', 'move':'Moved'}[action] # Double check the ticket number is actually a number if source_type == 'id': try: int(source) except ValueError: raise TracError('Value %r is not numeric'%source) self.log.debug('DatamoverTicketModule: Source is %s (%s)', source, source_type) query_string = { 'ticket': 'id=%s'%source, 'component': 'component=%s'%source, 'all': 'id!=0', 'query': source, }[source_type] try: # Find the ids we want ids = None if source_type == 'ticket': # Special case this pending #T4119 ids = [int(source)] else: self.log.debug('DatamoverTicketModule: Running query %r', query_string) ids = [x['id'] for x in Query.from_string(self.env, query_string).execute(req)] self.log.debug('DatamoverTicketModule: Results: %r', ids) dest_db = _open_environment(dest).get_db_cnx() for id in ids: copy_ticket(self.env, dest, id, dest_db) dest_db.commit() if action == 'move': for id in ids: Ticket(self.env, id).delete() if ids: req.hdf['datamover.message'] = '%s tickets %s'%(action_verb, ', '.join([str(n) for n in ids])) else: req.hdf['datamover.message'] = 'No tickets %s'%(action_verb.lower()) except TracError, e: req.hdf['datamover.message'] = "An error has occured: \n"+str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)
def remove_demo_components(self, group, env): for component in Component.select(env): if component.name.startswith('component'): component.delete()
def list_component_in_json(self): # stolen from trac.ticket.admin.py format: [(component,owner)] #components = [(c.name, c.owner) for c in TicketComponent.select(self.env)], [_('Name'), _('Owner')] components = [{'name':c.name,'owner':c.owner} for c in TicketComponent.select(self.env)] printout(json.dumps(components))
def process_request(self, req): name = req.args.get('name') if not (name == 'query'): id = req.args.get('id') if name == 'ticket': ticket = Ticket(self.env, id) comm_num = 0 attachment_num = len(self.get_attachments('ticket', id)) ticket_log = self.changeLog(id) for log in ticket_log: if log[2] == 'comment' and log[4]: comm_num += 1 data = {'ticket': ticket, 'comm_num': comm_num, 'attachment_num': attachment_num} return 'bh_emb_ticket.html', data, None elif name == 'milestone': ticket_num = len(get_tickets_for_milestone(self.env, milestone=id)) attachment_num = len(self.get_attachments('milestone', id)) data = {'milestone': Milestone(self.env, id), 'product': self.env.product, 'ticket_number': ticket_num, 'attachment_number': attachment_num } return 'bh_emb_milestone.html', data, None elif name == 'products': product = Product(self.env, {'prefix': id}) ticket_num = len(self.get_tickets_for_product(self.env, id)) product_env = ProductEnvironment(self.env, product.prefix) milestone_num = len(Milestone.select(product_env)) version_num = len(Version.select(product_env)) components = component.select(product_env) component_num = 0 for c in components: component_num += 1 data = {'product': product, 'ticket_num': ticket_num, 'owner': product.owner, 'milestone_num': milestone_num, 'version_num': version_num, 'component_num': component_num} return 'bh_emb_product.html', data, None elif name == 'query': qstr = req.query_string qstr = urllib.unquote(qstr).decode('utf8') if qstr=='': qstr = 'status!=closed' qresults = self.query(req, qstr) filters = qresults[0] tickets = qresults[1] data={'tickets': tickets, 'query': qstr, 'filters': filters} return 'bh_emb_query.html', data, None else: msg = "It is not possible to embed this resource." raise ResourceNotFound((msg), ("Invalid resource"))