I have a flask application which is utilizing Fabric to deploy code to certain machines.
One particular method, fabric.contrib.files.upload_template, requires a filename which is the path of a file I would like to upload to my remote machines.
I have a file, index.php, which I want to place on my remote machines. I want to use upload_template to accomplish this task.
Where should I place 'index.php' in my flask folder? How will I be able to obtain the path of index.php for upload_template?
Please note that:
- My application is hosted on Heroku so the typical
/home/Sparrowcide/flaskapp/path/to/filewon't work. - I know I can probably get away by invoking a method which writes to
/tmp/path/to/file, but I'd rather not as this is not a very elegant solution.
1 Answer
Well the short answer is that you can pretty much put it wherever you want, I don't think flask will enforce any sort of structure on you here. However I personally would create a subdirectory called data and then in the flask app I might do something like this:
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'index.php')Or, if I felt I was likely to re-use this information (eg if i had multiple files to upload), I might break it out into multiple variables:
SRCDIR = os.path.dirname(os.path.abspath(__file__))
DATADIR = os.path.join(SRCDIR, 'data')
whatever_upload_function(os.path.join(DATADIR, 'index.php')) 0