- Timestamp:
- Jun 2, 2010, 3:56:35 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Makefile.am
r1055 r1060 24 24 bin_PROGRAMS = svndigest svncopyright 25 25 26 svndigest_SOURCES = Parameter.cc svndigest .cc27 svncopyright_SOURCES = Parameter.cc svncopyright .cc26 svndigest_SOURCES = Parameter.cc svndigestParameter.cc svndigest.cc 27 svncopyright_SOURCES = Parameter.cc svncopyrightParameter.cc svncopyright.cc 28 28 29 noinst_HEADERS = Parameter.h 29 noinst_HEADERS = Parameter.h svncopyrightParameter.h svndigestParameter.h 30 30 31 31 bin_SCRIPTS = svndigest-copy-cache … … 33 33 34 34 LDADD = $(top_builddir)/lib/libsvndigest.a \ 35 $(top_builddir)/lib/yat/libyat.a $(SVN_LIBS) $(APR_LIBS) $(PLPLOT_LIBS)36 AM_LDFLAGS = $(APR_LDFLAGS) $(SVN_LDFLAGS) $(PLPLOT_LDFLAGS)35 $(top_builddir)/lib/yat/libyat.a $(SVN_LIBS) $(APR_LIBS) 36 AM_LDFLAGS = $(APR_LDFLAGS) $(SVN_LDFLAGS) 37 37 38 38 AM_CPPFLAGS = -I$(top_srcdir)/lib $(DEFAULT_CPPFLAGS) \ 39 $(APR_CPPFLAGS) $(SVN_CPPFLAGS) $(PLPLOT_CPPFLAGS)39 $(APR_CPPFLAGS) $(SVN_CPPFLAGS) 40 40 AM_CXXFLAGS = $(DEFAULT_CXXFLAGS) 41 42 svndigest_LDADD = $(LDADD) $(PLPLOT_LIBS) 43 svndigest_LDFLAGS = $(AM_LDFLAGS) $(PLPLOT_LDFLAGS) 44 svndigest_CPPFLAGS = $(AM_CPPFLAGS) $(PLPLOT_CPPFLAGS) 41 45 42 46 .as.in: -
trunk/bin/Parameter.cc
r1023 r1060 48 48 namespace svndigest { 49 49 50 Parameter::Parameter( int argc, char *argv[])50 Parameter::Parameter(void) 51 51 : cmd_( std::string("Mandatory arguments to long options ") + 52 52 std::string("are mandatory for short options too.")), 53 anchor_format_(cmd_,"anchor-format",54 "override anchor image format defined in config file"),55 53 config_file_(cmd_, "config-file", 56 54 "configuration file [<ROOT>/.svndigest/config]"), 57 copyright_(cmd_, "copyright", "update copyright statement"),58 55 force_(cmd_, "f,force", 59 56 std::string("if sub-directory named <ROOT> exists in target dire")+ … … 65 62 std::string("ignore cache files and analyze ") + 66 63 std::string("everything from repository")), 67 format_(cmd_,"format", "override image format defined in config file"),68 report_(cmd_, "report", "create no HTML report", true),69 revisions_(cmd_, "revisions",70 "use revision number as time scale instead of dates [dates]"),71 64 root_(cmd_, "r,root", 72 65 "svn controlled directory to perform statistics on [.]"), 73 target_(cmd_, "t,target", "output directory [.]"),74 66 verbose_(cmd_, "v,verbose", "explain what is being done"), 75 67 version_(cmd_, "version", "print version information and exit", &verbose_) 68 { 69 } 70 71 void Parameter::parse(int argc, char* argv[]) 76 72 { 77 73 init(); … … 84 80 } 85 81 86 // set default values 87 if (!root_.present()) 88 root_.value("."); 89 90 if (!target_.present()) 91 target_.value("."); 92 93 if (!config_file_.present()) 94 config_file_.value(concatenate_path(root_.value(),".svndigest/config")); 82 set_default(); 95 83 96 84 // analyse arguments … … 101 89 Parameter::~Parameter(void) 102 90 { 103 }104 105 106 const yat::utility::OptionArg<std::string>&107 Parameter::anchor_format(void) const108 {109 return anchor_format_;110 91 } 111 92 … … 128 109 chdir(save_wd.c_str()); 129 110 130 // check target (only if we write report)131 if (report()) {132 check_existence(target_.value());133 check_readable(target_.value());134 std::string base_root = file_name(root_.value());135 std::string path = concatenate_path(target_.value(),base_root);136 if (access_rights(target_.value().c_str(), "w")) {137 std::stringstream ss;138 ss << "svndigest: cannot create directory `" << path139 << "': " << strerror(errno);140 throw yat::utility::cmd_error(ss.str());141 }142 if (node_exist(path) && !force()) {143 std::stringstream ss;144 ss << "svndigest: cannot create directory `" << path << "' "145 << strerror(EEXIST);146 throw yat::utility::cmd_error(ss.str());147 }148 if (chdir(target_.value().c_str())) {149 std::stringstream ss;150 ss << "svndigest: cannot read `" << target_.value() << "': "151 << strerror(errno);152 throw yat::utility::cmd_error(ss.str());153 }154 target_.value(pwd());155 chdir(save_wd.c_str());156 }157 111 } 158 112 … … 176 130 } 177 131 } 132 analyse2(); 178 133 } 179 134 … … 205 160 206 161 207 bool Parameter::copyright(void) const208 {209 return copyright_.present();210 }211 212 213 162 bool Parameter::force(void) const 214 163 { … … 226 175 { 227 176 return ignore_cache_.present(); 228 }229 230 231 const yat::utility::OptionArg<std::string>&232 Parameter::format(void) const233 {234 return format_;235 177 } 236 178 … … 240 182 // don't use argv[0] because user may rename the binary 241 183 cmd_.program_name() = PACKAGE_NAME; 242 anchor_format_.print_arg("=FMT");243 184 config_file_.print_arg("=FILE"); 244 format_.print_arg("=FMT");245 185 root_.print_arg("=ROOT"); 246 target_.print_arg("=TARGET");247 186 std::stringstream ss; 248 187 ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n" 249 188 << PACKAGE << " home page: <" << PACKAGE_URL << ">.\n"; 250 189 help_.post_arguments() = ss.str(); 251 help_.synopsis() = 252 "Generate statistical report for a subversion repository\n"; 253 } 254 255 256 bool Parameter::report(void) const 257 { 258 return report_.value(); 259 } 260 261 262 bool Parameter::revisions(void) const 263 { 264 return revisions_.present(); 190 init2(); 265 191 } 266 192 … … 271 197 } 272 198 273 274 std::string Parameter::targetdir(void) const 275 { 276 return target_.value(); 277 } 278 279 199 void Parameter::set_default(void) 200 { 201 if (!root_.present()) 202 root_.value("."); 203 204 if (!config_file_.present()) 205 config_file_.value(concatenate_path(root_.value(),".svndigest/config")); 206 207 set_default2(); 208 } 209 210 280 211 bool Parameter::verbose(void) const 281 212 { -
trunk/bin/Parameter.h
r1023 r1060 47 47 class Parameter { 48 48 public: 49 Parameter( int argc, char *argv[]);49 Parameter(void); 50 50 virtual ~Parameter(void); 51 const yat::utility::OptionArg<std::string>& anchor_format(void) const; 51 void parse( int argc, char *argv[]); 52 52 53 std::string config_file(void) const; 53 54 54 bool copyright(void) const;55 55 bool force(void) const; 56 56 bool generate_config(void) const ; 57 57 bool ignore_cache(void) const; 58 const yat::utility::OptionArg<std::string>& format(void) const;59 bool report(void) const;60 bool revisions(void) const;61 58 /// @return absolute path to root directory 62 59 std::string root(void) const; 63 /// @return absolute path to target directory64 std::string targetdir(void) const;65 60 bool verbose(void) const; 66 61 67 private: 68 void analyse(void); 62 protected: 63 yat::utility::CommandLine cmd_; 64 yat::utility::OptionHelp help_; 65 69 66 // throw cmd_error if path doesn't exist 70 67 void check_existence(std::string path) const; … … 74 71 void check_readable(std::string path) const; 75 72 73 private: 74 void analyse(void); 75 virtual void analyse2(void)=0; 76 76 void init(void); 77 // called at end of init(void) 78 virtual void init2(void) = 0; 79 void set_default(void); 80 virtual void set_default2(void)=0; 77 81 78 yat::utility::CommandLine cmd_;79 yat::utility::OptionArg<std::string> anchor_format_;80 82 yat::utility::OptionArg<std::string> config_file_; 81 yat::utility::OptionSwitch copyright_;82 83 yat::utility::OptionSwitch force_; 83 84 yat::utility::OptionSwitch generate_config_; 84 yat::utility::OptionHelp help_;85 85 yat::utility::OptionSwitch ignore_cache_; 86 yat::utility::OptionArg<std::string> format_;87 yat::utility::OptionSwitch report_;88 yat::utility::OptionSwitch revisions_;89 86 yat::utility::OptionArg<std::string> root_; 90 yat::utility::OptionArg<std::string> target_;91 87 yat::utility::OptionSwitch verbose_; 88 protected: 92 89 OptionVersion version_; 93 90 -
trunk/bin/svncopyright.cc
r1055 r1060 20 20 */ 21 21 22 #include " Parameter.h"22 #include "svncopyrightParameter.h" 23 23 24 24 #include <cassert> … … 32 32 33 33 // Reading commandline options 34 Parameter* option=NULL;34 svncopyrightParameter option; 35 35 try { 36 option = new Parameter(argc,argv);37 if (option ->verbose())36 option.parse(argc, argv); 37 if (option.verbose()) 38 38 std::cout << "Done parsing parameters" << std::endl; 39 39 } … … 42 42 return EXIT_FAILURE; 43 43 } 44 assert(option);45 46 44 return EXIT_SUCCESS; // normal exit 47 45 } -
trunk/bin/svndigest.cc
r1041 r1060 21 21 */ 22 22 23 #include " Parameter.h"23 #include "svndigestParameter.h" 24 24 25 25 #include "Configuration.h" … … 58 58 59 59 // Reading commandline options 60 Parameter* option=NULL; 61 try { 62 option = new Parameter(argc,argv); 60 svndigestParameter* option = new svndigestParameter; 61 assert(option); 62 try { 63 option->parse(argc,argv); 63 64 if (option->verbose()) 64 65 std::cout << "Done parsing parameters" << std::endl; … … 68 69 exit(EXIT_FAILURE); 69 70 } 70 assert(option);71 71 72 72 // Reading configuration file -
trunk/bin/svndigestParameter.cc
r1054 r1060 23 23 #include <config.h> // this header file is created by configure 24 24 25 #include " Parameter.h"25 #include "svndigestParameter.h" 26 26 27 27 #include "OptionVersion.h" 28 28 #include "../lib/utility.h" // to avoid inclusion of yat file 29 30 #ifdef HAVE_PLPLOT 31 #include <plplot/plstream.h> 32 #endif 29 33 30 34 #include "yat/ColumnStream.h" … … 48 52 namespace svndigest { 49 53 50 Parameter::Parameter( int argc, char *argv[]) 51 : cmd_( std::string("Mandatory arguments to long options ") + 52 std::string("are mandatory for short options too.")), 54 svndigestParameter::svndigestParameter(void) 55 : Parameter(), 53 56 anchor_format_(cmd_,"anchor-format", 54 57 "override anchor image format defined in config file"), 55 config_file_(cmd_, "config-file",56 "configuration file [<ROOT>/.svndigest/config]"),57 58 copyright_(cmd_, "copyright", "update copyright statement"), 58 force_(cmd_, "f,force",59 std::string("if sub-directory named <ROOT> exists in target dire")+60 std::string("ctory, remove sub-directory before writing results")),61 generate_config_(cmd_, "g,generate-config",62 "write configuration to standard output"),63 help_(cmd_),64 ignore_cache_(cmd_, "ignore-cache",65 std::string("ignore cache files and analyze ") +66 std::string("everything from repository")),67 59 format_(cmd_,"format", "override image format defined in config file"), 68 60 report_(cmd_, "report", "create no HTML report", true), 69 61 revisions_(cmd_, "revisions", 70 62 "use revision number as time scale instead of dates [dates]"), 71 root_(cmd_, "r,root", 72 "svn controlled directory to perform statistics on [.]"), 73 target_(cmd_, "t,target", "output directory [.]"), 74 verbose_(cmd_, "v,verbose", "explain what is being done"), 75 version_(cmd_, "version", "print version information and exit", &verbose_) 63 target_(cmd_, "t,target", "output directory [.]") 76 64 { 77 init();78 try {79 cmd_.parse(argc, argv);80 }81 catch (yat::utility::cmd_error& e) {82 std::cerr << e.what() << std::endl;83 exit (-1);84 }85 86 65 // set default values 87 if (!root_.present()) 88 root_.value("."); 89 66 /* 90 67 if (!target_.present()) 91 68 target_.value("."); 92 93 if (!config_file_.present()) 94 config_file_.value(concatenate_path(root_.value(),".svndigest/config")); 95 96 // analyse arguments 97 analyse(); 69 */ 98 70 } 99 71 100 72 101 Parameter::~Parameter(void)73 svndigestParameter::~svndigestParameter(void) 102 74 { 103 75 } … … 105 77 106 78 const yat::utility::OptionArg<std::string>& 107 Parameter::anchor_format(void) const79 svndigestParameter::anchor_format(void) const 108 80 { 109 81 return anchor_format_; … … 111 83 112 84 113 void Parameter::analyse(void)85 void svndigestParameter::analyse2(void) 114 86 { 115 87 std::string save_wd = pwd(); … … 117 89 // check root but not if -g option given 118 90 if (!generate_config()) { 119 check_existence(root_.value());120 check_readable(root_.value());121 if (chdir(root_.value().c_str())) {122 std::stringstream ss;123 ss << "svndigest: cannot read `" << root_.value() << "': "124 << strerror(errno);125 throw yat::utility::cmd_error(ss.str());126 }127 root_.value(pwd());128 chdir(save_wd.c_str());129 130 91 // check target (only if we write report) 131 92 if (report()) { 132 93 check_existence(target_.value()); 133 94 check_readable(target_.value()); 134 std::string base_root = file_name(root _.value());95 std::string base_root = file_name(root()); 135 96 std::string path = concatenate_path(target_.value(),base_root); 136 97 if (access_rights(target_.value().c_str(), "w")) { … … 156 117 } 157 118 } 158 159 // check config file160 struct stat nodestat;161 // true also if there is a broken symlink named...162 bool config_exists = !lstat(config_file_.value().c_str(), &nodestat);163 // the latter case in order to catch broken symlink164 if (config_file_.present() || config_exists)165 // throws if file does not exists166 check_existence(config_file_.value());167 if (config_exists) {168 // throws if file is not readable169 check_readable(config_file_.value());170 stat(config_file_.value().c_str(), &nodestat);171 if (!S_ISREG(nodestat.st_mode)) {172 std::stringstream ss;173 ss << "svndigest: `" << config_file_.value()174 << "' is not a regular file";175 throw yat::utility::cmd_error(ss.str());176 }177 }178 119 } 179 120 180 121 181 void Parameter::check_existence(std::string path) const 182 { 183 if (node_exist(path)) 184 return; 185 std::stringstream ss; 186 ss << "svndigest: cannot stat `" << path << "': " << strerror(errno); 187 throw yat::utility::cmd_error(ss.str()); 188 } 189 190 191 void Parameter::check_readable(std::string path) const 192 { 193 if (!access_rights(path, "r")) 194 return; 195 std::stringstream ss; 196 ss << "svndigest: cannot open `" << path << "': " << strerror(errno); 197 throw yat::utility::cmd_error(ss.str()); 198 } 199 200 201 std::string Parameter::config_file(void) const 202 { 203 return config_file_.value(); 204 } 205 206 207 bool Parameter::copyright(void) const 122 bool svndigestParameter::copyright(void) const 208 123 { 209 124 return copyright_.present(); … … 211 126 212 127 213 bool Parameter::force(void) const214 {215 return force_.present();216 }217 218 219 bool Parameter::generate_config(void) const220 {221 return generate_config_.present();222 }223 224 225 bool Parameter::ignore_cache(void) const226 {227 return ignore_cache_.present();228 }229 230 231 128 const yat::utility::OptionArg<std::string>& 232 Parameter::format(void) const129 svndigestParameter::format(void) const 233 130 { 234 131 return format_; … … 236 133 237 134 238 void Parameter::init(void)135 void svndigestParameter::init2(void) 239 136 { 240 137 // don't use argv[0] because user may rename the binary 241 cmd_.program_name() = PACKAGE_NAME;138 cmd_.program_name() = "svndigest"; 242 139 anchor_format_.print_arg("=FMT"); 243 config_file_.print_arg("=FILE");244 140 format_.print_arg("=FMT"); 245 root_.print_arg("=ROOT");246 141 target_.print_arg("=TARGET"); 247 std::stringstream ss;248 ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n"249 << PACKAGE << " home page: <" << PACKAGE_URL << ">.\n";250 help_.post_arguments() = ss.str();251 142 help_.synopsis() = 252 143 "Generate statistical report for a subversion repository\n"; 144 145 std::stringstream ss; 146 #ifdef HAVE_PLPLOT 147 ss << "using libplplot "; 148 plstream pls; 149 char* plplot_version = new char[32]; 150 pls.gver(plplot_version); 151 ss << plplot_version << "\n"; 152 delete [] plplot_version; 153 #endif 154 version_.extra(ss.str()); 155 version_.program_name("svndigest"); 253 156 } 254 157 255 158 256 bool Parameter::report(void) const159 bool svndigestParameter::report(void) const 257 160 { 258 161 return report_.value(); … … 260 163 261 164 262 bool Parameter::revisions(void) const165 bool svndigestParameter::revisions(void) const 263 166 { 264 167 return revisions_.present(); … … 266 169 267 170 268 std::string Parameter::root(void) const171 void svndigestParameter::set_default2(void) 269 172 { 270 return root_.value(); 173 271 174 } 272 175 273 274 std::string Parameter::targetdir(void) const176 177 std::string svndigestParameter::targetdir(void) const 275 178 { 276 179 return target_.value(); 277 180 } 278 181 279 280 bool Parameter::verbose(void) const281 {282 return verbose_.present();283 }284 285 286 182 }} // of namespace svndigest and namespace theplu -
trunk/bin/svndigestParameter.h
r1054 r1060 1 #ifndef _theplu_svndigest_ parameter_2 #define _theplu_svndigest_ parameter_1 #ifndef _theplu_svndigest_svndigest_parameter_ 2 #define _theplu_svndigest_svndigest_parameter_ 3 3 4 4 // $Id$ … … 24 24 */ 25 25 26 #include "Parameter.h" 27 26 28 #include "OptionVersion.h" 27 29 … … 37 39 namespace yat { 38 40 namespace utility { 39 class OptionHelp;40 41 class OptionSwitch; 41 42 }} 42 43 namespace svndigest { 43 44 44 class OptionVersion;45 46 45 // class for command line options. 47 class Parameter { 46 class svndigestParameter : public Parameter 47 { 48 48 public: 49 Parameter( int argc, char *argv[]);50 virtual ~ Parameter(void);49 svndigestParameter(void); 50 virtual ~svndigestParameter(void); 51 51 const yat::utility::OptionArg<std::string>& anchor_format(void) const; 52 std::string config_file(void) const;53 52 54 53 bool copyright(void) const; 55 bool force(void) const;56 bool generate_config(void) const ;57 bool ignore_cache(void) const;58 54 const yat::utility::OptionArg<std::string>& format(void) const; 59 55 bool report(void) const; 60 56 bool revisions(void) const; 61 57 /// @return absolute path to root directory 62 std::string root(void) const;63 /// @return absolute path to target directory64 58 std::string targetdir(void) const; 65 bool verbose(void) const;66 59 67 60 private: 68 void analyse(void); 69 // throw cmd_error if path doesn't exist 70 void check_existence(std::string path) const; 71 // throw cmd_error if path is not dir 72 void check_is_dir(std::string path) const; 73 // throw cmd_error if path is not readable 74 void check_readable(std::string path) const; 61 void analyse2(void); 62 void init2(void); 63 void set_default2(void); 75 64 76 void init(void);77 78 yat::utility::CommandLine cmd_;79 65 yat::utility::OptionArg<std::string> anchor_format_; 80 yat::utility::OptionArg<std::string> config_file_;81 66 yat::utility::OptionSwitch copyright_; 82 yat::utility::OptionSwitch force_;83 yat::utility::OptionSwitch generate_config_;84 yat::utility::OptionHelp help_;85 yat::utility::OptionSwitch ignore_cache_;86 67 yat::utility::OptionArg<std::string> format_; 87 68 yat::utility::OptionSwitch report_; 88 69 yat::utility::OptionSwitch revisions_; 89 yat::utility::OptionArg<std::string> root_;90 70 yat::utility::OptionArg<std::string> target_; 91 yat::utility::OptionSwitch verbose_;92 OptionVersion version_;93 94 71 }; 95 72 -
trunk/lib/OptionVersion.cc
r1058 r1060 33 33 #include <apr_version.h> 34 34 35 #ifdef HAVE_PLPLOT36 #include <plplot/plstream.h>37 #endif38 39 35 #include <cstdlib> 40 36 #include <iostream> … … 57 53 yat::utility::ColumnStream cs(std::cout, 1); 58 54 cs.width(0)=79; 59 cs << PACKAGE_NAME<< " " << PACKAGE_VERSION;55 cs << prog_name_ << " " << PACKAGE_VERSION; 60 56 bool no_verbose = verbose_ && verbose_->present() && !verbose_->value(); 61 57 if (!no_verbose) { … … 83 79 cs << apr_version_string(); 84 80 cs << "\n"; 85 #ifdef HAVE_PLPLOT 86 cs << "using libplplot "; 87 plstream pls; 88 char* plplot_version = new char[32]; 89 pls.gver(plplot_version); 90 cs << plplot_version << "\n"; 91 delete [] plplot_version; 92 #endif 81 cs << extra_; 93 82 } 94 83 exit(EXIT_SUCCESS); 95 84 } 96 85 86 87 void OptionVersion::extra(const std::string& str) 88 { 89 extra_ = str; 90 } 91 92 93 void OptionVersion::program_name(const std::string& str) 94 { 95 prog_name_ = str; 96 } 97 97 98 }} // of namespace svndigest and theplu -
trunk/lib/OptionVersion.h
r1059 r1060 58 58 59 59 /** 60 add extra string appended to output 61 */ 62 void extra(const std::string&); 63 64 /** 65 set program name 66 */ 67 void program_name(const std::string&); 68 69 /** 60 70 \brief set version string 61 71 */ … … 64 74 private: 65 75 OptionSwitch* const verbose_; 66 76 std::string extra_; 77 std::string prog_name_; 67 78 68 79 /** -
trunk/test/svncopyright_test.sh
r1055 r1060 31 31 done 32 32 33 ../bin/svncopyright --version | head -n 1 | grep svncopyright || exit_fail 34 33 35 exit_success
Note: See TracChangeset
for help on using the changeset viewer.