creaImageIO_lib
main.cxx
Go to the documentation of this file.
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  # pour la Santé)
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
9  #
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.
16  #
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
21  # liability.
22  #
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  # ------------------------------------------------------------------------
26 */
27 #include <boost/program_options.hpp>
28 
29 using namespace boost;
30 namespace po = boost::program_options;
31 
32 #include <creaImageIOGimmick.h>
33 #include <creaMessageManager.h>
34 
35 using namespace std;
36 
37 int main(int ac, char* av[])
38 {
39 
41  int verb,deb;
42  std::string handler("Local database");
43 
44  //Describes first group of options
45  po::options_description generic("GENERIC");
46  generic.add_options()
47  ("help,h", "Print help and exit")
48  ("version,V", "Print version and exit");
49 
50  //Describes second group of options
51  po::options_description command("COMMANDS");
52  command.add_options()
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");
58 
59  //Describes third group of options
60  po::options_description option("OPTIONS");
61  option.add_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')");
68 
69  //Adds the groups into a big one
70  po::options_description cmdline_options;
71  cmdline_options.add(generic).add(command).add(option);
72 
73  //Adds the corresponding variables
74  po::variables_map vm;
75  po::store(po::parse_command_line(ac, av, cmdline_options), vm);
76  po::notify(vm);
77 
78 
79  //Does something on each option
80  //GENERIC
81  if (vm.count("help")) {
82  cout << "Usage: gimmick COMMAND [OPTIONS]:\n";
83  cout << cmdline_options << "\n";
84  }
85  if (vm.count("version")) {
86  cout << "gimmick 0.1.0\n";
87  }
88 
89  //OPTIONS
90  if (vm.count("verbose")) {
91  g.SetMessageLevel(verb);
92  cout << "Verbose level is now "<<verb<<"\n";
93  }
94  if (vm.count("debug")) {
95  g.SetDebugMessageLevel(deb);
96  cout << "Debug level is now "<<deb<<"\n";
97  }
98 
99  //COMMANDS
100  if ( vm.count("print")
101  ||vm.count("file")
102  ||vm.count("dir")
103  ||vm.count("sync")
104  ||vm.count("copy")
105  )
106  {
107 
108  try
109  {
110  g.Initialize();
111  if (vm.count("print")) {
112  g.GetTreeHandler(handler)->LoadChildren(0,0);
113  g.Print(handler);
114  }
115  if (vm.count("file")) {
116  std::vector<std::string> files=vm["file"].as< vector<string> >();
117  g.AddFiles(handler,files);
118  }
119  if (vm.count("dir")) {
120  std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
121  bool recu=false;
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);
126  }
127  if (vm.count("sync")) {
128  bool rep=false;
129  bool chk=false;
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";
138  }
139  if (vm.count("copy")) {
140  std::vector<std::string> name=vm["copy"].as< vector<string> >();
141  g.CopyFiles(name,handler);
142  }
143  g.Finalize();
144  }
145  catch (crea::Exception e)
146  {
147  e.Print();
148  }
149  }
150 
151 
152  return 0;
153 }