1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// $Id: RDBase.cpp 1885 2011-12-09 04:59:46Z glandrum $
//
// Copyright (c) 2004-2011 greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <boost/python.hpp>
#include <iostream>
#include <fstream>
#include <RDBoost/Wrap.h>
#include <RDBoost/python_streambuf.h>
#include <RDGeneral/versions.h>
#include <RDGeneral/RDLog.h>
#if 0
#include <boost/log/functions.hpp>
#if defined(BOOST_HAS_THREADS)
#include <boost/log/extra/functions_ts.hpp>
#endif
#endif
namespace python = boost::python;
namespace logging = boost::logging;
std::string _version(){
return "$Id: RDBase.cpp 1885 2011-12-09 04:59:46Z glandrum $";
}
void EnableLog(std::string spec){
logging::enable_logs(spec);
}
void DisableLog(std::string spec){
logging::disable_logs(spec);
}
void AttachFileToLog(std::string spec,std::string filename,int delay=100){
#if 0
#if defined(BOOST_HAS_THREADS)
logging::manipulate_logs(spec)
.add_appender(logging::ts_appender(logging::write_to_file(filename),
delay));
#else
logging::manipulate_logs(spec)
.add_appender(logging::write_to_file(filename));
#endif
#endif
}
void LogMessage(std::string spec,std::string msg){
#if 0
logging::logger theLog(spec);
if(theLog.is_enabled(logging::level::default_)){
*(theLog.stream().stream()) << msg;
}
#else
// FIX: get this more general
boost::logging::rdLogger *dest;
if(spec=="rdApp.error"){
dest=rdErrorLog;
} else if(spec=="rdApp.warning"){
dest=rdWarningLog;
} else if(spec=="rdApp.info"){
dest=rdInfoLog;
} else if(spec=="rdApp.debug"){
dest=rdDebugLog;
} else {
dest=0;
}
if(dest){
BOOST_LOG(dest)<<msg;
}
#endif
}
namespace {
struct python_streambuf_wrapper
{
typedef boost_adaptbx::python::streambuf wt;
static void
wrap()
{
using namespace boost::python;
class_<wt, boost::noncopyable>("streambuf", no_init)
.def(init<object&, std::size_t>((
arg("python_file_obj"),
arg("buffer_size")=0),"documentation")[with_custodian_and_ward_postcall<0,2>()])
;
}
};
struct python_ostream_wrapper
{
typedef boost_adaptbx::python::ostream wt;
static void
wrap()
{
using namespace boost::python;
class_<std::ostream, boost::noncopyable>("std_ostream", no_init);
class_<wt, boost::noncopyable, bases<std::ostream> >("ostream", no_init)
.def(init<object&, std::size_t>((
arg("python_file_obj"),
arg("buffer_size")=0)))
;
}
};
}
BOOST_PYTHON_MODULE(rdBase)
{
python::scope().attr("__doc__") =
"Module containing basic definitions for wrapped C++ code\n"
"\n"
;
RDLog::InitLogs();
RegisterVectorConverter<int>();
RegisterVectorConverter<unsigned>();
RegisterVectorConverter<double>();
RegisterVectorConverter<std::string>(1);
RegisterVectorConverter< std::vector<int> >();
RegisterVectorConverter< std::vector<unsigned> >();
RegisterVectorConverter< std::vector<double> >();
RegisterListConverter< int >();
RegisterListConverter< std::vector<int> >();
python::register_exception_translator<IndexErrorException>(&translate_index_error);
python::register_exception_translator<ValueErrorException>(&translate_value_error);
python::def("_version",_version,"Deprecated, use the constant rdkitVersion instead");
python::scope().attr("rdkitVersion")=RDKit::rdkitVersion;
python::scope().attr("boostVersion")=RDKit::boostVersion;
python::def("EnableLog",EnableLog);
python::def("DisableLog",DisableLog);
python::def("AttachFileToLog",AttachFileToLog,"Causes the log to write to a file",
(python::arg("spec"),python::arg("filename"),python::arg("delay")=100));
python::def("LogMessage",LogMessage);
python_streambuf_wrapper::wrap();
python_ostream_wrapper::wrap();
}
|