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 # ------------------------------------------------------------------------
29 #include <creaImageIOSystem.h>
30 #include <creaImageIOSynchronizer.h>
31 #include "boost/filesystem.hpp"
33 namespace fs = boost::filesystem;
39 //==============================================================
40 Synchronizer::Synchronizer(TreeHandler * th)
44 //==============================================================
46 //==============================================================
47 Synchronizer::~Synchronizer()
51 //==============================================================
53 //==============================================================
54 std::string Synchronizer::Synchronize(bool update)
56 GimmickMessage(1,"Synchronizing "<<std::endl);
58 std::stringstream mess;
60 mHandler->GetAttribute("Image","","","FullFileName",file);
63 while(fin<file.size()-1)
65 fin=file.find('#',ini);
66 SynchronizeFile(update,file.substr(ini,fin-ini),mess);
71 mess<<"Database up to date"<<std::endl;
73 GimmickMessage(1,mess.str());
76 //==============================================================
78 //==============================================================
79 void Synchronizer::SynchronizeFile(bool update, std::string file, std::stringstream& mess)
85 mHandler->DeleteTuple("Image","FullFileName",file);
86 mess<<file<<" has been removed from the DB"<<std::endl;
90 mess<<file<<" State: Non existant"<<std::endl;
95 AttributesMatch(update,file,mess);
98 //==============================================================
100 //==============================================================
101 bool Synchronizer::FileExists(std::string file)
103 GimmickDebugMessage(4,"Verifying if file "<<file<<" exists"<<std::endl);
105 if ( !fs::exists( file ) )
111 //==============================================================
113 //==============================================================
114 void Synchronizer::AttributesMatch(bool update, std::string file, std::stringstream& mess)
116 std::map< std::string, std::string> attr;
117 mHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
118 mReader.ReadAttributes(file,attr);
119 tree::LevelDescriptor::AttributeDescriptorListType adl= mHandler->GetTree().GetAttributeDescriptorList(mHandler->GetTree().GetNumberOfLevels()-1);
120 tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
121 for (a = adl.begin();a!=adl.end();++a)
123 std::string databaseVal;
124 mHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal);
125 std::string fileVal=attr.find(a->GetKey())->second;
126 if ( a->GetFlags()==0 && databaseVal.compare(fileVal)!=0 )
130 mHandler->SetAttribute("Image",a->GetKey(),fileVal,"FullFileName", file);
131 mess<<file<<" has been updated in the DB"<<std::endl;
135 mess<<file<<" State: Attributes differ"<<std::endl;
140 //==============================================================