Documentation for OpenFLUID 2.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WareSrcHelpers.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file WareSrcHelpers.hpp
34 
35  @author Armel THÖNI <armel.thoni@inra.fr>
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inrae.fr>
37  @author Dorian GERARDIN <dorian.gerardin@inrae.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_WARESDEV_WARESRCHELPERS_HPP__
42 #define __OPENFLUID_WARESDEV_WARESRCHELPERS_HPP__
43 
44 
45 #include <set>
46 #include <vector>
47 #include <string>
48 #include <regex>
49 
54 #include <openfluid/dllexport.hpp>
55 
56 
57 namespace openfluid { namespace waresdev {
58 
59 
61 {
62 
63  private:
64 
65  std::string m_BuildDirRegexStr = "_build-";
66  std::string ModeArg = "(release|debug)";
67  std::string VersionArg = "[0-9]+\\.[0-9]+";
68  std::string VersionMajorMinorStr;
69  std::string CurrentVersionRegex;
70 
71 
72  public:
73 
74  WarePurgeHandler(bool CurrentVersion, bool OtherVersions, bool ReleaseMode, bool DebugMode)
75  {
76 
78  CurrentVersionRegex = openfluid::tools::replace(VersionMajorMinorStr, ".", "\\.");
79 
80  if (CurrentVersion && !OtherVersions) // Current version only
81  {
82  VersionArg = CurrentVersionRegex;
83  }
84  else if (!CurrentVersion && OtherVersions) // Other versions only
85  {
86  VersionArg = "(?!"+CurrentVersionRegex+")[0-9]+\\.[0-9]+";
87  }
88 
89  if (ReleaseMode && !DebugMode) // Release mode only
90  {
91  ModeArg = "release";
92  }
93  else if (!ReleaseMode && DebugMode) // Debug mode only
94  {
95  ModeArg = "debug";
96  }
97 
98  m_BuildDirRegexStr = m_BuildDirRegexStr + ModeArg + "-" + VersionArg;
99  }
100 
101 
102  // =====================================================================
103  // =====================================================================
104 
105 
107  std::function<void(std::string, std::string)> WriteMessageFunc,
108  std::function<void(bool)> EmitSignal)
109  {
110  std::regex FilterRegExp(m_BuildDirRegexStr);
111 
112  if(!WarePath.exists())
113  {
114  WriteMessageFunc(WarePath.toGeneric() + ": Ware path does not exists ", "Error");
115  return;
116  }
117 
118  for (const auto& Entry : std::filesystem::directory_iterator(WarePath.stdPath()))
119  {
120  auto EntryFSP = openfluid::tools::FilesystemPath(Entry.path().string());
121  if (std::regex_match(EntryFSP.filename(), FilterRegExp))
122  {
123  EntryFSP.removeDirectory();
124 
125  if(EntryFSP.isDirectory())
126  {
127  WriteMessageFunc(EntryFSP.filename() + ": Error ", "Error");
128  EmitSignal(false);
129  }
130  else
131  {
132  WriteMessageFunc(EntryFSP.filename() + ": Deleted ", "Success");
133  EmitSignal(true);
134  }
135  }
136  }
137  }
138 
140  {
141 
142  }
143 };
144 
145 
146 // TODO reuse this wherever possible
147 inline static const std::vector<std::string> CppFilesExt = {"cpp","hpp","cc","hh","cxx","hxx","C","H","h"};
148 
149 
150 // =====================================================================
151 // =====================================================================
152 
153 
154 /**
155  Returns true if the given file path is a C++ source file (based on its extension)
156  @param[in] FileObj The file path
157  @return true if the file extension is a C++ extension
158 */
160 
161 
162 // =====================================================================
163 // =====================================================================
164 
165 
166 /**
167  Returns true if the given file path is a CMake file (based on its name and/or extension)
168  @param[in] FileObj The file path
169  @return true if the file a CMake file
170 */
172 
173 
174 // =====================================================================
175 // =====================================================================
176 
177 
178 /**
179  Checks if a given user can do read operations on a ware based on the RO/RW lists
180  @param[in] UserName the current user to check
181  @param[in] IsLoggedIn true if logged in to hub
182  @param[in] ROUsers the set of users with read only access
183  @param[in] RWUsers the set of users with read+write access
184  @return true if user is allowed to access the corresponding ware
185 */
186 bool OPENFLUID_API hasUserAccess(const std::string& UserName, bool IsLoggedIn,
187  const std::set<std::string>& ROUsers,
188  const std::set<std::string>& RWUsers={});
189 
190 
191 // =====================================================================
192 // =====================================================================
193 
194 
195 /**
196  Checks if a given ware id is found in current workspace.
197  Wrapper of WareSrcEnquirer function
198  @param[in] WarePath the ware path
199  @return true if ware found in workspace
200 */
201 bool OPENFLUID_API isWareInCurrentWorkspace(const std::string& WarePath);
202 
203 
204 // =====================================================================
205 // =====================================================================
206 
207 
208 /**
209  Initializes a map of CMake variables according to the OpenFLUID installation context
210  @return a map of variables
211 */
212 std::map<std::string,std::string> OPENFLUID_API initializeConfigureVariables();
213 
214 
215 } } // namespaces
216 
217 
218 #endif /* __OPENFLUID_WARESDEV_WARESRCHELPERS_HPP__ */
static std::string getVersionMajorMinor()
Definition: Environment.hpp:196
Definition: FilesystemPath.hpp:62
std::string toGeneric() const
const std::filesystem::path & stdPath() const
bool exists(const std::string &Path="") const
Definition: WareSrcHelpers.hpp:61
void purge(openfluid::tools::FilesystemPath WarePath, std::function< void(std::string, std::string)> WriteMessageFunc, std::function< void(bool)> EmitSignal)
Definition: WareSrcHelpers.hpp:106
WarePurgeHandler(bool CurrentVersion, bool OtherVersions, bool ReleaseMode, bool DebugMode)
Definition: WareSrcHelpers.hpp:74
~WarePurgeHandler()
Definition: WareSrcHelpers.hpp:139
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::string OPENFLUID_API replace(const std::string &Str, const std::string &SearchStr, const std::string &ReplaceStr)
static const std::vector< std::string > CppFilesExt
Definition: WareSrcHelpers.hpp:147
bool OPENFLUID_API IsCppFile(const openfluid::tools::FilesystemPath &FileObj)
bool OPENFLUID_API hasUserAccess(const std::string &UserName, bool IsLoggedIn, const std::set< std::string > &ROUsers, const std::set< std::string > &RWUsers={})
bool OPENFLUID_API isWareInCurrentWorkspace(const std::string &WarePath)
std::map< std::string, std::string > OPENFLUID_API initializeConfigureVariables()
bool OPENFLUID_API IsCMakeFile(const openfluid::tools::FilesystemPath &FileObj)
Definition: ApplicationException.hpp:47