2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
27 #include <boost/program_options.hpp>
29 using namespace boost;
30 namespace po = boost::program_options;
32 #include <creaImageIOGimmick.h>
33 #include <creaMessageManager.h>
37 int main(int ac, char* av[])
40 creaImageIO::Gimmick g;
42 std::string handler("Local database");
44 //Describes first group of options
45 po::options_description generic("GENERIC");
47 ("help,h", "Print help and exit")
48 ("version,V", "Print version and exit");
50 //Describes second group of options
51 po::options_description command("COMMANDS");
53 ("print,p","Prints the local database tree (default=off)")
54 ("files,f",po::value< vector<string> >(),"Adds the file(s) to the local database")
55 ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
56 ("sync,s",po::value< vector<string> >(),"Synchronizes the local database with the files")
57 ("copy,c",po::value< vector<string> >(),"Copies the files into a local directory");
59 //Describes third group of options
60 po::options_description option("OPTIONS");
62 ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
63 ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')")
64 ("recurse,r","Recurse into sub-directories (default=off)")
65 ("repair,R","Repair the database (on synchronization) (default=off)")
66 ("check,C","Check for attribute differences (on synchronization) (default=off)")
67 ("handler,H",po::value<string>(&handler),"Handler name (default=`Local database')");
69 //Adds the groups into a big one
70 po::options_description cmdline_options;
71 cmdline_options.add(generic).add(command).add(option);
73 //Adds the corresponding variables
75 po::store(po::parse_command_line(ac, av, cmdline_options), vm);
79 //Does something on each option
81 if (vm.count("help")) {
82 cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
83 cout << cmdline_options << "\n";
85 if (vm.count("version")) {
86 cout << "gimmick 0.1.0\n";
90 if (vm.count("verbose")) {
91 g.SetMessageLevel(verb);
92 cout << "Verbose level is now "<<verb<<"\n";
94 if (vm.count("debug")) {
95 g.SetDebugMessageLevel(deb);
96 cout << "Debug level is now "<<deb<<"\n";
100 if ( vm.count("print")
111 if (vm.count("print")) {
112 g.GetTreeHandler(handler)->LoadChildren(0,0);
115 if (vm.count("file")) {
116 std::vector<std::string> files=vm["file"].as< vector<string> >();
117 g.AddFiles(handler,files);
119 if (vm.count("dir")) {
120 std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
122 std::stringstream out;
123 out<<vm.count("recurse");
124 if(out.str().compare("1")==0){recu=true;}
125 g.AddDir(handler,dirs.front(), recu);
127 if (vm.count("sync")) {
130 std::vector<std::string> name=vm["sync"].as< vector<string> >();
131 std::stringstream out;
132 out<<vm.count("repair");
133 if(out.str().compare("1")==0){rep=true;}
134 std::stringstream out2;
135 out2<<vm.count("check");
136 if(out2.str().compare("1")==0){chk=true;}
137 cout<<g.Synchronize(name.front(),rep,chk)<<"\n";
139 if (vm.count("copy")) {
140 std::vector<std::string> name=vm["copy"].as< vector<string> >();
141 g.CopyFiles(name,handler);
145 catch (crea::Exception e)