]> Creatis software - bbtk.git/blob - kernel/appli/bbRegeneratePackageDoc/bbRegeneratePackageDoc.cpp
#3202 BBTK Feature New Normal - fast algorithm for ImageBoundaries box
[bbtk.git] / kernel / appli / bbRegeneratePackageDoc / bbRegeneratePackageDoc.cpp
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
28
29 #include <bbtkWx.h>
30 #include <bbtkInterpreter.h>
31 #include <bbtkConfigurationFile.h>
32 #include <bbtkUtilities.h>
33
34 //==========================================================================
35 void RegenerateDoc ( bbtk::Package::Pointer p, std::string& doc_path )
36 {
37         
38   std::string pack_name(p->GetName());
39   std::string pack_path = doc_path + pack_name;
40   // Creating directory
41   if ( ! bbtk::Utilities::FileExists(pack_path) )
42     {
43       std::string command("mkdir \"" +pack_path+ "\"");
44       system( command.c_str() );
45     }
46   std::string pack_index(pack_path);
47   pack_index += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
48   pack_index += "index.html";
49   
50   std::cout << "* Generating doc for package '"<<pack_name<<"' in "
51             << pack_index << std::endl;
52   
53   p->SetDocURL(pack_index);
54   p->SetDocRelativeURL("index.html");
55         
56         
57   p->CreateHtmlPage(pack_index,"bbtk",pack_name,"","",0,0,true); //true);
58         
59         
60 }
61
62
63 void Usage()
64 {
65   std::cout << "usage : bbRegeneratePackageDoc [<package name>|-a] [-q|-v]" 
66             << std::endl
67             << "        -a : All packages"<<std::endl
68             << "        -q : Quiet"<<std::endl
69             << "        -v : Verbose"<<std::endl;
70 }
71
72 //==========================================================================
73 int main(int argc, char **argv)
74 {
75   std::string pack("-a");
76   if (argc==2) 
77     {
78       pack = std::string(argv[1]);
79     }
80   else if (argc==3)
81     {
82       pack = std::string(argv[1]);
83       std::string param(argv[2]);
84       if (param=="-q") bbtk::MessageManager::SetMessageLevel("max",0);
85       else if (param=="-v") bbtk::MessageManager::SetMessageLevel("all",9);
86       else 
87         {
88           Usage();
89           return 0;
90         }
91     }
92   else 
93     {
94       Usage();
95       return 0;
96     }
97  
98   try
99     {
100                 std::string doc_path = bbtk::ConfigurationFile::GetInstance().Get_doc_path();
101       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
102       doc_path += "bbdoc";
103       doc_path += bbtk::ConfigurationFile::GetInstance().Get_file_separator();
104       bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
105       I->SetCommandLine(true);
106       I->SetThrow(false);
107 //std::cout<<"JCP bbRegeneratePackageDoc.cpp  I->InterpretLine( exec freeze_no_error);"<<std::endl;
108           I->InterpretLine( "exec freeze_no_error");
109       if (pack != "-a") 
110         {
111
112                 I->InterpretLine( "include "+pack);
113                 I->InterpretLine( "include "+pack+"-appli");
114                 bbtk::Package::Pointer p = I->GetExecuter()->GetFactory()->GetPackage(pack);
115 //std::cout<<"JCP bbRegeneratePackageDoc.cpp RegenerateDoc(I->GetExecuter()->GetFactory()->GetPackage(pack),doc_path);"<<std::endl;
116                 RegenerateDoc(I->GetExecuter()->GetFactory()->GetPackage(pack),doc_path);
117         }
118       else
119         {
120 //std::cout<<"JCP bbRegeneratePackageDoc.cpp I->InterpretLine( include );"<<std::endl;
121                 I->InterpretLine( "include *");
122                 bbtk::Factory::PackageMapType::const_iterator i;
123           for (i  = I->GetExecuter()->GetFactory()->GetPackageMap().begin();
124                i != I->GetExecuter()->GetFactory()->GetPackageMap().end();
125                ++i)
126             {
127 //std::cout<<" if (i->second->GetName()==user) continue;"<<std::endl;
128               if (i->second->GetName()=="user") continue;
129               RegenerateDoc(i->second,doc_path);
130             }
131         }
132     }
133   catch (bbtk::Exception e)
134     {
135       std::cout << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
136       return 1;
137     }
138     // JGRR & CM : this kills this never-ending process when it's supposed to! 
139     std::cout << "bbRegeneratePackageDoc has finished normally. It will be aborted on purpose."<< std::endl; 
140     abort();
141     // EO JGRR CM
142         return 0;
143 }
144 //==========================================================================
145
146