Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/homedirectory.py
diff options
context:
space:
mode:
Diffstat (limited to 'homedirectory.py')
-rw-r--r--homedirectory.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/homedirectory.py b/homedirectory.py
new file mode 100644
index 0000000..13d83ce
--- /dev/null
+++ b/homedirectory.py
@@ -0,0 +1,35 @@
+"""
+Module for finding out the directory of the program we are running,
+be it a Python script or an executable.
+Use homedirectory.do() to set this path as the current os path and to
+add it to sys.path.
+"""
+
+import os
+import sys
+
+
+def _are_we_frozen():
+ """Returns whether we are frozen via py2exe.
+ This will affect how we find out where we are located."""
+
+ return hasattr(sys, "frozen")
+
+
+def our_path():
+ """ This will get us the program's directory,
+ even if we are frozen using py2exe"""
+
+ if _are_we_frozen():
+ return os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding( )))
+
+ return os.path.dirname(unicode(__file__, sys.getfilesystemencoding( )))
+
+def do():
+ """
+ Sets the directory containing our program as the current directory in os,
+ as well as adding it to sys.path.
+ """
+ path=our_path()
+ os.chdir(path)
+ sys.path.append(path) \ No newline at end of file