source: trunk/lib/File.cc @ 226

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

added reading of config file in Parameter closes ##106 and #98. Move function check_target from svndigest.cc to utility.cc and changed name to node_exist. added support for aliases in Copyright update refs #36

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