File: py_packages.cc

package info (click to toggle)
cadabra2 2.4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 78,732 kB
  • sloc: ansic: 133,450; cpp: 92,064; python: 1,530; javascript: 203; sh: 184; xml: 182; objc: 53; makefile: 51
file content (40 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (3)
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
#include <fstream>
#include <ctime>
#include "../CdbPython.hh"

#include "py_packages.hh"

namespace cadabra {


	void compile_package(const std::string& in_name, const std::string& out_name)
		{
		// Get current time info
		//		std::time_t t = std::time(nullptr);
		//		std::tm tm = *std::localtime(&t);

		// Only compile if the notebook is newer than the compiled package
		struct stat f1, f2;
		if (stat(in_name.c_str(), &f1) == 0 && stat(out_name.c_str(), &f2) == 0 && f1.st_mtime < f2.st_mtime)
			return;

		std::string pystr;
		if(in_name.size()>3 && in_name.substr(in_name.size()-4)==".cdb")
			pystr = cadabra::cdb2python(in_name, false);
		else
			pystr = cadabra::cnb2python(in_name, false);
		
		if (pystr != "") {
			std::ofstream ofs(out_name);
			//		std::ofstream ofs(name+".py");
			ofs << pystr;
			}
		}


	void init_packages(pybind11::module& m)
		{
		m.def("compile_package__", &compile_package);
		}

	}