LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Utils.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "lsst/utils/Utils.h"
24 
25 #include <iostream>
26 #include <sstream>
27 #include <string>
28 #include "boost/regex.hpp"
29 #include "lsst/pex/exceptions.h"
30 
31 namespace lsst {
32 namespace utils {
53 void guessSvnVersion(std::string const& headURL,
54  std::string& version
55  ) {
56  const boost::regex getURL("^\\$HeadURL:\\s+([^$ ]+)\\s*\\$$");
57  boost::smatch matchObject;
58  if (boost::regex_search(headURL, matchObject, getURL)) {
59  version = matchObject[1];
60 
61  const boost::regex getVersion("(branches|tags|tickets|trunk)/([^/]+)");
62  if (boost::regex_search(version, matchObject, getVersion)) {
63  std::string type = matchObject[1];
64  version = matchObject[2];
65 
66  if (type == "branches") {
67  version += "B";
68  } else if (type == "tickets") {
69  version += "T" ;
70  } else if (type == "trunk") {
71  version = "svn";
72  }
73  }
74  } else {
75  version = "(NOSVN)";
76  return;
77  }
78 }
79 
80 
81 // Free utility function
82 
83 boost::any stringToAny(std::string valueString)
84 {
85  const boost::regex intRegex("(\\Q+\\E|\\Q-\\E){0,1}[0-9]+");
86  const boost::regex doubleRegex("(\\Q+\\E|\\Q-\\E){0,1}([0-9]*\\.[0-9]+|[0-9]+\\.[0-9]*)((e|E)(\\Q+\\E|\\Q-\\E){0,1}[0-9]+){0,1}");
87  const boost::regex FitsStringRegex("'(.*)'");
88 
89  boost::smatch matchStrings;
90 
91  std::istringstream converter(valueString);
92 
93  if (boost::regex_match(valueString, intRegex)) {
94  // convert the string to an int
95  int intVal;
96  converter >> intVal;
97  return boost::any(intVal);
98  }
99 
100  if (boost::regex_match(valueString, doubleRegex)) {
101  // convert the string to a double
102  double doubleVal;
103  converter >> doubleVal;
104  return boost::any(doubleVal);
105  }
106 
107  if (boost::regex_match(valueString, matchStrings, FitsStringRegex)) {
108  // strip off the enclosing single quotes and return the string
109  return boost::any(matchStrings[1].str());
110  }
111 
112  return boost::any(valueString);
113 }
114 
123 std::string eups::productDir(std::string const& product, std::string const& version) {
124  if (version != "setup") {
125  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, "Unsupported version: " + version);
126  }
127 
128  std::string var = product; // product's environment variable
129 
130  transform(var.begin(), var.end(), var.begin(), (int (*)(int)) toupper);
131  var += "_DIR";
132 
133  char const *dir = getenv(var.c_str());
134  if (!dir) {
135  throw LSST_EXCEPT(lsst::pex::exceptions::NotFoundError, "Product " + product + " has no version " + version);
136  }
137 
138  return dir;
139 }
140 
141 }} // namespace lsst::utils
std::string productDir(std::string const &product, std::string const &version="setup")
return an eups PRODUCT_DIR
Definition: Utils.cc:123
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::any stringToAny(std::string valueString)
Definition: Utils.cc:83
void guessSvnVersion(std::string const &headURL, std::string &OUTPUT)
Definition: Utils.cc:53
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, bool >::type any(Scalar const &scalar)
Definition: operators.h:1165
Include files required for standard LSST Exception handling.