~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to graph.py

  • Committer: Aaron Bentley
  • Date: 2005-09-23 00:02:14 UTC
  • mfrom: (189.1.2)
  • Revision ID: aaron.bentley@utoronto.ca-20050923000214-cb57e12afbd89378
Merged Meinel's HTML stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from dotgraph import Node, dot_output, invoke_dot, invoke_dot_aa, NoDot, NoRsvg
 
1
from dotgraph import Node, dot_output, invoke_dot, invoke_dot_aa, invoke_dot_html, NoDot, NoRsvg
2
2
from dotgraph import RSVG_OUTPUT_TYPES, DOT_OUTPUT_TYPES, Edge
3
3
from bzrlib.branch import Branch
4
4
from bzrlib.errors import BzrCommandError, NoCommonRoot, NoSuchRevision
10
10
import bzrlib.errors
11
11
import re
12
12
import os.path
 
13
import time
13
14
 
14
15
mail_map = {'aaron.bentley@utoronto.ca'     : 'Aaron Bentley',
15
16
            'abentley@panoramicfeedback.com': 'Aaron Bentley',
61
62
            new_ancestors[me][new_parent] = distance
62
63
    return new_ancestors    
63
64
 
64
 
def get_committer(rev_id, source):
 
65
def get_rev_info(rev_id, source):
 
66
    """Return the committer, message, and date of a revision."""
 
67
    committer = None
 
68
    message = None
 
69
    date = None
 
70
    if rev_id == 'null:':
 
71
        return None, 'Null Revision', None
65
72
    try:
66
 
        committer = short_committer(source.get_revision(rev_id).committer)
 
73
        rev = source.get_revision(rev_id)
67
74
    except NoSuchRevision:
68
75
        try:
69
76
            committer = '-'.join(rev_id.split('-')[:-2]).strip(' ')
70
77
            if committer == '':
71
 
                return None
 
78
                return None, None, None
72
79
        except ValueError:
73
 
            return None
 
80
            return None, None, None
 
81
    else:
 
82
        committer = short_committer(rev.committer)
 
83
        if rev.message is not None:
 
84
            message = rev.message.split('\n')[0]
 
85
        date = time.strftime('%Y-%m-%d', time.gmtime(rev.timestamp + (rev.timezone or 0)))
74
86
    if '@' in committer:
75
87
        try:
76
88
            committer = mail_map[committer]
80
92
        committer = committer_alias[committer]
81
93
    except KeyError:
82
94
        pass
83
 
    return committer
 
95
    return committer, message, date
84
96
 
85
97
class Grapher(object):
86
98
    def __init__(self, branch, other_branch=None):
111
123
            self.base = None
112
124
            self.m_history = []
113
125
 
114
 
    def get_timestamp(self, revision_id):
115
 
        try:
116
 
            return float(self.branch.get_revision(revision_id).timestamp)
117
 
        except NoSuchRevision:
118
 
            return None
119
 
 
120
126
    def dot_node(self, node, num):
121
127
        try:
122
128
            n_rev = self.n_history.index(node) + 1
157
163
            color = "#33ff99"
158
164
 
159
165
        label = [name]
160
 
        committer = get_committer(node, self.branch)
 
166
        committer, message, date = get_rev_info(node, self.branch)
161
167
        if committer is not None:
162
168
            label.append(committer)
163
169
 
164
 
        timestamp = self.get_timestamp(node)
165
 
        if timestamp is not None:
166
 
            date = datetime.fromtimestamp(timestamp)
167
 
            label.append("%d/%d/%d" % (date.year, date.month, date.day))
 
170
        if date is not None:
 
171
            label.append(date)
168
172
 
169
173
        if node in self.distances:
170
174
            rank = self.distances[node]
173
177
            rank = None
174
178
 
175
179
        d_node = Node("n%d" % num, color=color, label="\\n".join(label), 
176
 
                    rev_id=node, cluster=cluster)
 
180
                    rev_id=node, cluster=cluster, message=message,
 
181
                    date=date)
177
182
        d_node.rank = rank
178
183
 
179
184
        if node not in self.ancestors:
248
253
        my_file = file(filename, 'wb')
249
254
        for fragment in output:
250
255
            my_file.write(fragment)
 
256
    elif ext=='html':
 
257
        try:
 
258
            invoke_dot_html(output, filename)
 
259
        except NoDot, e:
 
260
            raise BzrCommandError("Can't find 'dot'.  Please ensure Graphviz"\
 
261
                " is installed correctly, or use --noantialias")
251
262
    elif not done:
252
263
        print "Unknown file extension: %s" % ext
253
264