source: trunk/lib/utility.cc @ 115

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

added pwd function

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