Skip to content

Commit

Permalink
Improved tempdir handling
Browse files Browse the repository at this point in the history
  • Loading branch information
severinsimmler committed Apr 23, 2018
1 parent dde9332 commit 29d14c4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions application/web.py
Expand Up @@ -6,17 +6,28 @@
import werkzeug.exceptions


TEMPDIR = tempfile.mkdtemp() # Dumping the logfile, temporary data, etc.
ARCHIVEDIR = tempfile.mkdtemp() # Dumping the ZIP archive
app = application.config.create_app() # Creating the app


@app.route('/')
def index():
"""
Renders the main page. A warning pops up, if the machine is not
connected to the internet.
"""
global TEMPDIR
global ARCHIVEDIR

TEMPDIR = tempfile.mkdtemp() # Dumping the logfile, temporary data, etc.
ARCHIVEDIR = tempfile.mkdtemp() # Dumping the ZIP archive

def unlink_content(directory):
for p in pathlib.Path(directory).rglob('*'):
if p.is_file():
p.unlink()

unlink_content(TEMPDIR)
unlink_content(ARCHIVEDIR)

if application.utils.is_connected():
return flask.render_template('index.html')
else:
Expand Down

0 comments on commit 29d14c4

Please sign in to comment.