7 |
30 Dec 05 |
jari |
// $Id$ |
4 |
29 Dec 05 |
peter |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
1017 |
09 Jan 10 |
peter |
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2012, 2023 Peter Johansson |
84 |
13 Mar 06 |
jari |
6 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
84 |
13 Mar 06 |
jari |
8 |
|
149 |
12 Aug 06 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
84 |
13 Mar 06 |
jari |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
84 |
13 Mar 06 |
jari |
(at your option) any later version. |
84 |
13 Mar 06 |
jari |
13 |
|
149 |
12 Aug 06 |
jari |
svndigest is distributed in the hope that it will be useful, but |
84 |
13 Mar 06 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
149 |
12 Aug 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
84 |
13 Mar 06 |
jari |
General Public License for more details. |
84 |
13 Mar 06 |
jari |
18 |
|
84 |
13 Mar 06 |
jari |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
84 |
13 Mar 06 |
jari |
21 |
*/ |
84 |
13 Mar 06 |
jari |
22 |
|
1619 |
12 Mar 23 |
peter |
23 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
24 |
|
1290 |
12 Nov 10 |
peter |
25 |
#include "DirectoryPrinter.h" |
303 |
11 May 07 |
peter |
26 |
|
303 |
11 May 07 |
peter |
27 |
#include "Alias.h" |
1007 |
03 Jan 10 |
peter |
28 |
#include "Configuration.h" |
1290 |
12 Nov 10 |
peter |
29 |
#include "Directory.h" |
10 |
30 Dec 05 |
jari |
30 |
#include "File.h" |
181 |
03 Sep 06 |
peter |
31 |
#include "html_utility.h" |
4 |
29 Dec 05 |
peter |
32 |
#include "Node.h" |
1234 |
23 Oct 10 |
peter |
33 |
#include "NodeVisitor.h" |
1290 |
12 Nov 10 |
peter |
34 |
#include "StatsPlotter.h" |
91 |
23 Mar 06 |
jari |
35 |
#include "SVN.h" |
258 |
30 Apr 07 |
peter |
36 |
#include "SVNlog.h" |
1234 |
23 Oct 10 |
peter |
37 |
#include "TinyStats.h" |
100 |
19 Jun 06 |
peter |
38 |
#include "utility.h" |
4 |
29 Dec 05 |
peter |
39 |
|
19 |
30 Dec 05 |
peter |
40 |
#include <algorithm> |
210 |
12 Sep 06 |
jari |
41 |
#include <cassert> |
23 |
02 Jan 06 |
peter |
42 |
#include <fstream> |
72 |
02 Mar 06 |
peter |
43 |
#include <functional> |
9 |
30 Dec 05 |
jari |
44 |
#include <iostream> |
9 |
30 Dec 05 |
jari |
45 |
#include <iterator> |
18 |
30 Dec 05 |
jari |
46 |
#include <list> |
226 |
11 Mar 07 |
peter |
47 |
#include <map> |
864 |
20 Nov 09 |
jari |
48 |
#include <sstream> |
9 |
30 Dec 05 |
jari |
49 |
|
9 |
30 Dec 05 |
jari |
50 |
#include <dirent.h> |
22 |
02 Jan 06 |
jari |
51 |
#include <sys/stat.h> |
9 |
30 Dec 05 |
jari |
52 |
|
4 |
29 Dec 05 |
peter |
53 |
namespace theplu{ |
149 |
12 Aug 06 |
jari |
54 |
namespace svndigest{ |
4 |
29 Dec 05 |
peter |
55 |
|
91 |
23 Mar 06 |
jari |
56 |
|
1290 |
12 Nov 10 |
peter |
57 |
DirectoryPrinter::DirectoryPrinter(const Directory& dir) |
1290 |
12 Nov 10 |
peter |
58 |
: NodePrinter(), directory_(dir) |
9 |
30 Dec 05 |
jari |
59 |
{ |
9 |
30 Dec 05 |
jari |
60 |
} |
4 |
29 Dec 05 |
peter |
61 |
|
10 |
30 Dec 05 |
jari |
62 |
|
1290 |
12 Nov 10 |
peter |
63 |
DirectoryPrinter::~DirectoryPrinter(void) |
10 |
30 Dec 05 |
jari |
64 |
{ |
10 |
30 Dec 05 |
jari |
65 |
} |
10 |
30 Dec 05 |
jari |
66 |
|
1234 |
23 Oct 10 |
peter |
67 |
|
1290 |
12 Nov 10 |
peter |
68 |
const Node& DirectoryPrinter::node(void) const |
1234 |
23 Oct 10 |
peter |
69 |
{ |
1290 |
12 Nov 10 |
peter |
70 |
return directory_; |
1234 |
23 Oct 10 |
peter |
71 |
} |
1234 |
23 Oct 10 |
peter |
72 |
|
1234 |
23 Oct 10 |
peter |
73 |
|
1537 |
07 Oct 12 |
peter |
74 |
std::string DirectoryPrinter::out_name(const std::string& stats_type, |
1537 |
07 Oct 12 |
peter |
75 |
const std::string& user, |
1537 |
07 Oct 12 |
peter |
76 |
const std::string& line_type) const |
1537 |
07 Oct 12 |
peter |
77 |
{ |
1538 |
07 Oct 12 |
peter |
78 |
std::string outdir = stats_type+"/"+user+"/" +line_type; |
1538 |
07 Oct 12 |
peter |
79 |
if (node().local_path()!="") |
1538 |
07 Oct 12 |
peter |
80 |
outdir += "/"+node().local_path(); |
1538 |
07 Oct 12 |
peter |
81 |
return outdir+"/index.html"; |
1537 |
07 Oct 12 |
peter |
82 |
} |
1537 |
07 Oct 12 |
peter |
83 |
|
1537 |
07 Oct 12 |
peter |
84 |
|
1290 |
12 Nov 10 |
peter |
85 |
std::string DirectoryPrinter::output_path(void) const |
101 |
22 Jun 06 |
peter |
86 |
{ |
343 |
19 May 07 |
peter |
87 |
return output_dir()+"index.html"; |
343 |
19 May 07 |
peter |
88 |
} |
343 |
19 May 07 |
peter |
89 |
|
9 |
30 Dec 05 |
jari |
90 |
|
1290 |
12 Nov 10 |
peter |
91 |
void DirectoryPrinter::print_core(const bool verbose) const |
23 |
02 Jan 06 |
peter |
92 |
{ |
207 |
11 Sep 06 |
peter |
93 |
} |
207 |
11 Sep 06 |
peter |
94 |
|
207 |
11 Sep 06 |
peter |
95 |
|
1290 |
12 Nov 10 |
peter |
96 |
void DirectoryPrinter::print_core(const std::string& stats_type, |
1538 |
07 Oct 12 |
peter |
97 |
const std::string& user, |
1538 |
07 Oct 12 |
peter |
98 |
const std::string& line_type, |
1538 |
07 Oct 12 |
peter |
99 |
const SVNlog& log) const |
207 |
11 Sep 06 |
peter |
100 |
{ |
1290 |
12 Nov 10 |
peter |
101 |
const Stats& stats = directory_.stats_[stats_type]; |
1014 |
05 Jan 10 |
jari |
102 |
std::string imagedir = stats_type+"/"+"images/"+line_type; |
1538 |
07 Oct 12 |
peter |
103 |
std::string html_name = out_name(stats_type, user, line_type); |
1538 |
07 Oct 12 |
peter |
104 |
std::string outdir = directory_name(html_name); |
1290 |
12 Nov 10 |
peter |
105 |
if (node().local_path()!="") { |
1290 |
12 Nov 10 |
peter |
106 |
imagedir += "/"+node().local_path(); |
1290 |
12 Nov 10 |
peter |
107 |
outdir += "/"+node().local_path(); |
1014 |
05 Jan 10 |
jari |
108 |
} |
1234 |
23 Oct 10 |
peter |
109 |
mkdir_p(outdir); |
235 |
21 Apr 07 |
peter |
110 |
if (user=="all") |
1234 |
23 Oct 10 |
peter |
111 |
mkdir_p(imagedir); |
1538 |
07 Oct 12 |
peter |
112 |
|
207 |
11 Sep 06 |
peter |
113 |
std::ofstream os(html_name.c_str()); |
207 |
11 Sep 06 |
peter |
114 |
assert(os.good()); |
1290 |
12 Nov 10 |
peter |
115 |
if (node().local_path().empty()) |
1538 |
07 Oct 12 |
peter |
116 |
print_header(os, node().name(), directory_.level_+3, user, line_type, |
1538 |
07 Oct 12 |
peter |
117 |
"index.html", stats_type, node().revision_min()); |
213 |
15 Sep 06 |
peter |
118 |
else |
1513 |
23 Sep 12 |
peter |
119 |
print_header(os, node().name(), directory_.level_+3, user, line_type, |
1538 |
07 Oct 12 |
peter |
120 |
node().local_path()+"/index.html", stats_type, |
1538 |
07 Oct 12 |
peter |
121 |
node().revision_min()); |
199 |
09 Sep 06 |
peter |
122 |
path_anchor(os); |
864 |
20 Nov 09 |
jari |
123 |
|
864 |
20 Nov 09 |
jari |
124 |
std::stringstream ss; |
1290 |
12 Nov 10 |
peter |
125 |
for (size_t i=0; i<directory_.level_; ++i) |
864 |
20 Nov 09 |
jari |
126 |
ss << "../"; |
864 |
20 Nov 09 |
jari |
127 |
ss << "../../../"; |
235 |
21 Apr 07 |
peter |
128 |
if (user=="all") |
1614 |
15 Feb 23 |
peter |
129 |
ss << StatsPlotter(stats).plot(imagedir+"/index", line_type, |
1614 |
15 Feb 23 |
peter |
130 |
directory_.local_path()); |
235 |
21 Apr 07 |
peter |
131 |
else |
1014 |
05 Jan 10 |
jari |
132 |
ss << imagedir << "/index"; |
1513 |
23 Sep 12 |
peter |
133 |
os << "<p class=\"plot\">\n"; |
1024 |
10 Jan 10 |
peter |
134 |
os << image(ss.str()); |
864 |
20 Nov 09 |
jari |
135 |
os << "</p>\n"; |
864 |
20 Nov 09 |
jari |
136 |
|
259 |
30 Apr 07 |
peter |
137 |
os << "<h3>File Summary"; |
259 |
30 Apr 07 |
peter |
138 |
if (user!="all") |
259 |
30 Apr 07 |
peter |
139 |
os << " for " << user; |
1513 |
23 Sep 12 |
peter |
140 |
os << "</h3>"; |
112 |
29 Jun 06 |
peter |
141 |
os << "<table class=\"listings\">\n"; |
378 |
20 Jun 07 |
jari |
142 |
os << "<thead>\n"; |
112 |
29 Jun 06 |
peter |
143 |
os << "<tr>\n"; |
112 |
29 Jun 06 |
peter |
144 |
os << "<th>Node</th>\n"; |
112 |
29 Jun 06 |
peter |
145 |
os << "<th>Lines</th>\n"; |
112 |
29 Jun 06 |
peter |
146 |
os << "<th>Code</th>\n"; |
112 |
29 Jun 06 |
peter |
147 |
os << "<th>Comments</th>\n"; |
243 |
28 Apr 07 |
peter |
148 |
os << "<th>Other</th>\n"; |
112 |
29 Jun 06 |
peter |
149 |
os << "<th>Revision</th>\n"; |
112 |
29 Jun 06 |
peter |
150 |
os << "<th>Author</th>\n"; |
112 |
29 Jun 06 |
peter |
151 |
os << "</tr>\n</thead>\n"; |
378 |
20 Jun 07 |
jari |
152 |
os << "<tbody>\n"; |
101 |
22 Jun 06 |
peter |
153 |
|
234 |
09 Apr 07 |
peter |
154 |
std::string color("light"); |
1290 |
12 Nov 10 |
peter |
155 |
if (directory_.level_){ |
112 |
29 Jun 06 |
peter |
156 |
os << "<tr class=\"light\">\n"; |
369 |
14 Jun 07 |
peter |
157 |
os << "<td class=\"directory\" colspan=\"7\">"; |
235 |
21 Apr 07 |
peter |
158 |
os << anchor("../index.html", "../"); |
181 |
03 Sep 06 |
peter |
159 |
os << "</td>\n</tr>\n"; |
234 |
09 Apr 07 |
peter |
160 |
color = "dark"; |
112 |
29 Jun 06 |
peter |
161 |
} |
112 |
29 Jun 06 |
peter |
162 |
|
72 |
02 Mar 06 |
peter |
// print html links to daughter nodes |
1513 |
23 Sep 12 |
peter |
164 |
for (NodeConstIterator d = directory_.daughters_.begin(); |
1290 |
12 Nov 10 |
peter |
165 |
d!=directory_.daughters_.end(); ++d) { |
1290 |
12 Nov 10 |
peter |
166 |
|
1290 |
12 Nov 10 |
peter |
167 |
(*d)->html_tablerow(os, stats_type, color, user); |
234 |
09 Apr 07 |
peter |
168 |
if (color=="dark") |
234 |
09 Apr 07 |
peter |
169 |
color = "light"; |
101 |
22 Jun 06 |
peter |
170 |
else |
234 |
09 Apr 07 |
peter |
171 |
color = "dark"; |
101 |
22 Jun 06 |
peter |
172 |
} |
234 |
09 Apr 07 |
peter |
173 |
os << "<tr class=\"" << color << "\">\n"; |
112 |
29 Jun 06 |
peter |
174 |
os << "<td>Total</td>\n"; |
213 |
15 Sep 06 |
peter |
175 |
if (user=="all"){ |
532 |
26 Dec 07 |
peter |
176 |
os << "<td>" << stats.lines() << "</td>\n"; |
532 |
26 Dec 07 |
peter |
177 |
os << "<td>" << stats.code() << "</td>\n"; |
532 |
26 Dec 07 |
peter |
178 |
os << "<td>" << stats.comments() << "</td>\n"; |
532 |
26 Dec 07 |
peter |
179 |
os << "<td>" << stats.empty() << "</td>\n"; |
213 |
15 Sep 06 |
peter |
180 |
} |
213 |
15 Sep 06 |
peter |
181 |
else { |
1513 |
23 Sep 12 |
peter |
182 |
os << "<td>" << stats.lines(user); |
1513 |
23 Sep 12 |
peter |
183 |
if (stats.lines(user)) |
1513 |
23 Sep 12 |
peter |
184 |
os << " (" << percent(stats.lines(user),stats.lines()) << "%)"; |
313 |
17 May 07 |
peter |
185 |
os << "</td>\n"; |
1513 |
23 Sep 12 |
peter |
186 |
os << "<td>" << stats.code(user); |
1513 |
23 Sep 12 |
peter |
187 |
if (stats.code(user)) |
1513 |
23 Sep 12 |
peter |
188 |
os << " (" << percent(stats.code(user),stats.code()) << "%)"; |
313 |
17 May 07 |
peter |
189 |
os << "</td>\n"; |
1513 |
23 Sep 12 |
peter |
190 |
os << "<td>" << stats.comments(user); |
1513 |
23 Sep 12 |
peter |
191 |
if (stats.comments(user)) |
1513 |
23 Sep 12 |
peter |
192 |
os << " (" << percent(stats.comments(user),stats.comments()) << "%)"; |
313 |
17 May 07 |
peter |
193 |
os << "</td>\n"; |
1513 |
23 Sep 12 |
peter |
194 |
os << "<td>" << stats.empty(user); |
1513 |
23 Sep 12 |
peter |
195 |
if (stats.empty(user)) |
1513 |
23 Sep 12 |
peter |
196 |
os << " (" << percent(stats.empty(user),stats.empty()) << "%)"; |
313 |
17 May 07 |
peter |
197 |
os << "</td>\n"; |
213 |
15 Sep 06 |
peter |
198 |
} |
1290 |
12 Nov 10 |
peter |
199 |
os << "<td>" << trac_revision(node().last_changed_rev()) << "</td>\n"; |
1290 |
12 Nov 10 |
peter |
200 |
os << "<td>" << node().author() << "</td>\n"; |
112 |
29 Jun 06 |
peter |
201 |
os << "</tr>\n"; |
378 |
20 Jun 07 |
jari |
202 |
os << "</tbody>\n"; |
74 |
07 Mar 06 |
jari |
203 |
os << "</table>\n"; |
532 |
26 Dec 07 |
peter |
204 |
print_author_summary(os, stats, line_type, log); |
400 |
28 Jun 07 |
peter |
205 |
os << "\n"; |
23 |
02 Jan 06 |
peter |
206 |
print_footer(os); |
1513 |
23 Sep 12 |
peter |
207 |
os.close(); |
10 |
30 Dec 05 |
jari |
208 |
} |
10 |
30 Dec 05 |
jari |
209 |
|
198 |
09 Sep 06 |
peter |
210 |
|
149 |
12 Aug 06 |
jari |
211 |
}} // end of namespace svndigest and namespace theplu |