source: trunk/lib/DirectoryPrinter.cc @ 1290

Last change on this file since 1290 was 1290, checked in by Peter Johansson, 11 years ago

closes #457. Lifting out plotting functions in Stats into a new class
StatsPlotter?. In same manner lifting out print functions from
Node/Directory/File? into a new hierarchy
NodePrinter/DirectoryPrinter/FilePrinter?. To accomplish these splits
without to much recoding some friendships are introduced. These new
classes are only needed for svndigest (not svncopyright) and are
therefore placed in a library named libsvndigest together with Graph
class and first_page functions. Remaining functionality, shared
between svncopyright and svndigest, are located in libsvndigest_core
and linked into both binaries.

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