creaImageIO_lib
main.cxx File Reference
#include <boost/program_options.hpp>
#include <creaImageIOGimmick.h>
#include <creaMessageManager.h>
Include dependency graph for main.cxx:

Go to the source code of this file.

Functions

int main (int ac, char *av[])
 

Function Documentation

int main ( int  ac,
char *  av[] 
)

Definition at line 37 of file main.cxx.

References creaImageIO::Gimmick::AddDir(), creaImageIO::Gimmick::AddFiles(), creaImageIO::Gimmick::CopyFiles(), creaImageIO::Gimmick::Finalize(), creaImageIO::Gimmick::GetTreeHandler(), creaImageIO::Gimmick::Initialize(), creaImageIO::TreeHandler::LoadChildren(), creaImageIO::Gimmick::Print(), creaImageIO::Gimmick::SetDebugMessageLevel(), creaImageIO::Gimmick::SetMessageLevel(), and creaImageIO::Gimmick::Synchronize().

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 }

Here is the call graph for this function: