Changeset 201


Ignore:
Timestamp:
Sep 9, 2006, 7:36:34 PM (17 years ago)
Author:
Peter Johansson
Message:

fixes #76 and refs #87 new output file structure and draft to new main page.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r198 r201  
    138138  GnuplotFE::instance()->command(std::string("cd '")+option->targetdir()+"'");
    139139  chdir(option->targetdir().c_str());
     140  mkdir(tree.name());
     141  print_css(tree.name()+"/svndigest.css");
     142  print_main_page(tree.name(), commit_dates);
     143  mkdir(tree.name()+"/all");
     144  mkdir(tree.name()+"/all/total");
    140145  try {
    141     tree.print(option->verbose());
     146    tree.print(tree.name()+"/all/total", option->verbose());
    142147  }
    143148  catch (const std::runtime_error& x) {
     
    156161  if (option->verbose())
    157162    std::cout << "Finalizing" << std::endl;
    158   std::string css(file_name(option->root())+"/svndigest.css");
    159   std::ofstream os(css.c_str());
    160   print_css(os);
    161   os.close();
    162163
    163164  delete option;
  • trunk/lib/Directory.cc

    r199 r201  
    7272          if (S_ISDIR(nodestat.st_mode))       // C api from sys/stat.h
    7373            daughters_.push_back(new Directory(level_+1,fullpath,
    74                                                output_name()+"/"));
     74                                               local_path()+"/"));
    7575          else
    76             daughters_.push_back(new File(level_,fullpath,output_name()+"/"));
     76            daughters_.push_back(new File(level_,fullpath,local_path()+"/"));
    7777          break;
    7878        case SVN::unresolved:
     
    118118
    119119
    120   void Directory::print(const bool verbose) const
     120  void Directory::print(const std::string& out_path, const bool verbose) const
    121121  {
    122     mkdir(output_name());
    123     std::string output(output_name() + "/index.html");
     122    mkdir(out_path);
     123    std::string output(out_path + "/index.html");
    124124    if (verbose)
    125125      std::cout << "Printing output for " << path_ << std::endl;
    126126    std::ofstream os(output.c_str());
    127     print_header(os, name(), level_);
     127    print_header(os, name(), level_+2);
    128128    path_anchor(os);
    129129    os << "<p align=center>\n<img src='"
    130        << file_name(stats_.plot(output_name()+"/index.png", output_name()))
     130       << file_name(stats_.plot(out_path+"/index.png", local_path()))
    131131       << "' alt='[plot]' border=0><br>\n";
    132132    os << "<table class=\"listings\">\n";
     
    176176
    177177    // print daughter nodes, i.e, this function is recursive
    178     std::for_each(daughters_.begin(), daughters_.end(),
    179                   std::bind2nd(std::mem_fun(&Node::print),verbose));
     178    for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
     179      (*i)->print(out_path+"/"+(*i)->name(), verbose);
    180180  }
    181181
  • trunk/lib/Directory.h

    r198 r201  
    7777    const Stats& parse(const bool verbose=false);
    7878
    79     void print(const bool verbose=false) const;
     79    void print(const std::string&, const bool verbose=false) const;
    8080
    8181    void print_copyright(const std::vector<std::string>& dates) const;
  • trunk/lib/File.cc

    r199 r201  
    5656
    5757
    58   void File::print(const bool verbose) const
     58  void File::print(const std::string& out_path, const bool verbose) const
    5959  {
    6060    // no output page for binary files
    6161    if (ignore())
    6262      return;
    63     std::string output(output_name() + ".html");
     63    std::string output(out_path + ".html");
    6464    if (verbose)
    6565      std::cout << "Printing output for " << path_ << std::endl;
    6666    std::ofstream os(output.c_str());
    67     print_header(os, name(), level_);
     67    print_header(os, name(), level_+2);
    6868    path_anchor(os);
    6969    os << "<p align=center>\n<img src='"
    70        << file_name(stats_.plot(output_name()+".png",output_name()))
     70       << file_name(stats_.plot(out_path+".png",local_path()))
    7171       << "' alt='[plot]' border=0>\n</p>";
    7272
     
    126126    if (ignore())
    127127      return;
    128     std::cout << "\nCOPYRIGHT " << output_name() << std::endl;
     128    std::cout << "\nCOPYRIGHT " << local_path() << std::endl;
    129129    // last rev and 4-chars string for each year
    130130    std::vector<std::pair<size_t,std::string> > years;
  • trunk/lib/File.h

    r198 r201  
    6262    ///
    6363    ///
    64     void print(const bool verbose=false) const;
     64    void print(const std::string&, const bool verbose=false) const;
    6565
    6666    void print_copyright(const std::vector<std::string>&) const;
  • trunk/lib/Node.cc

    r200 r201  
    4141    binary_=property.binary();
    4242    svndigest_ignore_=property.svndigest_ignore();
    43     output_name_ = output+file_name(path_);
     43    local_path_ = output+file_name(path_);
    4444  }
    4545
     
    5757    words.reserve(level_+1);
    5858    std::string word;
    59     std::stringstream ss(output_name());
     59    std::stringstream ss(local_path());
    6060    while(getline(ss,word,'/'))
    6161      words.push_back(word);
  • trunk/lib/Node.h

    r200 r201  
    115115    /// @return
    116116    ///
    117     inline const std::string& output_name(void) const { return output_name_; }
     117    inline const std::string& local_path(void) const { return local_path_; }
     118
     119    ///
     120    /// Function returning everything after the last '/'
     121    ///
     122    /// @return name of node (not full path)
     123    ///
     124    inline std::string name(void) const { return file_name(path_); }
    118125
    119126    ///
     
    130137    /// Function printing HTML in current working directory
    131138    ///
    132     virtual void print(const bool verbose=false) const=0;
     139    virtual void print(const std::string&, const bool verbose=false) const=0;
    133140
    134141    virtual void print_copyright(const std::vector<std::string>& dates) const=0;
     
    149156
    150157    ///
    151     /// Function returning everything after the last '/'
    152     ///
    153     /// @return name of node (not full path)
    154     ///
    155     inline std::string name(void) const { return file_name(path_); }
    156 
    157     ///
    158158    /// print path in html format (with anchors) to @a os
    159159    ///
     
    161161
    162162    u_int level_;
    163     std::string output_name_; //without suffix
    164     std::string path_;
     163    std::string local_path_; // path from root
     164    std::string path_; // absolute path from
    165165    Stats stats_;
    166166
     
    181181    {   
    182182      if (first->dir()==second->dir())
    183         return first->output_name()<second->output_name();
     183        return first->name()<second->name();
    184184      return first->dir();
    185185    }
  • trunk/lib/html_utility.cc

    r200 r201  
    2222*/
    2323
     24#include "html_utility.h"
    2425#include "utility.h"
    2526#include <config.h> // this header file is created by configure
     
    3233#include <sys/param.h>
    3334#include <unistd.h>
     35#include <vector>
    3436
    3537namespace theplu{
     
    9092 
    9193
    92   void print_css(std::ostream& s)
    93   {
     94  void print_css(const std::string& str)
     95  {
     96    std::ofstream s(str.c_str());
    9497    s << "body {\n";
    9598    s << " background: #fff; \n";
     
    128131    s << "}\n";
    129132    s << "\n";
     133    s << "div.main {\n";
     134    s << " text-align: center\n";
     135    s << "}\n";
    130136    s << "table.listings {\n";
    131137    s << " clear: both;\n";
     
    175181    s << "\n";
    176182    s << "\n";
     183    s.close();
     184  }
     185
     186
     187  void print_main_page(const std::string& dir,
     188                       const std::vector<std::string>& commit_dates)
     189  {
     190    std::string filename=dir+"/index.html";
     191    std::ofstream os(filename.c_str());
     192    print_header(os, dir, 0);
     193    time_t now;
     194    time (&now);
     195    u_int n7=0;
     196    u_int n30=0;
     197    u_int n365=0;
     198    for (size_t i=1; i<commit_dates.size(); ++i){
     199      double diff = difftime(now,str2time(commit_dates[i]));
     200      if (diff<365*24*3600){
     201        n365++;
     202        if (diff<30*24*3600){
     203          n30++;
     204          if (diff<7*24*3600)
     205            n7++;
     206        }
     207      }
     208    }
     209    os << "<div class=\"main\">\n"
     210       << "<table><thead><tr><th>Statistics for " << dir
     211       << "</th></tr><thead>\n"
     212       << "<tr><td>Commits last year</td><td>" << n365 << "</td></tr>\n"
     213       << "<tr><td>Commits last month</td><td>" << n30 << "</td></tr>\n"
     214       << "<tr><td>Commits last week</td><td>" << n7 << "</td></tr>\n"
     215       << "</table></div>\n";
     216   
     217       
     218    print_footer(os);
     219    os.close();
    177220  }
    178221
     
    199242       << " xml:lang=\"en\" lang=\"en\"><head>\n"
    200243       << "<head>\n"
    201        << "<title> svndigest " << title << "</title>\n"
     244       << "<title> " << title << " - svndigest</title>\n"
    202245       << "</head>\n"
    203246       << "<link rel=\"stylesheet\" "
     
    212255    anchor(os, "index.html", "Home", level, "Main page");
    213256    os << "</li>"
     257       << "<li>";
     258    anchor(os, "all/total/index.html", "Browse", level, "Browser");
     259    os << "</li>"
    214260       << "</ul></div>"
    215261       << "<div id=\"main\">\n";
  • trunk/lib/html_utility.h

    r200 r201  
    2929#include <iosfwd>
    3030#include <string>
     31#include <vector>
    3132
    3233namespace theplu{
     
    5253
    5354  ///
    54   /// @printing cascading style sheet to stream @a s.
     55  /// @printing cascading style sheet to file name @a str.
    5556  ///
    56   void print_css(std::ostream& s);
     57  void print_css(const std::string& str);
    5758
     59  ///
     60  /// @brief print main page
     61  ///
     62  void print_main_page(const std::string&, const std::vector<std::string>&);
     63   
    5864  ///
    5965  /// @brief print html footer of page
  • trunk/lib/utility.cc

    r198 r201  
    3131#include <sys/param.h>
    3232#include <unistd.h>
     33
     34#include <iostream>
    3335
    3436namespace theplu{
     
    8486  }
    8587
     88  time_t str2time(const std::string& str)
     89  {
     90    //  str in format 2006-09-09T10:55:52.132733Z
     91    std::stringstream sstream(str);
     92    time_t rawtime;
     93    struct tm * timeinfo;
     94    time ( &rawtime );
     95    timeinfo =  gmtime ( &rawtime );
     96
     97    u_int year, month, day, hour, minute, second;
     98    std::string tmp;
     99    getline(sstream,tmp,'-');
     100    year=atoi(tmp.c_str());
     101    timeinfo->tm_year = year - 1900;
     102    std::cout << tmp << " " << year << std::endl;
     103
     104    getline(sstream,tmp,'-');
     105    month=atoi(tmp.c_str());
     106    timeinfo->tm_mon = month - 1;
     107    std::cout << tmp << " " << month << std::endl;
     108
     109    getline(sstream,tmp,'T');
     110    day=atoi(tmp.c_str());
     111    timeinfo->tm_mday = day;
     112    std::cout << tmp << " " << day << std::endl;
     113
     114    getline(sstream,tmp,':');
     115    hour=atoi(tmp.c_str());
     116    timeinfo->tm_hour = hour;
     117    std::cout << tmp << " " << hour << std::endl;
     118
     119    getline(sstream,tmp,':');
     120    minute=atoi(tmp.c_str());
     121    timeinfo->tm_min = minute;
     122    std::cout << tmp << " " << minute << std::endl;
     123
     124    getline(sstream,tmp,'.');
     125    second=atoi(tmp.c_str());
     126    timeinfo->tm_sec = second;
     127    std::cout << tmp << " " << second << std::endl;
     128
     129    return mktime(timeinfo);
     130  }
     131
     132
    86133}} // end of namespace svndigest and namespace theplu
  • trunk/lib/utility.h

    r198 r201  
    9494
    9595  ///
     96  ///
     97  ///
     98  time_t str2time(const std::string&);
     99
     100  ///
    96101  /// Calculating sum of two vectors.
    97102  ///
Note: See TracChangeset for help on using the changeset viewer.