source: trunk/lib/utility.cc @ 125

Last change on this file since 125 was 125, checked in by Jari Häkkinen, 17 years ago

Cleaning.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1// $Id: utility.cc 125 2006-08-01 22:47:30Z jari $
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/param.h>
33#include <sys/stat.h>
34#include <unistd.h>
35
36namespace theplu{
37namespace svnstat{
38
39  int blame(const std::string& path)
40  {
41    std::string mod_path = mod_str(path);
42    std::string system_call="svn blame " + mod_path + 
43      " 1> /tmp/svnstat.tmp 2> /dev/null";
44    int system_return = system(system_call.c_str());
45    if (system_return)
46      std::cerr << "Error: svn blame " << path << std::endl;     
47    return system_return;
48  }
49
50  int createdir(const std::string& dir, bool force)
51  {
52    struct stat buf;
53    if (force && !stat(dir.c_str(),&buf))
54      rmdirhier(dir);
55
56    return mkdir(dir.c_str(),0777);
57  }
58
59  std::string file_name(const std::string& full_path)
60  {
61    std::stringstream ss(full_path);
62    std::string name;
63    while (getline(ss,name,'/')) {}
64    return name;
65  }
66
67  std::map<std::string, std::string> info(const std::string& path) 
68  {
69    std::string mod_path=mod_str(path);
70    std::string system_call="svn info " + mod_path + 
71      " 1> /tmp/svnstat.tmp 2> /dev/null";
72    int system_return = system(system_call.c_str());
73    if (system_return)
74      return std::map<std::string, std::string>();
75
76    std::ifstream is("/tmp/svnstat.tmp");
77    std::string line;
78    std::map<std::string, std::string> svn_info;
79    while (getline(is,line)){
80      std::stringstream ss(line);
81      std::string tag;
82      getline(ss,tag,':');
83      ss >> svn_info[tag];
84    }
85    return svn_info;
86  }
87
88  std::string mod_str(const std::string& str)
89  {
90    std::string mod_str="";
91    for (size_t i=0; i<str.size(); ++i){
92      if (str[i]==' ')
93        mod_str+="\\ ";
94      else
95        mod_str+=str[i];
96    }
97    return mod_str;
98  }
99
100  void print_css(std::ostream& s)
101  {
102    s << "body {\n";
103    s << " background: #fff; \n";
104    s << " color: #000; \n";
105    s << " margin: 0px; \n";
106    s << " padding: 0; \n";
107    s << "} \n";
108    s << "\n";
109    s << "#menu {\n";
110    s << " background: #eee;\n";
111    s << " width: 100%;\n";
112    s << " margin: 0px;\n";
113    s << " padding: 0px;\n";
114    s << "}\n\n";
115    s << "#menu ul\n";
116    s << "{ \n";
117    s << "padding: 0px;\n";
118    s << "margin: 0px;list-style-type: none; text-align: center;"
119      << "border-bottom: 1px solid black;}\n";
120    s << "#menu ul li { display: inline; border-right: 1px solid black;}\n";
121    s << "#menu ul li a {text-decoration: none; padding-right: 1em;" 
122      << "padding-left: 1em; margin: 0px;}\n";
123    s << "#menu ul li a:hover{ color: #000; background: #ddd;}\n";
124    s << "\n";
125    s << "#main {\n";
126    s << " margin: 10px; \n";
127    s << "}\n";
128    s << "\n";
129    s << "body, th, td {\n";
130    s << " font: normal 13px verdana,arial,'Bitstream Vera Sans',"
131      << "helvetica,sans-serif;\n";
132    s << "}\n";
133    s << ":link, :visited {\n";
134    s << " text-decoration: none;\n";
135    s << " color: #b00;\n";
136    s << "}\n";
137    s << "\n";
138    s << "table.listings {\n";
139    s << " clear: both;\n";
140    s << " border-bottom: 1px solid #d7d7d7;\n";
141    s << " border-collapse: collapse;\n";
142    s << " border-spacing: 0;\n";
143    s << " margin-top: 1em;\n";
144    s << " width: 100%;\n";
145    s << "}\n";
146    s << "\n";
147    s << "table.listings th {\n";
148    s << " text-align: left;\n";
149    s << " padding: 0 1em .1em 0;\n";
150    s << " font-size: 12px\n";
151    s << "}\n";
152    s << "table.listings thead { background: #f7f7f0 }\n";
153    s << "table.listings thead th {\n";
154    s << " border: 1px solid #d7d7d7;\n";
155    s << " border-bottom-color: #999;\n";
156    s << " font-size: 11px;\n";
157    s << " font-wheight: bold;\n";
158    s << " padding: 2px .5em;\n";
159    s << " vertical-align: bottom;\n";
160    s << "}\n";
161    s << "\n";
162    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
163    s << " background-color: transparent;\n";
164    s << "}\n";
165    s << "\n";
166    s << "table.listings tbody td, table.listing tbody th {\n";
167    s << " border: 1px dotted #ddd;\n";
168    s << " padding: .33em .5em;\n";
169    s << " vertical-align: top;\n";
170    s << "}\n";
171    s << "\n";
172    s << "table.listings tbody td a:hover, table.listing tbody th a:hover {\n";
173    s << " background-color: transparent;\n";
174    s << "}\n";
175    s << "table.listings tbody tr { border-top: 1px solid #ddd }\n";
176    s << "table.listings tbody tr.light { background-color: #fcfcfc }\n";
177    s << "table.listings tbody tr.dark { background-color: #f7f7f7 }\n";
178    s << "table.listings tbody tr:hover { background: #eed }\n";
179    s << "\n";
180    s << "\n";
181    s << "\n";
182  }
183
184
185  std::string pwd(void)
186  {
187    char buffer[MAXPATHLEN];
188    getcwd(buffer, MAXPATHLEN);
189    return std::string(buffer);
190  }
191
192
193
194}} // end of namespace svnstat and namespace theplu
Note: See TracBrowser for help on using the repository browser.