Commit f6b14153 authored by Administrator's avatar Administrator

[FEAT] Admin utils, check if user has a folder. Please this function.

parent 4e74b74e
import os
from gargantext_web.settings import MEDIA_ROOT
def ensure_dir(user):
# If user is new, folder does not exist yet, create it then
dirpath = '%s/corpora/%s' % (MEDIA_ROOT, user.username)
if not os.path.exists(dirpath):
print("Creating folder %s" % dirpath)
os.makedirs(dirpath)
...@@ -26,6 +26,9 @@ from parsing.corpustools import add_resource, parse_resources, extract_ngrams, c ...@@ -26,6 +26,9 @@ from parsing.corpustools import add_resource, parse_resources, extract_ngrams, c
from gargantext_web.celery import apply_workflow from gargantext_web.celery import apply_workflow
from admin.utils import ensure_dir
def project(request, project_id): def project(request, project_id):
# do we have a valid project id? # do we have a valid project id?
...@@ -140,11 +143,7 @@ def project(request, project_id): ...@@ -140,11 +143,7 @@ def project(request, project_id):
session.commit() session.commit()
# If user is new, folder does not exist yet, create it then # If user is new, folder does not exist yet, create it then
dirpath = '%s/corpora/%s' % (MEDIA_ROOT, request.user.username) ensure_dir(request.user)
if not os.path.exists(dirpath):
print("Creating folder %s" % dirpath)
os.makedirs(dirpath)
# Save the uploaded file # Save the uploaded file
filepath = '%s/corpora/%s/%s' % (MEDIA_ROOT, request.user.username, thefile._name) filepath = '%s/corpora/%s/%s' % (MEDIA_ROOT, request.user.username, thefile._name)
......
...@@ -37,6 +37,8 @@ from parsing.corpustools import add_resource, parse_resources, extract_ngrams, c ...@@ -37,6 +37,8 @@ from parsing.corpustools import add_resource, parse_resources, extract_ngrams, c
from gargantext_web.celery import apply_workflow from gargantext_web.celery import apply_workflow
from time import sleep from time import sleep
from admin.utils import ensure_dir
def getGlobalStats(request ): def getGlobalStats(request ):
print(request.method) print(request.method)
alist = ["bar","foo"] alist = ["bar","foo"]
...@@ -141,7 +143,9 @@ def doTheQuery(request , project_id): ...@@ -141,7 +143,9 @@ def doTheQuery(request , project_id):
# """ # """
ensure_dir(request.user)
tasks = MedlineFetcher() tasks = MedlineFetcher()
for i in range(8): for i in range(8):
t = threading.Thread(target=tasks.worker2) #thing to do t = threading.Thread(target=tasks.worker2) #thing to do
t.daemon = True # thread dies when main thread (only non-daemon thread) exits. t.daemon = True # thread dies when main thread (only non-daemon thread) exits.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment