Changeset 229
- Timestamp:
- Mar 25, 2007, 10:16:07 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Parameter.cc
r226 r229 45 45 if (myargv=="-c" || myargv=="--config"){ 46 46 if (++i<argc){ 47 config_ path_= std::string(argv[i]);47 config_file_= std::string(argv[i]); 48 48 ok=true; 49 49 } … … 55 55 else if (myargv=="-f" || myargv=="--force"){ 56 56 force_=true; 57 ok=true; 58 } 59 else if (myargv=="-g" || myargv=="--generate-config"){ 60 generate_config_=true; 57 61 ok=true; 58 62 } … … 95 99 "\nType 'svndigest --help' for usage."); 96 100 } 97 98 std::string home_path = getenv("HOME") + "/.svndigest";99 if (!node_exist(home_path))100 mkdir(home_path);101 if (!node_exist(home_path+"/config"))102 print_config(home_path+"/config");103 read_config(config_path_);104 101 105 102 analyse(); … … 137 134 if (chdir(workdir.c_str())) 138 135 runtime_error(string("svndigest: Failed to access cwd: ") + workdir); 136 137 if (config_file_.empty()) 138 runtime_error(string("svndigest: Parameter --config requires argument.")); 139 139 140 } 140 141 … … 142 143 void Parameter::defaults(void) 143 144 { 144 config_ path_ = getenv("HOME")+"/.svndigest/config";145 config_file_ = getenv("HOME")+"/.svndigest/config"; 145 146 copyright_=false; 146 147 force_=false; 148 generate_config_=false; 147 149 revisions_=false; 148 150 root_="."; … … 166 168 << "\n" 167 169 << "Valid options:\n" 168 << " -c [--config] arg : path to config file [" 169 << config_path_ << "]\n" 170 << " --copyright : update copyright statement\n" 171 << " -c [--config] arg : configuration file [" 172 << config_file_ << "]\n" 170 173 << " -f [--force] : remove target directory/file if it exists\n" 171 174 << " [no force]. NOTE recursive delete.\n" 175 << " -g [--generate-config] : write configuration file " 176 << "to standard output and exit\n" 172 177 << " -h [--help] : display this help and exit\n" 173 178 << " -r [--root] arg : svn controlled directory to perform\n" … … 184 189 185 190 186 void Parameter::print_config(std::string path) const187 {188 std::ofstream os(path.c_str());189 if (!os.good()){190 os.close();191 throw std::runtime_error("svndigest: error: cannot create file '" +192 path + "': permission denied");193 }194 os << "### This file configures various behaviors for svndigest\n"195 << "### The commented-out below are intended to demonstrate how to use\n"196 << "### this file.\n"197 << "\n"198 << "### Section for setting aliases used in copyright update\n"199 << "#[copyright-alias]\n"200 << "# jdoe = John Doe\n"201 << std::endl;202 os.close();203 }204 205 206 void Parameter::read_config(std::string path)207 {208 if (!node_exist(path))209 throw std::runtime_error("svndigest: error: configuration file '" +210 path + "' not found");211 std::ifstream is(path.c_str());212 if (!is.good()){213 is.close();214 throw std::runtime_error("svndigest: error: cannot open file '" + path +215 "' for reading");216 }217 std::string line;218 std::string section;219 std::string tmp;220 while (getline(is, line)) {221 line = ltrim(line);222 if (line.empty() || line[0]=='#')223 continue;224 std::stringstream ss(line);225 if (line[0] == '[') {226 getline(ss, tmp, '[');227 getline(ss, section, ']');228 }229 else if (section == "copyright-alias"){230 getline(ss, tmp, '=');231 std::string key = trim(tmp);232 getline(ss, tmp);233 std::string name = trim(tmp);234 copyright_alias_[key] = name;235 }236 }237 is.close();238 }239 240 241 191 void Parameter::version(void) const 242 192 { -
trunk/bin/Parameter.h
r226 r229 36 36 public: 37 37 Parameter(const int argc,const char *argv[]); 38 inline std::string config_file(void) const { return config_file_; } 38 39 inline bool copyright(void) const { return copyright_; } 39 40 /// @todo 40 inline const std::map<std::string, std::string>41 copyright_alias(void) const { return copyright_alias_; }42 41 inline bool force(void) const { return force_; } 42 inline bool generate_config(void) const { return generate_config_; } 43 43 inline bool revisions(void) const { return revisions_; } 44 44 /// @return absolute path to root directory … … 52 52 void defaults(void); 53 53 void help(void); 54 void print_config(std::string) const;55 void read_config(std::string);56 54 void version(void) const; 57 55 58 std::string config_ path_;56 std::string config_file_; 59 57 bool copyright_; 60 std::map<std::string, std::string> copyright_alias_;61 58 bool force_; 59 bool generate_config_; 62 60 bool revisions_; 63 61 std::string root_; -
trunk/bin/svndigest.cc
r227 r229 25 25 #include "Parameter.h" 26 26 27 #include "Configuration.h" 27 28 #include "Directory.h" 28 29 #include "GnuplotFE.h" … … 43 44 { 44 45 using namespace theplu::svndigest; 46 47 // Reading commandline options 45 48 Parameter* option=NULL; 46 49 try { … … 52 55 std::cerr << e.what() << std::endl; 53 56 exit(-1); 57 } 58 assert(option); 59 60 // Reading configuration file 61 Configuration* config = NULL; 62 if (node_exist(option->config_file())) { 63 std::ifstream is(option->config_file().c_str()); 64 if (!is.good()){ 65 is.close(); 66 std::cerr << "\nsvndigest: Cannot open config file " 67 << option->config_file() << std::endl; 68 exit(-1); 69 } 70 config = new Configuration(is); 71 is.close(); 72 } 73 else 74 config = new Configuration; 75 assert(config); 76 77 // write configuration 78 if (option->generate_config()) { 79 std::cout << *config; 80 exit(0); 54 81 } 55 82 … … 147 174 std::cerr << "svndigest: " << x.what() << std::endl; 148 175 } 149 176 150 177 if (option->copyright()){ 151 178 try { 152 179 if (option->verbose()) 153 180 std::cout << "Updating copyright statements" << std::endl; 154 tree.print_copyright(commit_dates, authors, option->copyright_alias());181 tree.print_copyright(commit_dates, authors, config->copyright_alias()); 155 182 } 156 183 catch (const std::runtime_error& x) { -
trunk/lib/Makefile.am
r193 r229 5 5 # Copyright (C) 2005 Jari Häkkinen 6 6 # Copyright (C) 2006 Jari Häkkinen, Peter Johansson 7 # Copyright (C) 2007 Peter Johansson 7 8 # 8 9 # This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest … … 25 26 noinst_LTLIBRARIES = libsvndigest.la 26 27 27 noinst_HEADERS = Directory.h File.h Gnuplot.h GnuplotFE.h\28 noinst_HEADERS = Configuration.h Directory.h File.h Gnuplot.h GnuplotFE.h \ 28 29 html_utility.h Node.h Parser.h rmdirhier.h Stats.h SVN.h SVNblame.h \ 29 30 SVNinfo.h SVNproperty.h utility.h 30 31 31 libsvndigest_la_SOURCES = Directory.cc File.cc Gnuplot.cc GnuplotFE.cc \ 32 libsvndigest_la_SOURCES = Configuration.cc Directory.cc File.cc \ 33 Gnuplot.cc GnuplotFE.cc \ 32 34 html_utility.cc Node.cc Parser.cc rmdirhier.cc Stats.cc SVN.cc \ 33 35 SVNblame.cc SVNinfo.cc SVNproperty.cc utility.cc
Note: See TracChangeset
for help on using the changeset viewer.