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