source: trunk/lib/File.cc @ 225

Last change on this file since 225 was 225, checked in by Peter Johansson, 15 years ago

copyright based on log is printed to cout refs #36

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