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