Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
8b10fe78
Commit
8b10fe78
authored
May 07, 2015
by
Vincent Castellano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support loading the script from any path, truncate .py if needed.
parent
9ccc3016
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
python-tg.c
python-tg.c
+15
-7
No files found.
python-tg.c
View file @
8b10fe78
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <libgen.h>
#include <Python.h>
#include <Python.h>
#ifdef EVENT_V2
#ifdef EVENT_V2
...
@@ -1271,18 +1271,26 @@ void inittgl()
...
@@ -1271,18 +1271,26 @@ void inittgl()
void
py_init
(
const
char
*
file
)
{
void
py_init
(
const
char
*
file
)
{
if
(
!
file
)
{
return
;
}
if
(
!
file
)
{
return
;
}
python_loaded
=
0
;
python_loaded
=
0
;
PyObject
*
pModule
,
*
pDict
;
PyObject
*
pModule
,
*
pDict
;
// Get a copy of the filename for dirname, which may modify the string.
char
filename
[
100
];
strncpy
(
filename
,
file
,
100
);
Py_Initialize
();
Py_Initialize
();
inittgl
();
inittgl
();
PyObject
*
sysPath
=
PySys_GetObject
((
char
*
)
"path"
);
PyObject
*
sysPath
=
PySys_GetObject
((
char
*
)
"path"
);
PyList_Append
(
sysPath
,
PyString_FromString
(
"."
));
PyList_Append
(
sysPath
,
PyString_FromString
(
dirname
(
filename
)));
// remove .py extension from file, if any
char
*
dot
=
strrchr
(
file
,
'.'
);
if
(
dot
&&
strcmp
(
dot
,
".py"
)
==
0
)
*
dot
=
0
;
pModule
=
PyImport_Import
(
PyString_FromString
(
file
));
pModule
=
PyImport_Import
(
PyString_FromString
(
file
));
if
(
PyErr_Occurred
())
{
// Error loading script
if
(
pModule
==
NULL
||
PyErr_Occurred
())
{
// Error loading script
logprintf
(
"Failed to load python script
\n
"
);
logprintf
(
"Failed to load python script
\n
"
);
PyErr_Print
();
PyErr_Print
();
exit
(
1
);
exit
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment