source: trunk/lib/File.cc @ 207

Last change on this file since 207 was 207, checked in by Peter Johansson, 16 years ago

refs #41 and #44. Splitted print function in File and Directory to 2 functions. One public and one private. The private print a page for a specific author (or all) and specific code (or total), and the public calls this private function. Also added total number of commits #refs 87. NOTE the change of file structure forced all local paths to be relative from target/projectname rather than target as before.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1// $Id: File.cc 207 2006-09-11 07:08:57Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "File.h"
25#include "html_utility.h"
26#include "Stats.h"
27
28#include <cassert>
29#include <fstream>
30#include <iostream>
31#include <string>
32
33namespace theplu{
34namespace svndigest{
35
36
37  std::string File::href(void) const
38  { 
39    return name()+".html"; 
40  }
41
42
43  const std::string File::node_type(void) const
44  {
45    return std::string("file");
46  }
47
48
49  const Stats& File::parse(const bool verbose)
50  {
51    if (verbose)
52      std::cout << "Parsing " << path_ << std::endl; 
53    stats_.reset();
54    stats_.parse(path_);
55    return stats_;
56  }
57
58
59  void File::print(const std::string& user, const std::string& line_type) const 
60  {
61    std::string outpath = user+"/"+line_type+"/"+local_path();
62    std::string html_name(outpath + ".html");
63    std::ofstream os(html_name.c_str());
64    print_header(os, name(), level_+2);
65    path_anchor(os);
66    os << "<p align=center>\n<img src='" 
67       << file_name(stats_.plot(outpath+".png",local_path()))
68       << "' alt='[plot]' border=0>\n</p>";
69
70    os << "<table class=\"listings\">\n";
71    os << "<thead>";
72    os << "<tr>\n";
73    os << "<th>Author</th>\n";
74    os << "<th>Lines</th>\n";
75    os << "<th>Code</th>\n";
76    os << "<th>Comments</th>\n";
77    os << "</tr>\n</thead>\n";
78    os << "<tbody>";
79
80    bool dark=false;
81    os << "<tr class=\"light\">\n";
82    os << "<td class=\"directory\" colspan=\"5\">";
83    anchor(os, "index.html", "../");
84    os << "</td>\n</tr>\n";
85    dark=!dark;
86   
87    // print authors
88    for (std::set<std::string>::const_iterator i=stats_.authors().begin();
89         i!=stats_.authors().end(); ++i){
90      if (dark)
91        os << "<tr class=\"dark\"><td>" << *i
92           << "</td><td>" << stats_.lines(*i)
93           << "</td><td>" << stats_.code(*i)
94           << "</td><td>" << stats_.comments(*i)
95           << "</td></tr>\n";
96      else
97        os << "<tr class=\"light\"><td>" << *i
98           << "</td><td>" << stats_.lines(*i)
99           << "</td><td>" << stats_.code(*i)
100           << "</td><td>" << stats_.comments(*i)
101           << "</td></tr>\n";
102      dark=!dark;
103    }
104    if (dark)
105      os << "<tr class=\"dark\">\n";
106    else
107      os << "<tr class=\"light\">\n";
108    os << "<td>Total</td>\n";
109    os << "<td>" << stats_.lines() << "</td>\n";
110    os << "<td>" << stats_.code() << "</td>\n";
111    os << "<td>" << stats_.comments() << "</td>\n";
112    os << "</tr>\n";
113    os << "</table>\n";
114    os << "</p>\n";
115
116    print_footer(os);
117    os.close(); 
118  }
119
120
121  void File::print(const bool verbose) const 
122  {
123    // no output page for binary files
124    if (ignore())
125      return;
126    if (verbose)
127      std::cout << "Printing output for " << path_ << std::endl;
128    print("all", "total");
129  }
130
131
132  void File::print_blame(std::ofstream& os, const std::string line_type) const
133  {
134    os << "<table class=\"blame\">\n";
135
136    os << "</table>\n";
137  }
138
139
140  void File::print_copyright(const std::vector<std::string>& dates) const
141  {
142    if (ignore())
143      return;
144    std::cout << "\nCOPYRIGHT " << local_path() << std::endl;
145    // last rev and 4-chars string for each year
146    std::vector<std::pair<size_t,std::string> > years;
147    for (size_t i=1; i<dates.size(); ++i) // ignoring rev 0
148      if (years.empty() || years.back().second != dates[i].substr(0,4)){
149        years.push_back(std::pair<size_t,std::string>(i,dates[i].substr(0,4)));
150      } 
151      else {
152        years.back() = std::pair<size_t, std::string>(i, dates[i].substr(0,4));
153      }
154
155    // copyrigt[i] is set of contributors for year 'i'
156    std::vector<std::set<std::string> > copyright;
157    copyright.resize(years.size());
158    for (std::set<std::string>::const_iterator au=stats_.authors().begin();
159         au!=stats_.authors().end(); ++au){
160      std::vector<u_int> lines = stats_.total(*au);
161      assert(!lines.empty());
162      // insert author for 'year zero'
163      if (lines[years[0].first]>0 ){
164        copyright[0].insert(*au);
165      }
166      // insert authors for remaining years
167      for (size_t y=1; y<years.size(); ++y)
168        if (lines[years[y].first]!=lines[years[y-1].first] ){
169          copyright[y].insert(*au);
170        }
171     
172    }
173    // looping over years
174    for (size_t i = 0; i<copyright.size();++i){
175      if (copyright[i].empty()){
176        continue;
177      }
178
179      std::cout << "Copyright (C) " << years[i].second;
180      for (size_t j=i+1; j<copyright.size(); ++j){
181        if (copyright[j].empty())
182          continue;
183        else if (copyright[j]==copyright[i]){
184          std::cout << ", " << years[j].second;
185          i=j;
186        }
187        else
188          break;
189      }
190      std::cout << " ";
191     
192      for (std::set<std::string>::const_iterator iter=copyright[i].begin();
193           iter!=copyright[i].end(); ++iter){
194        if (iter!=copyright[i].begin())
195          std::cout << ", ";
196        std::cout << *iter;
197       
198      }
199      std::cout << std::endl;
200    }
201  }
202}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.