File: c_python.cc

package info (click to toggle)
gnucap-python 0.0.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,672 kB
  • sloc: python: 7,873; sh: 4,384; cpp: 1,786; makefile: 252
file content (79 lines) | stat: -rw-r--r-- 1,773 bytes parent folder | download
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
#include <u_lang.h>
#include <c_comand.h>
#include <globals.h>
#include <s__.h>

#include <Python.h>

// Swig _gnucap init function prototype
//extern "C" void init_gnucap();
//
extern std::vector<CMD*> installed_commands;
extern bool have_default_plugins;

/*--------------------------------------------------------------------------*/
namespace {
  static int python_loaded = 0;

/*--------------------------------------------------------------------------*/
void load_file(CS& cmd, OMSTREAM out, CARD_LIST* scope)
{
  std::string file_name;
  char *argv[] = {};
  FILE *fp;

  cmd >> file_name;
  
  fp = fopen(file_name.c_str(), "r");
  
  if(fp == NULL) {
    throw Exception_File_Open(std::string("Could not open ") + file_name);
  }else{
  }
  

//  huh?! why not link?
  if(!python_loaded) {
	  trace0("dlopen python");
   // dlopen(PYTHON_SO, RTLD_NOW|RTLD_GLOBAL);
    Py_Initialize();

#if PY_MAJOR_VERSION >= 3
#else
    PySys_SetArgv(0, argv);
#endif
    
    // Call init function of SWIG _gnucap module
 //   init_gnucap();

//    python_loaded = 1;
  }else{ untested();
  }

  trace1("running", file_name);
  PyRun_SimpleFile(fp, file_name.c_str());
}

/*--------------------------------------------------------------------------*/
class CMD_PYTHON : public CMD {
public:
	CMD_PYTHON(){
	  have_default_plugins=true;
	}
	~CMD_PYTHON(){
		// need to uninstall from here?
		trace1("~CMD_PYTHON", installed_commands.size());
		for(auto i : installed_commands){
			command_dispatcher.uninstall(i);
		}
	}
public:
  void do_it(CS& cmd, CARD_LIST* Scope)
  {
    load_file(cmd, IO::mstdout, Scope);
  }
} p1;

DISPATCHER<CMD>::INSTALL d1(&command_dispatcher, "python|loadpy", &p1);
/*--------------------------------------------------------------------------*/
}