Re: How to add a message to an issue via roundup-admin?

Dan Tenenbaum <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.user
Message-ID <[email protected]>

----- Original Message -----
> From: "John P. Rouillard" <[email protected]>
> To: "Dan Tenenbaum" <[email protected]>
> Cc: [email protected]
> Sent: Friday, June 12, 2015 4:28:28 PM
> Subject: Re: [Roundup-users] How to add a message to an issue via roundup-admin?
> 
> In message
> <[email protected]>,
> Dan Tenenbaum writes:
> >> OK, I've written such a script. The only problem is, it doesn't
> >> work!
> >> The goal of it is to append a message to an existing issue. It
> >> does
> >> that, such that when I then retrieve the issue's messages, it
> >> shows
> >> me that it now has 2 messages whereas before it only had 1:
> >> 
> >> In [92]: db.issue.get(1, 'messages')
> >> Out[92]: ['1', '9']
> >> 
> >> However, when I look at issue1 in my browser it only shows one
> >> message, and if I go to
> >> 
> >> http://myhost.com/mytracker/msg9
> >> 
> >> it says there is no such message. But in the database I can see
> >> it:
> >> 
> >> In [93]: db.getnode('msg', 9)
> >> Out[93]:
> >> {'activity': <Date 2015-06-12.18:28:39.000>,
> >>  'actor': '1',
> >>  'author': '3',
> >>  'content': None,
> >>  'creation': <Date 2015-06-12.18:27:39.000>,
> >>  'creator': '1',
> >>  'date': <Date 2015-06-12.18:27:39.000>,
> >>  'files': [],
> >>  'inreplyto': None,
> >>  'messageid': '<[email protected]>',
> >>  'recipients': ['1', '3'],
> >>  'summary': 'hey\nho',
> >>  'type': None}
> >> 
> >> 
> >> So what is the script doing wrong?
> >> 
> >
> >One more clue: in my <tracker_home>/db/files/msg/0 directory there
> >is
> >not a msg9 file as I would expect but there is a msg9.tmp file with
> >the correct contents. If I rename it to msg9 it does not fix the
> >problem, the new message still does not show up attached to the
> >issue.
> 
> Yup I bet you are not commiting the change.
> 
> >> Thanks in advance! Here's the script.
> >> #!/usr/bin/env python
> >> 
> >> import sys
> >> from roundup import instance, hyperdb, date
> >> from roundup.date import Date
> >> 
> >> tracker_home = "/mytrackerhome" # conditionalize me!
> >> instance = instance.open(tracker_home)
> >> db = instance.open("admin") # make sure there is an admin user on
> >> production!
> >> 
> >> issue_id = 1 # parameterize me!
> >> 
> >> try:
> >>   issue = db.getnode("issue", issue_id)
> >> except IndexError:
> >>   print("No such issue!")
> >>   sys.exit(1)
> >> 
> >> username = "admin" # parameterize me
> >> 
> >> message = """
> >> hey
> >> ho
> >> """ # parameterize me
> >> 
> >> matching_users = db.user.filter(None, {"username": username})
> >> 
> >> if len(matching_users) == 0:
> >>   print("No such user!")
> >>   sys.exit(1)
> >> 
> >> userid = matching_users[0]
> >> 
> >> msg_id = db.msg.create(
> >>   author=str(userid),
> >>   date=Date('.'),
> >>   summary=message,
> >>   content=message
> >> )
> >> 
> >> messages = issue.get("messages")
> >> 
> >> messages.append(msg_id)
> >> 
> >> db.issue.set(str(issue_id), messages=messages)
> 
> I think you need a db.commit and db.close here.
> 
> See scripts/add-issue in the distribution which ends:
> 
> [...]
> try:
> 
>     # handle the message
>     messages = []
>     if message_text:
>         summary, x = mailgw.parseContent(message_text, 0, 0)
>         msg = db.msg.create(content=message_text, summary=summary,
>         author=uid,
>             date=date.Date())
>         messages = [msg]
> 
>     # now create the issue
>     db.issue.create(title=issue_title, priority=issue_priority,
>         messages=messages)
> 
>     db.commit()
> finally:
>     db.close()
> 


That was it. Thanks for the pointer to the example.
Dan

> 
> --
> 				-- rouilj
> John Rouillard
> ===========================================================================
> My employers don't acknowledge my existence much less my opinions.
> 

------------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.