source: trunk/lib/Node.cc @ 343

Last change on this file since 343 was 343, checked in by Peter Johansson, 16 years ago

refs #169

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1// $Id: Node.cc 343 2007-05-19 13:58:19Z 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 <iostream>
35#include <sstream>
36
37namespace theplu{
38namespace svndigest{
39
40  std::string Node::project_=std::string();
41
42  Node::Node(const u_int level, const std::string& path, 
43             const std::string& local_path)
44    : level_(level), path_(path), stats_(path), 
45      svninfo_(path)
46  { 
47    SVNproperty property(path);
48    binary_=property.binary();
49    svndigest_ignore_=property.svndigest_ignore();
50    if (Node::project_==std::string()) // no root directory in local path
51      Node::project_ = file_name(path);
52    else if (local_path.empty())
53      local_path_ = file_name(path);
54    else
55      local_path_ = local_path + "/" + file_name(path);
56  }
57
58
59  bool Node::dir(void) const
60  {
61    return false;
62  }
63
64
65  void Node::html_tablerow(std::ostream& os, 
66                           const std::string& css_class,
67                           const std::string& user) const
68  {
69    os << "<tr class=\"" << css_class << "\">\n"
70       << "<td class=\"" << node_type() << "\">";
71    if (svndigest_ignore())
72      os << name() << " (<i>svndigest:ignore</i>)";
73    else if (binary())
74      os << name() << " (<i>binary</i>)";
75    // there is no output for nodes when user has zero contribution
76    else if (user!="all" && !stats_.lines(user))
77      os << name();
78    else
79      os << anchor(href(), name()); 
80    os << "</td>\n"; 
81    if (user=="all") {
82      os << "<td>" << stats_.lines() << "</td>\n"
83         << "<td>" << stats_.code() << "</td>\n"
84         << "<td>" << stats_.comments() << "</td>\n"
85         << "<td>" << stats_.empty() << "</td>\n";
86    }
87    else {
88      os << "<td>" << stats_.lines(user); 
89      if (stats_.lines(user)) 
90        os << " (" << percent(stats_.lines(user),stats_.lines()) << "%)"; 
91      os << "</td>\n";
92      os << "<td>" << stats_.code(user); 
93      if (stats_.code(user)) 
94        os << " (" << percent(stats_.code(user),stats_.code()) << "%)"; 
95      os << "</td>\n";
96      os << "<td>" << stats_.comments(user); 
97      if (stats_.comments(user)) 
98        os << " (" << percent(stats_.comments(user),stats_.comments()) << "%)"; 
99      os << "</td>\n";
100      os << "<td>" << stats_.empty(user); 
101      if (stats_.empty(user)) 
102        os << " (" << percent(stats_.empty(user),stats_.empty()) << "%)"; 
103      os << "</td>\n";
104
105    }
106    os << "<td>" << trac_revision(stats_.last_changed_rev()) << "</td>\n"
107       << "<td>" << author() << "</td>\n"
108       << "</tr>\n";
109  }
110
111
112  std::string Node::output_dir(void) const
113  {
114    return output_dir_;
115  }
116
117
118  void Node::path_anchor(std::ostream& os) const
119  {
120
121    os << "<h2 class=\"path\">\n";
122    std::vector<std::string> words;
123    words.reserve(level_+1);
124    std::string word;
125    words.push_back(Node::project_);
126    std::stringstream ss(local_path());
127    while(getline(ss,word,'/'))
128      if (!word.empty()) // ignore double slash in path
129        words.push_back(word);
130    if (words.size()==1)
131      os << anchor("index.html", Node::project_,0, "View " + Node::project_);
132    else {
133      for (size_t i=0; i<words.size()-1; ++i){
134        os << anchor("index.html", words[i], level_-i, "View " + words[i]);
135        os << "<span class=\"sep\">/</span>\n";
136      }
137      os << anchor(href(), words.back(), level_+2-words.size(), 
138             "View " + words.back()); 
139    }
140    os << "\n</h2>\n";
141  }
142
143
144  void Node::print(const bool verbose) const
145  {
146    if (ignore())
147      return;
148    if (verbose)
149      std::cout << "Printing output for " << path_ << std::endl;
150    SVNlog log(path_);
151    print_core("all", "total", log);
152    print_core("all", "code", log);
153    print_core("all", "comments", log);
154    print_core("all", "empty", log);
155
156    for (std::set<std::string>::const_iterator i = stats_.authors().begin();
157         i!=stats_.authors().end(); ++i) {
158      print_core(*i, "total", log);
159      print_core(*i, "code", log);
160      print_core(*i, "comments", log);
161      print_core(*i, "empty", log);
162    }
163   
164    print_core(verbose);
165  }
166
167
168  void Node::print_author_summary(std::ostream& os, std::string line_type,
169                                  const SVNlog& log) const
170  { 
171    os << "<h4>Author Summary</h4>";
172    os << "<table class=\"listings\">\n";
173    os << "<thead>";
174    os << "<tr>\n";
175    os << "<th>Author</th>\n";
176    os << "<th>Lines</th>\n";
177    os << "<th>Code</th>\n";
178    os << "<th>Comments</th>\n";
179    os << "<th>Other</th>\n";
180    os << "<th>Revision</th>\n";
181    os << "<th>Date</th>\n";
182    os << "</tr>\n</thead>\n";
183    os << "<tbody>";
184
185    std::string color("light");
186    if (!dir()) {
187      os << "<tr class=\"" << color << "\">\n";
188      os << "<td class=\"directory\" colspan=\"5\">";
189      os << anchor("index.html", "../");
190      os << "</td>\n</tr>\n";
191    }
192
193    // print authors
194    const std::string timefmt("%e/%m/%y %H:%M:%S");
195    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
196         i!=stats_.authors().end(); ++i){
197      if (color=="dark")
198        color="light";
199      else
200        color="dark";
201      os << "<tr class=\"" << color << "\"><td>"; 
202      if (dir())
203        if (local_path().empty())
204          os << anchor(*i+"/"+line_type+"/index.html"
205                       ,*i, level_+2, "View statistics for "+*i); 
206        else
207          os << anchor(*i+"/"+line_type+"/"+local_path()+"/index.html"
208                       ,*i, level_+2, "View statistics for "+*i); 
209      else
210        os << anchor(*i+"/"+line_type+"/"+local_path()+".html"
211                     ,*i, level_+2, "View statistics for "+*i); 
212      os << "</td><td>" << stats_.lines(*i)
213         << "</td><td>" << stats_.code(*i)
214         << "</td><td>" << stats_.comments(*i)
215         << "</td><td>" << stats_.empty(*i);
216      if (log.exist(*i)) {
217        Commitment lc(log.latest_commit(*i));
218        os << "</td>" << "<td>" << trac_revision(lc.revision()) 
219           << "</td>" << "<td>" << lc.date()(timefmt);
220      }
221      else {
222        os << "</td>" << "<td>N/A"
223           << "</td>" << "<td>N/A";
224      }
225      os << "</td></tr>\n";
226    }
227
228    os << "<tr class=\"" << color << "\">\n";
229    os << "<td>"; 
230    if (dir())
231      if (local_path().empty())
232        os << anchor("all/"+line_type+"/index.html"
233                     ,"Total", level_+2, "View statistics for all"); 
234      else
235        os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
236                     ,"Total", level_+2, "View statistics for all"); 
237    else
238      os << anchor("all/"+line_type+"/"+local_path()+".html"
239                   ,"Total", level_+2, "View statistics for all"); 
240    os << "</td>\n";
241    os << "<td>" << stats_.lines() << "</td>\n";
242    os << "<td>" << stats_.code() << "</td>\n";
243    os << "<td>" << stats_.comments() << "</td>\n";
244    os << "<td>" << stats_.empty() << "</td>\n";
245    Commitment lc(log.latest_commit());
246    os << "<td>" << trac_revision(lc.revision()) << "</td>\n";
247    os << "<td>" << lc.date()(timefmt)<< "</td>\n";
248    os << "</tr>\n";
249    os << "</table>\n";
250
251  }
252
253 
254  std::string Node::url(void) const
255  {
256    return svninfo_.url();
257  }
258
259}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.