source: trunk/lib/NodePrinter.cc @ 1449

Last change on this file since 1449 was 1449, checked in by Peter Johansson, 10 years ago

refs #387. svncopyright no longer listens to property
svndigest:ignore. New revision (71) in test repo where
svncopyright:ignore was added to dir_to_be ignored.

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