Merge lp:~vjsamuel/drizzle/archive-reader-config-file into lp:~drizzle-trunk/drizzle/development

Proposed by Vijay Samuel
Status: Merged
Merged at revision: 1686
Proposed branch: lp:~vjsamuel/drizzle/archive-reader-config-file
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 135 lines (+49/-28)
1 file modified
plugin/archive/archive_reader.cc (+49/-28)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/archive-reader-config-file
Reviewer Review Type Date Requested Status
Drizzle Merge Team Pending
Review via email: mp+31723@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugin/archive/archive_reader.cc'
--- plugin/archive/archive_reader.cc 2010-08-02 18:35:08 +0000
+++ plugin/archive/archive_reader.cc 2010-08-04 08:46:42 +0000
@@ -21,6 +21,8 @@
21#include "config.h"21#include "config.h"
22#include <iostream>22#include <iostream>
23#include <string>23#include <string>
24#include <fstream>
25#include <drizzled/configmake.h>
24using namespace std;26using namespace std;
25#include <boost/program_options.hpp>27#include <boost/program_options.hpp>
26namespace po= boost::program_options;28namespace po= boost::program_options;
@@ -40,8 +42,6 @@
4042
41string opt_tmpdir;43string opt_tmpdir;
42uint64_t new_auto_increment_value;44uint64_t new_auto_increment_value;
43static const char *load_default_groups[]= { "archive_reader", 0 };
44static char **default_argv;
45bool opt_check, 45bool opt_check,
46 opt_force,46 opt_force,
47 opt_backup, 47 opt_backup,
@@ -55,58 +55,80 @@
55{55{
56try56try
57{57{
58 po::options_description long_options("Allowed Options");58 po::options_description commandline_options("Options used only in command line");
59 long_options.add_options()59 commandline_options.add_options()
60 ("back_up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
61 "Make a backup of an archive table.")
62 ("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
63 "Check table for errors")
64 ("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
65 "Extract the table protobuf message.")
66 ("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),60 ("force,f",po::value<bool>(&opt_force)->default_value(false)->zero_tokens(),
67 "Restart with -r if there are any errors in the table")61 "Restart with -r if there are any errors in the table")
68 ("help,?","Display this help and exit")62 ("help,?","Display this help and exit")
63 ("version,V","Print version and exit")
64 ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
65 "Configuration file defaults are not used if no-defaults is set")
66 ;
67
68 po::options_description archive_reader_options("Options specific to the archive reader");
69 archive_reader_options.add_options()
70 ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),
71 "Path for temporary files.")
72 ("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),
73 "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.")
74 ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
75 "Only print errors. One can use two -s to make archive_reader very silent.")
69 ("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),76 ("quick,q",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
70 "Faster repair but not modifying the data")77 "Faster repair but not modifying the data")
71 ("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),78 ("repair,r",po::value<bool>(&opt_quick)->default_value(false)->zero_tokens(),
72 "Repair a damaged Archive version 3 or above file.")79 "Repair a damaged Archive version 3 or above file.")
73 ("set-auto-increment,A",po::value<uint64_t>(&new_auto_increment_value)->default_value(0),80 ("back-up,b",po::value<bool>(&opt_backup)->default_value(false)->zero_tokens(),
74 "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.")81 "Make a backup of an archive table.")
75 ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),82 ("check,c",po::value<bool>(&opt_check)->default_value(false)->zero_tokens(),
76 "Only print errors. One can use two -s to make archive_reader very silent.")83 "Check table for errors")
77 ("tmpdir,t",po::value<string>(&opt_tmpdir)->default_value(""),84 ("extract-table-message,e",po::value<bool>(&opt_extract_table_message)->default_value(false)->zero_tokens(),
78 "Path for temporary files.") 85 "Extract the table protobuf message.")
79 ("version,V","Print version and exit")
80 ;86 ;
8187
82 unsigned int ret;88 unsigned int ret;
83 azio_stream reader_handle;89 azio_stream reader_handle;
8490
85 internal::my_init();91 std::string system_config_dir_archive_reader(SYSCONFDIR);
86 MY_INIT(argv[0]);92 system_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
87 internal::load_defaults("drizzle", load_default_groups, &argc, &argv);93
88 default_argv= argv;94 std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
89 95
96 po::options_description long_options("Allowed Options");
97 long_options.add(commandline_options).add(archive_reader_options);
98
90 po::variables_map vm;99 po::variables_map vm;
91 po::store(po::parse_command_line(argc,argv,long_options),vm);100 po::store(po::parse_command_line(argc,argv,long_options),vm);
101
102 if (! vm["no-defaults"].as<bool>())
103 {
104 std::string user_config_dir_archive_reader(user_config_dir);
105 user_config_dir_archive_reader.append("/drizzle/archive_reader.cnf");
106
107 ifstream user_archive_reader_ifs(user_config_dir_archive_reader.c_str());
108 po::store(parse_config_file(user_archive_reader_ifs, archive_reader_options), vm);
109
110 ifstream system_archive_reader_ifs(system_config_dir_archive_reader.c_str());
111 store(parse_config_file(system_archive_reader_ifs, archive_reader_options), vm);
112
113 }
92 po::notify(vm);114 po::notify(vm);
93115
94 if(vm.count("force")||vm.count("quiet")||vm.count("tmpdir"))116 if (vm.count("force") || vm.count("quiet") || vm.count("tmpdir"))
95 cout<<"Not implemented yet";117 cout << "Not implemented yet";
96118
97 if(vm.count("version"))119 if (vm.count("version"))
98 {120 {
99 printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,121 printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
100 HOST_VENDOR, HOST_OS, HOST_CPU);122 HOST_VENDOR, HOST_OS, HOST_CPU);
101 exit(0);123 exit(0);
102 }124 }
103 125
104 if(vm.count("set-auto-increment"))126 if (vm.count("set-auto-increment"))
105 {127 {
106 opt_autoincrement= true;128 opt_autoincrement= true;
107 }129 }
108130
109 if(vm.count("help")||argc == 0)131 if (vm.count("help") || argc == 0)
110 {132 {
111 printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,133 printf("%s Ver %s, for %s-%s (%s)\n", internal::my_progname, SHOW_VERSION,
112 HOST_VENDOR, HOST_OS, HOST_CPU);134 HOST_VENDOR, HOST_OS, HOST_CPU);
@@ -116,8 +138,7 @@
116 "license\n");138 "license\n");
117 puts("Read and modify Archive files directly\n");139 puts("Read and modify Archive files directly\n");
118 printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);140 printf("Usage: %s [OPTIONS] file_to_be_looked_at [file_for_backup]\n", internal::my_progname);
119 internal::print_defaults("drizzle", load_default_groups);141 cout << long_options << endl;
120 cout<<long_options<<endl;
121 exit(0); 142 exit(0);
122 }143 }
123 144