wooey / Wooey

A Django app that creates automatic web UIs for Python scripts.
http://wooey.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.11k stars 183 forks source link

how to get the full path and filename of the upload file #349

Closed Fatalerr closed 2 years ago

Fatalerr commented 2 years ago

Hi Chris, I need to add a script to Wooey. the script will use a python module that will read a log file. the log file will be uploaded by the user with wooey. but the problem is: the upload file must be a file handler object in the script, but the module only accepts a string as the filename as args. I'd like to know how to get the full path and filename of the uploaded log file? Thanks!

example code:

import somemodule

parser.add_argument("log_file", type=argparse.FileType('r'))
args = parser.parse_args()

print(args.log_file)  # the args.log_file is a io.TextIOWrapper
result = somemodule.check(log_filename)  # the log_filename must be a string not io.TextIOWrapper
Fatalerr commented 2 years ago

After some trying, I got the solution, it's very easy actually: the args.log_file is an io.IOTextWrapper object, it has a 'name' attribute which is its abs path.