Code forensics
0.1
Generate historical information about code changes
|
Go to the documentation of this file.
4 #ifndef PYTHON_INTEROP_HPP
5 #define PYTHON_INTEROP_HPP
11 #include <boost/python.hpp>
16 namespace py = boost::python;
115 template <
typename T>
117 static PyObject*
convert(T
const&);
120 template <
typename T>
123 py::converter::registry::push_back(
131 py::converter::rvalue_from_python_stage1_data* data);
139 auto tod = t.time_of_day();
140 auto usec = tod.total_microseconds() % 1000000;
141 return PyDateTime_FromDateAndTime(
153 return PyDateTime_Check(obj) ? obj :
nullptr;
159 py::converter::rvalue_from_python_stage1_data* data) {
160 auto storage =
reinterpret_cast<
161 py::converter::rvalue_from_python_storage<PTime>*
>(
165 PyDateTime_GET_YEAR(obj),
166 PyDateTime_GET_MONTH(obj),
167 PyDateTime_GET_DAY(obj));
169 PyDateTime_DATE_GET_HOUR(obj),
170 PyDateTime_DATE_GET_MINUTE(obj),
171 PyDateTime_DATE_GET_SECOND(obj));
172 time_of_day += boost::posix_time::microsec(
173 PyDateTime_DATE_GET_MICROSECOND(obj));
174 new (storage)
PTime(date_only, time_of_day);
175 data->convertible = storage;
181 return PyDate_FromDate(d.year(), d.month(), d.day());
186 return PyDate_Check(obj) ? obj :
nullptr;
192 py::converter::rvalue_from_python_stage1_data* data) {
193 auto storage =
reinterpret_cast<
194 py::converter::rvalue_from_python_storage<Date>*
>(
198 PyDateTime_GET_YEAR(obj),
199 PyDateTime_GET_MONTH(obj),
200 PyDateTime_GET_DAY(obj));
201 data->convertible = storage;
208 py::to_python_converter<PTime, type_into_python<PTime>>();
211 py::to_python_converter<Date, type_into_python<Date>>();
214 py::object class_creator =
216 py::class_<PyForensics>(
"Forensics")
229 "set_path_predicate",
231 py::args(
"predicate"))
233 "set_commit_period_mapping",
237 "set_sample_period_mapping",
241 "set_sample_predicate",
243 py::args(
"predicate"));
245 py::object module_level_object = class_creator();
246 py::scope().attr(
"config") = module_level_object;
249 #endif // PYTHON_INTEROP_HPP
py::object post_analyze
Definition: python_interop.hpp:23
Definition: python_interop.hpp:121
void log_warning(CR< Str > text)
write text as a warning-level log record
Definition: python_interop.hpp:32
BOOST_PYTHON_MODULE(forensics)
Definition: python_interop.hpp:205
py::object sample_predicate
Definition: python_interop.hpp:22
#define LOG_F(state)
Definition: logging.hpp:158
int get_sample_period(CR< PTime > date) const
Get period number from the specified commit date.
Definition: python_interop.hpp:88
bool allow_sample_at_date(CR< PTime > date, CR< Str > author, CR< Str > id) const
Check whether commit by.
Definition: python_interop.hpp:98
int get_commit_period(CR< PTime > date) const
Get period number from the specified commit date.
Definition: python_interop.hpp:78
void set_logger(SPtr< Logger > log)
Definition: python_interop.hpp:27
SPtr< Logger > logger
Definition: python_interop.hpp:24
#define LOG_W(state)
Definition: logging.hpp:154
#define LOG_D(state)
Definition: logging.hpp:150
boost::posix_time::ptime PTime
Definition: program_state.hpp:25
void set_sample_predicate(py::object predicate)
set sample predicate callback for the allow_sample_at_date predicate
Definition: python_interop.hpp:62
void set_commit_period_mapping(py::object mapping)
set period mapping callback for the get_commit_period
Definition: python_interop.hpp:52
void log_fatal(CR< Str > text)
write text as a fatal-level log record
Definition: python_interop.hpp:40
py::object sample_period_mapping
Definition: python_interop.hpp:21
void set_post_analyze(py::object post)
set post-analyze hook implementation
Definition: python_interop.hpp:44
helper type to aid conversion from input type T to the python object
Definition: python_interop.hpp:116
Definition: python_interop.hpp:18
static void construct(PyObject *obj, py::converter::rvalue_from_python_stage1_data *data)
static PyObject * convert(T const &)
void set_path_predicate(py::object predicate)
set path filtering predicate for the allow_path predicate
Definition: python_interop.hpp:47
void log_info(CR< Str > text)
write text as a info-level log record
Definition: python_interop.hpp:30
#define LOG_E(state)
Definition: logging.hpp:156
py::object path_predicate
Definition: python_interop.hpp:19
type_from_python()
Definition: python_interop.hpp:122
py::object commit_period_mapping
Definition: python_interop.hpp:20
bool allow_path(CR< Str > path) const
Check whether provided path should be processed for the 'blame' information.
Definition: python_interop.hpp:69
#define LOG_I(state)
Definition: logging.hpp:152
void log_debug(CR< Str > text)
write text as a debug-level log record
Definition: python_interop.hpp:36
void run_post_analyze() const
Definition: python_interop.hpp:107
boost::gregorian::date Date
Definition: program_state.hpp:24
static void * convertible(PyObject *obj)
void log_error(CR< Str > text)
write text as a error-level log record
Definition: python_interop.hpp:38
boost::posix_time::time_duration TimeDuration
Definition: program_state.hpp:26
void log_trace(CR< Str > text)
write text as a trace-level log record
Definition: python_interop.hpp:34
void set_sample_period_mapping(py::object mapping)
set period mapping callback for the get_sample_period
Definition: python_interop.hpp:57
#define LOG_T(state)
Definition: logging.hpp:148