]> Creatis software - creaImageIO.git/blobdiff - appli/gimmick/main.cxx
Feature #1764
[creaImageIO.git] / appli / gimmick / main.cxx
index bee8ff1c269aa6b2137bbd82c9d695eaa1854764..f5f1c1ce7b1250c7a92a153ec30bff5de055d6de 100644 (file)
@@ -1,5 +1,31 @@
+/*
+       # ---------------------------------------------------------------------
+       #
+       # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
+       #                        pour la Santé)
+       # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+       # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+       # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+       #
+       #  This software is governed by the CeCILL-B license under French law and 
+       #  abiding by the rules of distribution of free software. You can  use, 
+       #  modify and/ or redistribute the software under the terms of the CeCILL-B 
+       #  license as circulated by CEA, CNRS and INRIA at the following URL 
+       #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+       #  or in the file LICENSE.txt.
+       #
+       #  As a counterpart to the access to the source code and  rights to copy,
+       #  modify and redistribute granted by the license, users are provided only
+       #  with a limited warranty  and the software's author,  the holder of the
+       #  economic rights,  and the successive licensors  have only  limited
+       #  liability. 
+       #
+       #  The fact that you are presently reading this means that you have had
+       #  knowledge of the CeCILL-B license and that you accept its terms.
+       # ------------------------------------------------------------------------
+*/
 #include <boost/program_options.hpp>
+
 using namespace boost;
 namespace po = boost::program_options;
 
@@ -25,18 +51,21 @@ int main(int ac, char* av[])
   po::options_description command("COMMANDS");
   command.add_options()
     ("print,p","Prints the local database tree  (default=off)")
-    ("file,f",po::value< vector<string> >(),"Adds the file to the local database")
+    ("files,f",po::value< vector<string> >(),"Adds the file(s) to the local database")
     ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
-    ("sync,s","Synchronizes the local database with the files")
-    ("recurse,r","Recurse into sub-directories  (default=off)");
-  
+    ("sync,s",po::value< vector<string> >(),"Synchronizes the local database with the files")
+       ("copy,c",po::value< vector<string> >(),"Copies the files into a local directory");
+
   //Describes third group of options
   po::options_description option("OPTIONS");
   option.add_options()
     ("verbose,v",po::value<int>(&verb),"Verbosity level (default=`1')")
-    ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')");
-  
-  
+    ("debug,D",po::value<int>(&deb),"Debug messages level (default=`0')")
+       ("recurse,r","Recurse into sub-directories  (default=off)")
+       ("repair,R","Repair the database (on synchronization) (default=off)")
+       ("check,C","Check for attribute differences (on synchronization) (default=off)")
+       ("handler,H",po::value<string>(&handler),"Handler name (default=`Local database')");
   //Adds the groups into a big one
   po::options_description cmdline_options;
   cmdline_options.add(generic).add(command).add(option);
@@ -46,6 +75,7 @@ int main(int ac, char* av[])
   po::store(po::parse_command_line(ac, av, cmdline_options), vm);
   po::notify(vm);    
   
+  
   //Does something on each option
   //GENERIC
   if (vm.count("help")) {
@@ -71,7 +101,9 @@ int main(int ac, char* av[])
        ||vm.count("file")
        ||vm.count("dir")
        ||vm.count("sync")
+       ||vm.count("copy")
        )
+  {
 
     try
       {
@@ -86,17 +118,36 @@ int main(int ac, char* av[])
        }
        if (vm.count("dir")) {
          std::vector<std::string> dirs=vm["dir"].as< vector<string> >();
-         g.AddDir(handler,dirs.front(), vm.count("recurse"));
+         bool recu=false;
+         std::stringstream out;
+         out<<vm.count("recurse");
+         if(out.str().compare("1")==0){recu=true;}
+         g.AddDir(handler,dirs.front(), recu);
        }
        if (vm.count("sync")) {
-         g.Synchronize(true,g.GetTreeHandler(handler));
+         bool rep=false;
+      bool chk=false;
+         std::vector<std::string> name=vm["sync"].as< vector<string> >();
+         std::stringstream out;
+         out<<vm.count("repair");
+         if(out.str().compare("1")==0){rep=true;}
+         std::stringstream out2;
+         out2<<vm.count("check");
+         if(out2.str().compare("1")==0){chk=true;}
+         cout<<g.Synchronize(name.front(),rep,chk)<<"\n";
        }       
+       if (vm.count("copy")) {
+         std::vector<std::string> name=vm["copy"].as< vector<string> >();
+         g.CopyFiles(name,handler);
+       }
        g.Finalize();
       }
     catch (crea::Exception e)
       {
        e.Print();
       }
+  }
+         
   
   return 0;
 }