How to load ditz issues into python

Ditz is a fantastic distributed bug tracking system written in Ruby.

Here’s some code that you can use to load some ditz issues into a python interpreter. You need to install my pitz project first though.


>>> from pitz.junkyard.ditzloader import *
>>> from glob import glob
>>> issue_file_path = glob('../.ditz/issue-*.yaml')[0]
>>> import yaml
>>> issue = yaml.load(open(issue_file_path))
>>> issue.title
'Distribute reports by email'
>>> print issue.desc
Somehow allow people to sign up for report subscriptions.


So when new reports come out, they get updated. Maybe I can use
RSS feeds to hold the reports.
>>> print issue.log_events
[[datetime.datetime(2008, 9, 2, 17, 47, 44, 549355), 'Matthew Wilson ', 'created', ''], [datetime.datetime(2008, 9, 2, 19, 18, 3, 286902), 'Matthew Wilson ', 'assigned to release 3.5.1 from unassigned', ''], [datetime.datetime(2008, 9, 4, 18, 27, 19, 571991), 'Matthew Wilson ', 'unassigned from release 3.5.1', '']]

That above just showed how to read the ditz issue. I’m having trouble updating the issue and then saving it in a format that ditz can still read. Updating the ditz issue and saving it out again is easy:


>>> issue.title = 'Distribute reports by email or RSS'
>>> open(issue_file_path, 'w').write(yaml.dump(issue))

But when I try to load it with ditz, I get this error:

$ ditz show 1209b
/home/matt/checkouts/ditz/lib/ditz/model-objects.rb:124:in `sort_by': comparison of String with Time failed (ArgumentError)
from /home/matt/checkouts/ditz/lib/ditz/model-objects.rb:124:in `assign_issue_names!'
from /home/matt/checkouts/ditz/lib/ditz/model-objects.rb:51:in `issues='
from /home/matt/checkouts/ditz/lib/ditz/file-storage.rb:21:in `load'
from /home/matt/checkouts/ditz/bin/ditz:165

I compared my dumped file to the original ruby file and found that python wrote dates out like this:

>>> print yaml.dump(issue.creation_time)
2008-09-02 17:47:43.268059

But in the ruby yaml files, the dates look like this:

$ grep creation_time ../../../.ditz/issue-1209b17b64335383a710ccadf10b74c3401dbcb2.yaml
creation_time: 2008-09-02 17:47:43.268059 Z

That trailing Z seems important.

Also, python and ruby seem to write out lists differently. Here’s how python dumped a list of lists:

>>> print yaml.dump(issue.log_events)
- [!!timestamp '2008-09-02 17:47:44.549355', Matthew Wilson , created,
'']
- [!!timestamp '2008-09-02 19:18:03.286902', Matthew Wilson , assigned
to release 3.5.1 from unassigned, '']
- [!!timestamp '2008-09-04 18:27:19.571991', Matthew Wilson , unassigned
from release 3.5.1, '']

But the same data dumped by ruby looks like:

log_events:
- - 2008-09-02 17:47:44.549355 Z
- Matthew Wilson
- created
- ""
- - 2008-09-02 19:18:03.286902 Z
- Matthew Wilson
- assigned to release 3.5.1 from unassigned
- ""
- - 2008-09-04 18:27:19.571991 Z
- Matthew Wilson
- unassigned from release 3.5.1
- ""

So, there’s clearly some more work for me (or you, this is an open-source project) to do.

6 thoughts on “How to load ditz issues into python

  1. You can make the YAML dump much nicer with a few settings..

    Try something like
    yaml.safe_dump(data, default_flow_style = False, allow_unicode = True)

    its quite a while since I looked at this – but if I remember this makes the output YAML a bit more user friendly (though I didn't have datetime instances in my dump I believe).

    Good luck.
    Mark

  2. It's the ISO 8601 date format. The trailing Z indicates the time is in UTC; lack of it doesn't say anything about the timezone.

    I've had a brief brush with YAML. It has more than one way to express various data structures. If both your YAML generator and the Ditz YAML parser implement the spec in the same way, this shouldn't cause any problems, in theory.

    YAML tried to be both human-friendly and simpler than XML. I personally think it failed on both counts.

  3. Mark — thanks for the tip. I can't use safe_dump on a complex object, but default_flow_style=False helps a lot. Now I need to know how to make my datetime object with a time zone.

  4. That trailing Z seems important.Also, python and ruby seem to write out lists differently. Here’s how python dumped a list of lists:>>> print yaml.dump(issue.log_events)
    – [!!timestamp '2008-09-02 17:47:44.549355', Matthew Wilson <[email protected]>, created,
    '']- [!!timestamp '2008-09-02 19:18:03.286902', Matthew Wilson <[email protected]>, assignedto release 3.5.1 from unassigned, '']
    – [!!timestamp '2008-09-04 18:27:19.571991', thrift savings plan Matthew Wilson <[email protected]>, unassigned
    from release 3.5.1, '']But the same data dumped by ruby looks like:

Comments are closed.