8 #include "../CEBLIncludes.hpp"
10 #include "../TextUtils.hpp"
11 #include "../Exceptions.hpp"
21 #define BOOST_FILESYSTEM_VERSION 2
22 #include <boost/filesystem/operations.hpp>
23 #include <boost/filesystem/convenience.hpp>
24 #include <boost/filesystem/fstream.hpp>
25 #include <boost/filesystem/path.hpp>
30 namespace fs = boost::filesystem;
34 ostream& operator<<(ostream& os, const vector<T>& v)
36 copy(v.begin(), v.end(), ostream_iterator<T>(os,
" "));
44 session_filename =
"";
45 default_channels_filename = string(HOMEDIR) +
"/.cebl/conf/channels-19.conf";
46 string_table_filename = string(HOMEDIR) +
"/.cebl/conf/string-table-en.txt";
58 session_filename =
"";
62 (
"help",
"Print Help")
63 (
"version",
"Print Version String")
66 po::options_description hidden(
"Hidden options");
68 (
"session-file", po::value< vector<string> >(),
"session file")
73 po::options_description visible(
"CEBL Options");
74 visible.add(desc).add(hidden);
76 po::positional_options_description p;
77 p.add(
"session-file", -1);
80 po::store(po::command_line_parser(ac, av).
81 options(visible).positional(p).run(), vm);
90 if (vm.count(
"version"))
95 if (vm.count(
"session-file"))
97 session_filename = vm[
"session-file"].as< vector<string> >()[0];
101 for(
unsigned i=0;i<option_list.size();i++)
103 string name = option_list[i];
104 set_options[name] =
"None";
107 set_options[name] = vm[name].as< vector<string> >()[0];
111 catch(exception& e) {
112 cerr <<
"error: " << e.what() <<
"\n";
116 cerr <<
"Exception of unknown type!\n";
128 char *pref_path = NULL;
129 bool pref_path_specified =
true;
130 pref_path = getenv(
"CEBL_PREF_DIR");
132 pref_path_specified =
false;
135 if(!pref_path_specified)
137 string home_path = string(HOMEDIR);
142 conf_dir = home_path+
"/.cebl/";
146 conf_dir = pref_path;
152 full_path = fs::system_complete(fs::path(conf_dir, fs::native));
154 if(!fs::exists(full_path))
158 have_conf_dir =
false;
167 fs::create_directory(full_path);
168 fs::create_directory(fs::system_complete(fs::path(conf_dir+
"/plugins", fs::native)));
169 fs::create_directory(fs::system_complete(fs::path(conf_dir+
"/plugins/classifiers", fs::native)));
170 fs::create_directory(fs::system_complete(fs::path(conf_dir+
"/plugins/filters", fs::native)));
171 fs::create_directory(fs::system_complete(fs::path(conf_dir+
"/plugins/features", fs::native)));
178 throw FileException(
"Could not create cebl configuration directory.");
183 if(!fs::is_directory(full_path))
185 throw FileException(conf_dir+
" is not a directory. Please remove the file "+conf_dir+
".");
193 paths.push_back(conf_dir);
195 string conf_file = conf_dir+
"/cebl.conf";
196 full_path = fs::system_complete(fs::path(conf_file, fs::native));
197 if(!fs::exists(full_path))
206 throw FileException(
"Failed to create initial configuration file.\n");
213 po::options_description config(
"Configuration");
216 po::value< vector<string> >()->composing(),
220 po::options_description config_file_options;
221 config_file_options.add(config);
224 po::variables_map vm;
226 ifstream ifs(conf_file.c_str());
227 store(parse_config_file(ifs, config_file_options), vm);
232 cout <<
"Path = " << vm[
"path"].as<
string >();
237 cout << e.what() <<
"\n";
249 return this->default_channels_filename;
255 string full_name = name;
256 if(short_name !=
'\0')
257 full_name = full_name+
","+short_name;
259 option_list.push_back(name);
261 (full_name.c_str(), po::value< vector<string> >(), description.c_str());
266 return set_options[name];