8
8
#include <stdio.h>
9
9
#include <stdlib.h>
10
10
#include <unistd.h>
11
+ #include <dirent.h>
11
12
#include <jni.h>
12
13
13
14
#include "SDL.h"
@@ -53,18 +54,27 @@ PyMODINIT_FUNC initandroidembed(void) {
53
54
/* (void) Py_InitModule("androidembed", AndroidEmbedMethods); */
54
55
}
55
56
56
- int dir_exists (char * filename )
57
- /* Function from http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists-on-linux-in-c# */
58
- {
59
- if (0 != access ("filename" , F_OK )) {
60
- if (ENOENT == errno ) {
61
- return 0 ;
62
- }
63
- if (ENOTDIR == errno ) {
64
- return 0 ;
65
- }
57
+ /* int dir_exists(char* filename) */
58
+ /* /\* Function from http://stackoverflow.com/questions/12510874/how-can-i-check-if-a-directory-exists-on-linux-in-c# *\/ */
59
+ /* { */
60
+ /* if (0 != access(filename, F_OK)) { */
61
+ /* if (ENOENT == errno) { */
62
+ /* return 0; */
63
+ /* } */
64
+ /* if (ENOTDIR == errno) { */
65
+ /* return 0; */
66
+ /* } */
67
+ /* return 1; */
68
+ /* } */
69
+ /* } */
70
+
71
+ int dir_exists (char * filename ) {
72
+ DIR * dip ;
73
+ if (dip = opendir (filename )) {
74
+ closedir (filename );
66
75
return 1 ;
67
76
}
77
+ return 0 ;
68
78
}
69
79
70
80
int file_exists (const char * filename )
@@ -108,7 +118,21 @@ int main(int argc, char *argv[]) {
108
118
*/
109
119
PyImport_AppendInittab ("androidembed" , initandroidembed );
110
120
121
+ LOG ("Preparing to initialize python" );
122
+
123
+ if (dir_exists ("../libs" )) {
124
+ LOG ("libs exists" );
125
+ } else {
126
+ LOG ("libs does not exist" );
127
+ }
128
+
129
+ if (dir_exists ("crystax_python" )) {
130
+ LOG ("exists without slash" );
131
+ }
132
+
111
133
if (dir_exists ("crystax_python/" )) {
134
+ /* if (1) { */
135
+ LOG ("crystax_python exists" );
112
136
char paths [256 ];
113
137
snprintf (paths , 256 , "%s/crystax_python/stdlib.zip:%s/crystax_python/modules" , env_argument , env_argument );
114
138
/* snprintf(paths, 256, "%s/stdlib.zip:%s/modules", env_argument, env_argument); */
@@ -118,7 +142,7 @@ int main(int argc, char *argv[]) {
118
142
wchar_t * wchar_paths = Py_DecodeLocale (paths , NULL );
119
143
Py_SetPath (wchar_paths );
120
144
LOG ("set wchar paths..." );
121
- }
145
+ } else { LOG ( "crystax_python does not exist" );}
122
146
123
147
Py_Initialize ();
124
148
@@ -152,18 +176,19 @@ int main(int argc, char *argv[]) {
152
176
" private + '/lib/python2.7/lib-dynload/', \n" \
153
177
" private + '/lib/python2.7/site-packages/', \n" \
154
178
" argument ]\n" );
155
- } else {
179
+ } else {
156
180
157
181
char add_site_packages_dir [256 ];
158
182
snprintf (add_site_packages_dir , 256 , "sys.path.append('%s/crystax_python/site-packages')" ,
159
183
env_argument );
160
184
161
185
PyRun_SimpleString (
162
- "import sys\n" \
163
- "sys.argv = ['notaninterpreterreally']\n" \
186
+ "import sys\n" \
187
+ "sys.argv = ['notaninterpreterreally']\n" \
164
188
"from os.path import realpath, join, dirname" );
165
189
PyRun_SimpleString (add_site_packages_dir );
166
- /* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
190
+ /* "sys.path.append(join(dirname(realpath(__file__)), 'site-packages'))") */
191
+ PyRun_SimpleString ("sys.path = ['.'] + sys.path" );
167
192
}
168
193
169
194
PyRun_SimpleString (
0 commit comments