lib/DirectoryPrinter.cc

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