source: trunk/lib/utility.cc @ 112

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

fixes #27 and added some beauty

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1// $Id: utility.cc 112 2006-06-29 09:30:54Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat 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  svnstat 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 "utility.h"
25#include "rmdirhier.h"
26
27#include <fstream>
28#include <iostream>
29#include <map>
30#include <sstream>
31#include <string>
32#include <sys/stat.h>
33
34namespace theplu{
35namespace svnstat{
36
37  int blame(const std::string& path)
38  {
39    std::string system_call="svn blame " + path + " 1> svnstat.tmp 2> /dev/null";
40    int system_return = system(system_call.c_str());
41    if (system_return)
42      std::cerr << "Error: svn blame " << path << std::endl;     
43    return system_return;
44  }
45
46  int createdir(const std::string& dir, bool force)
47  {
48    struct stat buf;
49    if (force && !stat(dir.c_str(),&buf))
50      rmdirhier(dir);
51
52    return mkdir(dir.c_str(),0777);
53  }
54
55  std::string file_name(const std::string& full_path)
56  {
57    std::stringstream ss(full_path);
58    std::string name;
59    while (getline(ss,name,'/')) {}
60    return name;
61  }
62
63  std::map<std::string, std::string> info(const std::string& path) 
64  {
65    std::string system_call="svn info " + path + " 1> svnstat.tmp 2> /dev/null";
66    int system_return = system(system_call.c_str());
67    if (system_return)
68      return std::map<std::string, std::string>();
69
70    std::ifstream is("svnstat.tmp");
71    std::string line;
72    std::map<std::string, std::string> svn_info;
73    while (getline(is,line)){
74      std::stringstream ss(line);
75      std::string tag;
76      getline(ss,tag,':');
77      ss >> svn_info[tag];
78    }
79    return  svn_info;
80  }
81
82  void print_css(std::ostream& s)
83  {
84    s << "body {\n";
85    s << " background: #fff; \n";
86    s << " color: #000; \n";
87    s << " margin: 10px; \n";
88    s << " padding: 0; \n";
89    s << "} \n";
90    s << "\n";
91    s << "body, th, td {\n";
92    s << " font: normal 13px verdana,arial,'Bitstream Vera Sans',"
93      << "helvetica,sans-serif;\n";
94    s << "}\n";
95    s << ":link, :visited {\n";
96    s << " text-decoration: none;\n";
97    s << " color: #b00;\n";
98    s << " border-bottom: 1px dotted #bbb;\n";
99    s << "}\n";
100    s << "\n";
101    s << "table.listings {\n";
102    s << " clear: both;\n";
103    s << " border-bottom: 1px solid #d7d7d7;\n";
104    s << " border-collapse: collapse;\n";
105    s << " border-spacing: 0;\n";
106    s << " margin-top: 1em;\n";
107    s << " width: 100%;\n";
108    s << "}\n";
109    s << "\n";
110    s << "table.listings th {\n";
111    s << " text-align: left;\n";
112    s << " padding: 0 1em .1em 0;\n";
113    s << " font-size: 12px\n";
114    s << "}\n";
115    s << "table.listings thead { background: #f7f7f0 }\n";
116    s << "table.listings thead th {\n";
117    s << " border: 1px solid #d7d7d7;\n";
118    s << " border-bottom-color: #999;\n";
119    s << " font-size: 11px;\n";
120    s << " font-wheight: bold;\n";
121    s << " padding: 2px .5em;\n";
122    s << " vertical-align: bottom;\n";
123    s << "}\n";
124    s << "\n";
125    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
126    s << " background-color: transparent;\n";
127    s << "}\n";
128    s << "\n";
129    s << "table.listings tbody td, table.listing tbody th {\n";
130    s << " border: 1px dotted #ddd;\n";
131    s << " padding: .33em .5em;\n";
132    s << " vertical-align: top;\n";
133    s << "}\n";
134    s << "\n";
135    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
136    s << " background-color: transparent;\n";
137    s << "}\n";
138    s << "table.listings tbody tr { border-top: 1px solid #ddd }\n";
139    s << "table.listings tbody tr.light { background-color: #fcfcfc }\n";
140    s << "table.listings tbody tr.dark { background-color: #f7f7f7 }\n";
141    s << "table.listings tbody tr.hover { background: #eed }\n";
142    s << "\n";
143    s << "\n";
144    s << "\n";
145  }
146
147
148}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.