In my app I have a setup python script (/root/ha/setup.py) which looks through a directory called modules and runs setup.py in each of the subdirectories.
The relevant code is this:
""" Exec the module's own setup file """
if os.path.isfile(os.path.join(root, module, "setup.py")):
execfile(os.path.join(root, module, "setup.py"))
The thing is I want /root/ha/modules/modulename/setup.py to work no matter where it's called from.
If I am in modules/modulename and run python setup.py it's fine but if I run it from the directory above modules/ i get this error
idFile = open(os.path.dirname(os.path.abspath(__file__)) + "/id.txt", "r").read()
IOError: [Errno 2] No such file or directory: '/root/ha/id.txt'
as you can see it is getting the path of the script that is calling it instead of the script that is running. It should be trying to read /root/ha/modules/modulename/id.txt
I've tried using different methods to get the path but all end up with this error...