Revert "Added wizardless commands (pack and unpack)" and re-implement original soluti...
[appimagekit/gsi.git] / AppImageAssistant.AppDir / portability.py
blobea5ee09b6e69d19945143812d1db59b5010a1768
1 #!/usr/bin/env python2
3 import os, sys, fnmatch
5 AppDir = os.path.realpath(os.path.dirname(__file__))
7 modules = []
9 for root, dirs, files in os.walk(AppDir):
10 for fname in files:
11 fpath = os.path.join(root,fname)
12 if fnmatch.fnmatch(fpath, '*__init__.py'):
13 modules.append(os.path.dirname(os.path.dirname(fpath)))
14 if fnmatch.fnmatch(fpath, '*/_*.so'):
15 modules.append(os.path.dirname(fpath))
16 if fnmatch.fnmatch(fpath, '*python*.so'):
17 modules.append(os.path.dirname(fpath))
18 if fnmatch.fnmatch(fpath, '*.py'):
19 modules.append(os.path.dirname(fpath))
21 modules = set(modules)
23 for module in modules:
24 sys.path.append(module)
26 usage = """
27 E.g., if the main executable is in $APPDIR/usr/bin, then add to the head of it:
29 import os,sys
30 sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
31 import portability
32 """
34 if __name__=="__main__":
35 print ""
36 print("Put this file into the root of an AppDir, then import it to make all Python modules in the AppDir visible to the app")
37 print usage