source: trunk/lib/Node.cc @ 274

Last change on this file since 274 was 274, checked in by Peter Johansson, 14 years ago

support for Trac. Fixes #125. Also added a config file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.5 KB
Line 
1// $Id: Node.cc 274 2007-05-02 09:05:55Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Peter Johansson
6
7  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "Node.h"
26#include "html_utility.h"
27#include "SVNlog.h"
28#include "SVNproperty.h"
29#include "utility.h"
30
31#include <cassert>
32#include <ctime>
33#include <fstream>
34#include <sstream>
35
36namespace theplu{
37namespace svndigest{
38
39  std::string Node::project_=std::string();
40
41  Node::Node(const u_int level, const std::string& path, 
42             const std::string& local_path)
43    : level_(level), path_(path), stats_(path), 
44      svninfo_(path)
45  { 
46    SVNproperty property(path);
47    binary_=property.binary();
48    svndigest_ignore_=property.svndigest_ignore();
49    if (Node::project_==std::string()) // no root directory in local path
50      Node::project_ = file_name(path);
51    else if (local_path.empty())
52      local_path_ = file_name(path);
53    else
54      local_path_ = local_path + "/" + file_name(path);
55  }
56
57
58  bool Node::dir(void) const
59  {
60    return false;
61  }
62
63
64  void Node::path_anchor(std::ostream& os) const
65  {
66
67    os << "<h2 class=\"path\">\n";
68    std::vector<std::string> words;
69    words.reserve(level_+1);
70    std::string word;
71    words.push_back(Node::project_);
72    std::stringstream ss(local_path());
73    while(getline(ss,word,'/'))
74      if (!word.empty()) // ignore double slash in path
75        words.push_back(word);
76    if (words.size()==1)
77      os << anchor("index.html", Node::project_,0, "View " + Node::project_);
78    else {
79      for (size_t i=0; i<words.size()-1; ++i){
80        os << anchor("index.html", words[i], level_-i, "View " + words[i]);
81        os << "<span class=\"sep\">/</span>\n";
82      }
83      os << anchor(href(), words.back(), level_+2-words.size(), 
84             "View " + words.back()); 
85    }
86    os << "\n</h2>\n";
87  }
88
89
90  void Node::html_tablerow(std::ostream& os, 
91                           const std::string& css_class,
92                           const std::string& user) const
93  {
94    os << "<tr class=\"" << css_class << "\">\n"
95       << "<td class=\"" << node_type() << "\">";
96    if (svndigest_ignore())
97      os << name() << " (<i>svndigest:ignore</i>)";
98    else if (binary())
99      os << name() << " (<i>binary</i>)";
100    // there is no output for nodes when user has zero contribution
101    else if (user!="all" && !stats_.lines(user))
102      os << name();
103    else
104      os << anchor(href(), name()); 
105    os << "</td>\n"; 
106    if (user=="all") {
107      os << "<td>" << stats_.lines() << "</td>\n"
108         << "<td>" << stats_.code() << "</td>\n"
109         << "<td>" << stats_.comments() << "</td>\n"
110         << "<td>" << stats_.empty() << "</td>\n";
111    }
112    else {
113      os << "<td>" << stats_.lines(user) << "</td>\n"
114         << "<td>" << stats_.code(user) << "</td>\n"
115         << "<td>" << stats_.comments(user) << "</td>\n"
116         << "<td>" << stats_.empty(user) << "</td>\n";
117    }
118    os << "<td>" << trac_revision(stats_.last_changed_rev()) << "</td>\n"
119       << "<td>" << author() << "</td>\n"
120       << "</tr>\n";
121  }
122
123
124  void Node::print(const bool verbose) const
125  {
126    if (ignore())
127      return;
128    if (verbose)
129      std::cout << "Printing output for " << path_ << std::endl;
130    SVNlog log(path_);
131    print_core("all", "total", log);
132    print_core("all", "code", log);
133    print_core("all", "comments", log);
134    print_core("all", "empty", log);
135
136    for (std::set<std::string>::const_iterator i = stats_.authors().begin();
137         i!=stats_.authors().end(); ++i) {
138      print_core(*i, "total", log);
139      print_core(*i, "code", log);
140      print_core(*i, "comments", log);
141      print_core(*i, "empty", log);
142    }
143   
144    print_core(verbose);
145  }
146
147
148  void Node::print_author_summary(std::ostream& os, std::string line_type,
149                                  const SVNlog& log) const
150  { 
151    os << "<h4>Author Summary</h4>";
152    os << "<table class=\"listings\">\n";
153    os << "<thead>";
154    os << "<tr>\n";
155    os << "<th>Author</th>\n";
156    os << "<th>Lines</th>\n";
157    os << "<th>Code</th>\n";
158    os << "<th>Comments</th>\n";
159    os << "<th>Other</th>\n";
160    os << "<th>Revision</th>\n";
161    os << "<th>Date</th>\n";
162    os << "</tr>\n</thead>\n";
163    os << "<tbody>";
164
165    std::string color("light");
166    if (!dir()) {
167      os << "<tr class=\"" << color << "\">\n";
168      os << "<td class=\"directory\" colspan=\"5\">";
169      os << anchor("index.html", "../");
170      os << "</td>\n</tr>\n";
171    }
172
173    // print authors
174    const std::string timefmt("%e/%m/%y %H:%M:%S");
175    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
176         i!=stats_.authors().end(); ++i){
177      if (color=="dark")
178        color="light";
179      else
180        color="dark";
181      os << "<tr class=\"" << color << "\"><td>"; 
182      if (dir())
183        if (local_path().empty())
184          os << anchor(*i+"/"+line_type+"/index.html"
185                       ,*i, level_+2, "View statistics for "+*i); 
186        else
187          os << anchor(*i+"/"+line_type+"/"+local_path()+"/index.html"
188                       ,*i, level_+2, "View statistics for "+*i); 
189      else
190        os << anchor(*i+"/"+line_type+"/"+local_path()+".html"
191                     ,*i, level_+2, "View statistics for "+*i); 
192      os << "</td><td>" << stats_.lines(*i)
193         << "</td><td>" << stats_.code(*i)
194         << "</td><td>" << stats_.comments(*i)
195         << "</td><td>" << stats_.empty(*i);
196      Commitment lc(log.latest_commit(*i));
197      os << "</td>" << "<td>" << trac_revision(lc.revision()) 
198         << "</td>" << "<td>" << lc.date()(timefmt)
199         << "</td></tr>\n";
200    }
201
202    os << "<tr class=\"" << color << "\">\n";
203    os << "<td>"; 
204    if (dir())
205      os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
206                   ,"Total", level_+2, "View statistics for all"); 
207    else
208      os << anchor("all/"+line_type+"/"+local_path()+".html"
209                   ,"Total", level_+2, "View statistics for all"); 
210    os << "</td>\n";
211    os << "<td>" << stats_.lines() << "</td>\n";
212    os << "<td>" << stats_.code() << "</td>\n";
213    os << "<td>" << stats_.comments() << "</td>\n";
214    os << "<td>" << stats_.empty() << "</td>\n";
215    Commitment lc(log.latest_commit());
216    os << "<td>" << trac_revision(lc.revision()) << "</td>\n";
217    os << "<td>" << lc.date()(timefmt)<< "</td>\n";
218    os << "</tr>\n";
219    os << "</table>\n";
220
221  }
222
223}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.