46 |
48 |
47 class GrepHandler : public RelationalReaderStringHadler { |
49 class GrepHandler : public RelationalReaderStringHadler { |
48 private: |
50 private: |
49 shared_ptr<writer::RelationalWriter> relationalWriter; |
51 shared_ptr<writer::RelationalWriter> relationalWriter; |
50 |
52 |
|
53 wchar_t* pythonProgramName; |
|
54 |
51 wregex relationNameRegEx; |
55 wregex relationNameRegEx; |
52 wregex attributeNameRegEx; |
56 wregex attributeNameRegEx; |
53 wregex searchRegEx; |
57 wregex searchRegEx; |
54 |
58 |
55 vector<boolean_t> currentSearchableAttributes; |
59 vector<boolean_t> currentSearchableAttributes; |
61 public: |
65 public: |
62 |
66 |
63 GrepHandler(ostream& output, const vector<string_t>& arguments) { |
67 GrepHandler(ostream& output, const vector<string_t>& arguments) { |
64 relationalWriter.reset(writer::Factory::create(output)); |
68 relationalWriter.reset(writer::Factory::create(output)); |
65 |
69 |
|
70 pythonProgramName = Py_DecodeLocale("relpipe-tr-python", NULL); |
|
71 Py_SetProgramName(pythonProgramName); |
|
72 Py_Initialize(); |
|
73 |
|
74 //PyRun_SimpleString("print('Hello from Python!')"); |
|
75 |
66 if (arguments.size() == 3) { |
76 if (arguments.size() == 3) { |
67 relationNameRegEx = wregex(arguments[0]); |
77 relationNameRegEx = wregex(arguments[0]); |
68 attributeNameRegEx = wregex(arguments[1]); |
78 attributeNameRegEx = wregex(arguments[1]); |
69 searchRegEx = wregex(arguments[2]); |
79 searchRegEx = wregex(arguments[2]); |
70 } else { |
80 } else { |
|
81 PyMem_RawFree(pythonProgramName); |
71 throw cli::RelpipeCLIException(L"Usage: relpipe-tr-python <relationNameRegExp> <attributeNameRegExp> <searchRegExp>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); |
82 throw cli::RelpipeCLIException(L"Usage: relpipe-tr-python <relationNameRegExp> <attributeNameRegExp> <searchRegExp>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); |
72 } |
83 } |
|
84 } |
|
85 |
|
86 virtual ~GrepHandler() { |
|
87 Py_FinalizeEx(); |
|
88 PyMem_RawFree(pythonProgramName); |
73 } |
89 } |
74 |
90 |
75 void startRelation(string_t name, vector<AttributeMetadata> attributes) override { |
91 void startRelation(string_t name, vector<AttributeMetadata> attributes) override { |
76 // TODO: move to a reusable method (or use same metadata on both reader and writer side?) |
92 // TODO: move to a reusable method (or use same metadata on both reader and writer side?) |
77 vector<writer::AttributeMetadata> writerMetadata; |
93 vector<writer::AttributeMetadata> writerMetadata; |