narc0tiq / factorio-updater

Factorio update helper for headless servers
MIT License
245 stars 48 forks source link

Use tempfile.gettempdir() instead of /tmp for --output-path default. #20

Open narc0tiq opened 7 years ago

narc0tiq commented 7 years ago

As title. Maybe someone wants to console update their Factorio on a platform where /tmp isn't available or something.

CaptainDapper commented 6 years ago

Running windows; sort-of related. I added a couple of lines since I don't have a /tmp folder in my drive root. First, when defining the default for -O: default=('/tmp' if os.name != 'nt' else './tmp')

((Side note; I'm also using Python 3...))

then I added if output_path=='./tmp' and not os.path.exists(output_path) and os.name=='nt': os.mkdir('./tmp') in the fetch_update() function, just before downloading. I also made a check to skip a file if it was already downloaded, but more properly should have just deleted the whole folder when I was finished. Also, there's lots of better ways to do this; just thought I would share.

narc0tiq commented 6 years ago

Yeah, but it can be even easier: https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir