aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2021-08-02 22:19:57 +0300
committerBonfaceKilz2021-08-03 15:49:50 +0300
commitcbe5d6edacafe7f1afba49e20c644a34fa9aaf7d (patch)
tree0728ee4c170320963d5c5054878858acb7b2ca2d
parent72bdbc512ee250ffaa1fa0c1ba91b2a065a485d0 (diff)
downloadgenenetwork2-cbe5d6edacafe7f1afba49e20c644a34fa9aaf7d.tar.gz
Replace TMPDIR hard-coded val with one set from flask
-rw-r--r--wqflask/wqflask/views.py39
1 files changed, 24 insertions, 15 deletions
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 78da024f..2f704ac9 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -544,6 +544,7 @@ def update_phenotype():
passwd=current_app.config.get("DB_PASS"),
host=current_app.config.get("DB_HOST"))
data_ = request.form.to_dict()
+ TMPDIR = current_app.config.get("TMPDIR")
author = g.user_session.record.get(b'user_name')
if 'file' not in request.files:
flash("No sample-data has been uploaded", "warning")
@@ -551,7 +552,7 @@ def update_phenotype():
file_ = request.files['file']
trait_name = str(data_.get('dataset-name'))
phenotype_id = str(data_.get('phenotype-id', 35))
- SAMPLE_DATADIR = "/tmp/sample-data/"
+ SAMPLE_DATADIR = os.path.join(TMPDIR, "sample-data")
if not os.path.exists(SAMPLE_DATADIR):
os.makedirs(SAMPLE_DATADIR)
if not os.path.exists(os.path.join(SAMPLE_DATADIR,
@@ -563,14 +564,17 @@ def update_phenotype():
os.makedirs(os.path.join(SAMPLE_DATADIR,
"updated"))
current_time = str(datetime.datetime.now().isoformat())
- new_file_name = ("/tmp/sample-data/updated/"
- f"{author.decode('utf-8')}."
- f"{trait_name}.{phenotype_id}."
- f"{current_time}.csv")
- uploaded_file_name = ("/tmp/sample-data/updated/"
- f"updated.{author.decode('utf-8')}."
- f"{trait_name}.{phenotype_id}."
- f"{current_time}.csv")
+ new_file_name = (os.path.join(TMPDIR,
+ "sample-data/updated/",
+ (f"{author.decode('utf-8')}."
+ f"{trait_name}.{phenotype_id}."
+ f"{current_time}.csv")))
+ uploaded_file_name = (os.path.join(
+ TMPDIR,
+ "sample-data/updated/",
+ (f"updated.{author.decode('utf-8')}."
+ f"{trait_name}.{phenotype_id}."
+ f"{current_time}.csv")))
file_.save(new_file_name)
publishdata_id = ""
lines = []
@@ -1425,7 +1429,9 @@ def approve_data(name):
user=current_app.config.get("DB_USER"),
passwd=current_app.config.get("DB_PASS"),
host=current_app.config.get("DB_HOST"))
- with open(os.path.join("/tmp/sample-data/diffs", name), 'r') as myfile:
+ TMPDIR = current_app.config.get("TMPDIR")
+ with open(os.path.join(f"{TMPDIR}/sample-data/diffs",
+ name), 'r') as myfile:
sample_data = json.load(myfile)
PUBLISH_ID = sample_data.get("publishdata_id")
modifications = [d for d in sample_data.get("Modifications")]
@@ -1452,8 +1458,8 @@ def approve_data(name):
json_data=json.dumps(sample_data)))
if modifications:
# Once data is approved, rename it!
- os.rename(os.path.join("/tmp/sample-data/diffs", name),
- os.path.join("/tmp/sample-data/diffs",
+ os.rename(os.path.join(f"{TMPDIR}/sample-data/diffs", name),
+ os.path.join(f"{TMPDIR}/sample-data/diffs",
f"{name}.approved"))
flash((f"Just updated data from: {name}; {row_counts} "
"row(s) modified!"),
@@ -1463,8 +1469,9 @@ def approve_data(name):
@app.route("/data-samples/reject/<name>")
def reject_data(name):
- os.rename(os.path.join("/tmp/sample-data/diffs", name),
- os.path.join("/tmp/sample-data/diffs",
+ TMPDIR = current_app.config.get("TMPDIR")
+ os.rename(os.path.join(f"{TMPDIR}/sample-data/diffs", name),
+ os.path.join(f"{TMPDIR}/sample-data/diffs",
f"{name}.rejected"))
flash(f"{name} has been rejected!", "success")
return redirect("/admin/data-sample/diffs/")
@@ -1472,6 +1479,8 @@ def reject_data(name):
@app.route("/display-file/<name>")
def display_file(name):
- with open(os.path.join("/tmp/sample-data/diffs", name), 'r') as myfile:
+ TMPDIR = current_app.config.get("TMPDIR")
+ with open(os.path.join(f"{TMPDIR}/sample-data/diffs",
+ name), 'r') as myfile:
content = myfile.read()
return Response(content, mimetype='text/json')