1 | // $Id: NodePrinter.cc 1355 2011-05-15 23:16:05Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
5 | Copyright (C) 2009, 2010 Peter Johansson |
---|
6 | |
---|
7 | This file is part of svndigest, http://dev.thep.lu.se/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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | */ |
---|
22 | |
---|
23 | #include "NodePrinter.h" |
---|
24 | |
---|
25 | #include "Configuration.h" |
---|
26 | #include "Date.h" |
---|
27 | #include "HtmlStream.h" |
---|
28 | #include "html_utility.h" |
---|
29 | #include "LineTypeParser.h" |
---|
30 | #include "Node.h" |
---|
31 | #include "SVNlog.h" |
---|
32 | #include "utility.h" |
---|
33 | |
---|
34 | #include <algorithm> |
---|
35 | #include <cassert> |
---|
36 | #include <ctime> |
---|
37 | #include <fstream> |
---|
38 | #include <iostream> |
---|
39 | #include <sstream> |
---|
40 | |
---|
41 | #include <dirent.h> |
---|
42 | #include <sys/stat.h> |
---|
43 | |
---|
44 | namespace theplu{ |
---|
45 | namespace svndigest{ |
---|
46 | |
---|
47 | NodePrinter::NodePrinter(void) |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | NodePrinter::~NodePrinter(void) |
---|
52 | { |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | std::string NodePrinter::output_dir(void) const |
---|
57 | { |
---|
58 | return node().output_dir_; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | void NodePrinter::path_anchor(std::ostream& os) const |
---|
63 | { |
---|
64 | os << "<h2 class=\"path\">\n"; |
---|
65 | std::vector<std::string> words; |
---|
66 | words.reserve(node().level_+1); |
---|
67 | std::string word; |
---|
68 | words.push_back(Node::project_); |
---|
69 | std::stringstream ss(node().local_path()); |
---|
70 | while(getline(ss,word,'/')) |
---|
71 | if (!word.empty()) // ignore double slash in path |
---|
72 | words.push_back(word); |
---|
73 | if (words.size()==1) |
---|
74 | os << anchor("index.html", Node::project_,0, "View " + Node::project_); |
---|
75 | else { |
---|
76 | for (size_t i=0; i<words.size()-1; ++i){ |
---|
77 | os << anchor("index.html", words[i], node().level_-i, "View " + words[i]); |
---|
78 | os << "<span class=\"sep\">/</span>"; |
---|
79 | } |
---|
80 | os << anchor(node().href(), words.back(), node().level_+2-words.size(), |
---|
81 | "View " + words.back()); |
---|
82 | } |
---|
83 | os << "\n</h2>\n"; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | void NodePrinter::print(const bool verbose) const |
---|
88 | { |
---|
89 | if (node().ignore()) |
---|
90 | return; |
---|
91 | if (!Configuration::instance().output_file() && !node().dir()) |
---|
92 | return; |
---|
93 | if (verbose) |
---|
94 | std::cout << "Printing output for '" << node().path_ << "'" << std::endl; |
---|
95 | const SVNlog& log = node().log(); |
---|
96 | typedef std::map<std::string, Stats*>::const_iterator iter; |
---|
97 | |
---|
98 | const iter end(node().stats_.stats().end()); |
---|
99 | for (iter i=node().stats_.stats().begin();i!=end; ++i){ |
---|
100 | print_core(i->first, "all", "total", log); |
---|
101 | print_core(i->first, "all", "code", log); |
---|
102 | print_core(i->first, "all", "comments", log); |
---|
103 | print_core(i->first, "all", "empty", log); |
---|
104 | for (std::set<std::string>::const_iterator j=i->second->authors().begin(); |
---|
105 | j!=i->second->authors().end(); ++j) { |
---|
106 | print_core(i->first, *j, "total", log); |
---|
107 | print_core(i->first, *j, "code", log); |
---|
108 | print_core(i->first, *j, "comments", log); |
---|
109 | print_core(i->first, *j, "empty", log); |
---|
110 | } |
---|
111 | } |
---|
112 | print_core(verbose); |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | void NodePrinter::print_author_summary(std::ostream& os, |
---|
117 | const Stats& stats, |
---|
118 | const std::string& line_type, |
---|
119 | const SVNlog& log) const |
---|
120 | { |
---|
121 | HtmlStream hs(os); |
---|
122 | os << "<h3>Author Summary</h3>"; |
---|
123 | os << "<table class=\"listings\">\n"; |
---|
124 | os << "<thead>\n"; |
---|
125 | os << "<tr>\n"; |
---|
126 | os << "<th>Author</th>\n"; |
---|
127 | os << "<th>Lines</th>\n"; |
---|
128 | os << "<th>Code</th>\n"; |
---|
129 | os << "<th>Comments</th>\n"; |
---|
130 | os << "<th>Other</th>\n"; |
---|
131 | os << "<th>Revision</th>\n"; |
---|
132 | os << "<th>Date</th>\n"; |
---|
133 | os << "</tr>\n</thead>\n"; |
---|
134 | os << "<tbody>\n"; |
---|
135 | |
---|
136 | std::string color("light"); |
---|
137 | if (!node().dir()) { |
---|
138 | os << "<tr class=\"" << color << "\">\n"; |
---|
139 | os << "<td class=\"directory\" colspan=\"7\">"; |
---|
140 | os << anchor("index.html", "../"); |
---|
141 | os << "</td>\n</tr>\n"; |
---|
142 | } |
---|
143 | |
---|
144 | // print authors |
---|
145 | const std::string timefmt("%Y-%m-%d %H:%M"); |
---|
146 | for (std::set<std::string>::const_iterator i=stats.authors().begin(); |
---|
147 | i!=stats.authors().end(); ++i){ |
---|
148 | if (color=="dark") |
---|
149 | color="light"; |
---|
150 | else |
---|
151 | color="dark"; |
---|
152 | os << "<tr class=\"" << color << "\"><td>"; |
---|
153 | os << anchor(*i+"/"+line_type+"/"+output_path() |
---|
154 | ,*i, node().level_+2, "View statistics for "+*i); |
---|
155 | os << "</td><td>" << stats.lines(*i) |
---|
156 | << "</td><td>" << stats.code(*i) |
---|
157 | << "</td><td>" << stats.comments(*i) |
---|
158 | << "</td><td>" << stats.empty(*i); |
---|
159 | if (log.exist(*i)) { |
---|
160 | const Commitment& lc(log.latest_commit(*i)); |
---|
161 | os << "</td>" << "<td>" << trac_revision(lc.revision()) |
---|
162 | << "</td>" << "<td>"; |
---|
163 | hs << Date(lc.date())(timefmt); |
---|
164 | } |
---|
165 | else { |
---|
166 | os << "</td>" << "<td>N/A" |
---|
167 | << "</td>" << "<td>N/A"; |
---|
168 | } |
---|
169 | os << "</td></tr>\n"; |
---|
170 | } |
---|
171 | |
---|
172 | os << "<tr class=\"" << color << "\">\n"; |
---|
173 | os << "<td>"; |
---|
174 | if (node().dir()) |
---|
175 | if (node().local_path().empty()) |
---|
176 | os << anchor("all/"+line_type+"/index.html" |
---|
177 | ,"Total", node().level_+2, "View statistics for all"); |
---|
178 | else |
---|
179 | os << anchor("all/"+line_type+"/"+node().local_path()+"/index.html" |
---|
180 | ,"Total", node().level_+2, "View statistics for all"); |
---|
181 | else |
---|
182 | os << anchor("all/"+line_type+"/"+node().local_path()+".html" |
---|
183 | ,"Total", node().level_+2, "View statistics for all"); |
---|
184 | os << "</td>\n"; |
---|
185 | os << "<td>" << stats.lines() << "</td>\n"; |
---|
186 | os << "<td>" << stats.code() << "</td>\n"; |
---|
187 | os << "<td>" << stats.comments() << "</td>\n"; |
---|
188 | os << "<td>" << stats.empty() << "</td>\n"; |
---|
189 | const Commitment& lc(log.latest_commit()); |
---|
190 | os << "<td>" << trac_revision(lc.revision()) << "</td>\n"; |
---|
191 | os << "<td>"; |
---|
192 | hs << Date(lc.date())(timefmt); |
---|
193 | os << "</td>\n"; |
---|
194 | os << "</tr>\n"; |
---|
195 | os << "</tbody>\n"; |
---|
196 | os << "</table>\n"; |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | }} // end of namespace svndigest and namespace theplu |
---|