00001 #include <boost/program_options.hpp>
00002
00003 using namespace boost;
00004 namespace po = boost::program_options;
00005
00006 #include <creaImageIOGimmick.h>
00007 #include <creaMessageManager.h>
00008
00009 using namespace std;
00010
00011 int main(int ac, char* av[])
00012 {
00013
00014 creaImageIO::Gimmick g;
00015 int verb,deb;
00016 std::string handler("Local database");
00017
00018
00019 po::options_description generic("GENERIC");
00020 generic.add_options()
00021 ("help,h", "Print help and exit")
00022 ("version,V", "Print version and exit");
00023
00024
00025 po::options_description command("COMMANDS");
00026 command.add_options()
00027 ("print,p","Prints the local database tree (default=off)")
00028 ("files,f",po::value< vector<string> >(),"Adds the file(s) to the local database")
00029 ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
00030 ("sync,s",po::value< vector<string> >(),"Synchronizes the local database with the files")
00031 ("copy,c",po::value< vector<string> >(),"Copies the files into a local directory");
00032
00033
00034 po::options_description option("OPTIONS");
00035 option.add_options()
00036 ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
00037 ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')")
00038 ("recurse,r","Recurse into sub-directories (default=off)")
00039 ("repair,R","Repair the database (on synchronization) (default=off)")
00040 ("check,C","Check for attribute differences (on synchronization) (default=off)")
00041 ("handler,H",po::value<string>(&handler),"Handler name (default=`Local database')");
00042
00043
00044 po::options_description cmdline_options;
00045 cmdline_options.add(generic).add(command).add(option);
00046
00047
00048 po::variables_map vm;
00049 po::store(po::parse_command_line(ac, av, cmdline_options), vm);
00050 po::notify(vm);
00051
00052
00053
00054
00055 if (vm.count("help")) {
00056 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
00057 cout << cmdline_options << "\n";
00058 }
00059 if (vm.count("version")) {
00060 cout << "gimmick 0.1.0\n";
00061 }
00062
00063
00064 if (vm.count("verbose")) {
00065 g.SetMessageLevel(verb);
00066 cout << "Verbose level is now "<<verb<<"\n";
00067 }
00068 if (vm.count("debug")) {
00069 g.SetDebugMessageLevel(deb);
00070 cout << "Debug level is now "<<deb<<"\n";
00071 }
00072
00073
00074 if ( vm.count("print")
00075 ||vm.count("file")
00076 ||vm.count("dir")
00077 ||vm.count("sync")
00078 ||vm.count("copy")
00079 )
00080 {
00081
00082 try
00083 {
00084 g.Initialize();
00085 if (vm.count("print")) {
00086 g.GetTreeHandler(handler)->LoadChildren(0,0);
00087 g.Print(handler);
00088 }
00089 if (vm.count("file")) {
00090 std::vector<std::string> files=vm["file"].as< vector<string> >();
00091 g.AddFiles(handler,files);
00092 }
00093 if (vm.count("dir")) {
00094 std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
00095 bool recu=false;
00096 std::stringstream out;
00097 out<<vm.count("recurse");
00098 if(out.str().compare("1")==0){recu=true;}
00099 g.AddDir(handler,dirs.front(), recu);
00100 }
00101 if (vm.count("sync")) {
00102 bool rep=false;
00103 bool chk=false;
00104 std::vector<std::string> name=vm["sync"].as< vector<string> >();
00105 std::stringstream out;
00106 out<<vm.count("repair");
00107 if(out.str().compare("1")==0){rep=true;}
00108 std::stringstream out2;
00109 out2<<vm.count("check");
00110 if(out2.str().compare("1")==0){chk=true;}
00111 cout<<g.Synchronize(name.front(),rep,chk)<<"\n";
00112 }
00113 if (vm.count("copy")) {
00114 std::vector<std::string> name=vm["copy"].as< vector<string> >();
00115 g.CopyFiles(name,handler);
00116 }
00117 g.Finalize();
00118 }
00119 catch (crea::Exception e)
00120 {
00121 e.Print();
00122 }
00123 }
00124
00125
00126 return 0;
00127 }