I am writing a fabric file that which will take a dataset, send it to a server, run an analysis script on it, and retrieve the results. If I hardcode the location of my script, process_script, I am all good. However, I would like to include the script as a file in a module and would therefore like to be able to access that file without hardcoding the location. Can I do it using the import system? I’m not sure. Here’s a working version of what I’d like to do:
#data, script
datafile = 'data.txt'
process_script = 'process.py'
#simple function
def upload_and_run():
newdir = remote_dir + '/process_temp'
put(datafile, newdir)
put(process_script, newdir)
with cd(newdir):
run('python2.6 process.py {0}'.format(datafile))
get(newdir,'%(path)s')
#pseudocode of how I'd like to access the process_script
process_script = from module import script
put(process_script, newdir)
any suggestions are appreciated,
thanks,
zach cp
as per this and this, I can access the module path using the
.__file__attribute of the module. The script is then hardcoded with that path.