source: trunk/lib/DirectoryPrinter.cc @ 1513

Last change on this file since 1513 was 1513, checked in by Peter Johansson, 9 years ago

remove trailing whitespace

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1// $Id: DirectoryPrinter.cc 1513 2012-09-23 04:09:08Z 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 <dirent.h>
48#include <sys/stat.h>
49
50namespace theplu{
51namespace svndigest{
52
53
54  DirectoryPrinter::DirectoryPrinter(const Directory& dir)
55    : NodePrinter(), directory_(dir)
56  {
57  }
58
59
60  DirectoryPrinter::~DirectoryPrinter(void)
61  {
62  }
63
64
65  const Node& DirectoryPrinter::node(void) const
66  {
67    return directory_;
68  }
69
70
71  std::string DirectoryPrinter::output_path(void) const
72  {
73    return output_dir()+"index.html";
74  }
75
76
77  void DirectoryPrinter::print_core(const bool verbose) const
78  {
79  }
80
81
82  void DirectoryPrinter::print_core(const std::string& stats_type,
83                             const std::string& user,
84                             const std::string& line_type,
85                             const SVNlog& log) const
86  {
87
88    const Stats& stats = directory_.stats_[stats_type];
89    std::string imagedir = stats_type+"/"+"images/"+line_type;
90    std::string outdir   = stats_type+"/"+user+"/" +line_type;
91    if (node().local_path()!="") {
92      imagedir += "/"+node().local_path();
93      outdir   += "/"+node().local_path();
94    }
95    mkdir_p(outdir);
96    if (user=="all")
97      mkdir_p(imagedir);
98    std::string html_name = outdir+"/index.html";
99    std::ofstream os(html_name.c_str());
100    assert(os.good());
101    if (node().local_path().empty())
102      print_header(os, node().name(), directory_.level_+3, user, line_type, "index.html",
103                   stats_type);
104    else
105      print_header(os, node().name(), directory_.level_+3, user, line_type,
106                   node().local_path()+"/index.html", stats_type);
107    path_anchor(os);
108
109    std::stringstream ss;
110    for (size_t i=0; i<directory_.level_; ++i)
111      ss << "../";
112    ss << "../../../";
113    if (user=="all")
114      ss << StatsPlotter(stats).plot(imagedir+"/index", line_type);
115    else
116      ss << imagedir << "/index";
117    os << "<p class=\"plot\">\n";
118    os << image(ss.str());
119    os << "</p>\n";
120
121    os << "<h3>File Summary";
122    if (user!="all")
123      os << " for " << user;
124    os << "</h3>";
125    os << "<table class=\"listings\">\n";
126    os << "<thead>\n";
127    os << "<tr>\n";
128    os << "<th>Node</th>\n";
129    os << "<th>Lines</th>\n";
130    os << "<th>Code</th>\n";
131    os << "<th>Comments</th>\n";
132    os << "<th>Other</th>\n";
133    os << "<th>Revision</th>\n";
134    os << "<th>Author</th>\n";
135    os << "</tr>\n</thead>\n";
136    os << "<tbody>\n";
137
138    std::string color("light");
139    if (directory_.level_){
140      os << "<tr class=\"light\">\n";
141      os << "<td class=\"directory\" colspan=\"7\">";
142      os << anchor("../index.html", "../");
143      os << "</td>\n</tr>\n";
144      color = "dark";
145    }
146
147    // print html links to daughter nodes
148    for (NodeConstIterator d = directory_.daughters_.begin();
149         d!=directory_.daughters_.end(); ++d) {
150
151      (*d)->html_tablerow(os, stats_type, color, user);
152      if (color=="dark")
153        color = "light";
154      else
155        color = "dark";
156    }
157    os << "<tr class=\"" << color << "\">\n";
158    os << "<td>Total</td>\n";
159    if (user=="all"){
160      os << "<td>" << stats.lines() << "</td>\n";
161      os << "<td>" << stats.code() << "</td>\n";
162      os << "<td>" << stats.comments() << "</td>\n";
163      os << "<td>" << stats.empty() << "</td>\n";
164    }
165    else {
166      os << "<td>" << stats.lines(user);
167      if (stats.lines(user))
168        os << " (" << percent(stats.lines(user),stats.lines()) << "%)";
169      os << "</td>\n";
170      os << "<td>" << stats.code(user);
171      if (stats.code(user))
172        os << " (" << percent(stats.code(user),stats.code()) << "%)";
173      os << "</td>\n";
174      os << "<td>" << stats.comments(user);
175      if (stats.comments(user))
176        os << " (" << percent(stats.comments(user),stats.comments()) << "%)";
177      os << "</td>\n";
178      os << "<td>" << stats.empty(user);
179      if (stats.empty(user))
180        os << " (" << percent(stats.empty(user),stats.empty()) << "%)";
181      os << "</td>\n";
182    }
183    os << "<td>" << trac_revision(node().last_changed_rev()) << "</td>\n";
184    os << "<td>" << node().author() << "</td>\n";
185    os << "</tr>\n";
186    os << "</tbody>\n";
187    os << "</table>\n";
188    print_author_summary(os, stats, line_type, log);
189    os << "\n";
190    print_footer(os);
191    os.close();
192  }
193
194
195}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.