Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
7fb37dcb
Commit
7fb37dcb
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
restructure corpus delete method
parent
7dcc8c48
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/main/views.py
+13
-33
13 additions, 33 deletions
app/main/views.py
app/models.py
+25
-10
25 additions, 10 deletions
app/models.py
app/utils.py
+1
-4
1 addition, 4 deletions
app/utils.py
with
39 additions
and
47 deletions
app/main/views.py
+
13
−
33
View file @
7fb37dcb
...
...
@@ -57,6 +57,18 @@ def corpus(corpus_id):
title
=
'
Corpus
'
)
@main.route
(
'
/corpora/<int:corpus_id>/delete
'
)
@login_required
def
delete_corpus
(
corpus_id
):
delete_thread
=
threading
.
Thread
(
target
=
background_delete_corpus
,
args
=
(
current_app
.
_get_current_object
(),
corpus_id
)
)
delete_thread
.
start
()
flash
(
'
Corpus has been deleted!
'
)
return
redirect
(
url_for
(
'
main.dashboard
'
))
@main.route
(
'
/corpora/<int:corpus_id>/download
'
)
@login_required
def
corpus_download
(
corpus_id
):
...
...
@@ -100,27 +112,7 @@ def dashboard():
title
=
create_corpus_form
.
title
.
data
)
db
.
session
.
add
(
corpus
)
db
.
session
.
commit
()
dir
=
os
.
path
.
join
(
current_app
.
config
[
'
OPAQUE_STORAGE_DIRECTORY
'
],
str
(
corpus
.
user_id
),
'
corpora
'
,
str
(
corpus
.
id
))
try
:
os
.
makedirs
(
dir
)
except
OSError
:
flash
(
'
OSError!
'
)
else
:
for
file
in
create_corpus_form
.
files
.
data
:
filename
=
secure_filename
(
file
.
filename
)
file
.
save
(
os
.
path
.
join
(
dir
,
filename
))
file_dir
=
os
.
path
.
join
(
str
(
corpus
.
user_id
),
'
corpora
'
,
str
(
corpus
.
id
))
corpus_file
=
CorpusFile
(
filename
=
filename
,
corpus_id
=
corpus
.
id
,
dir
=
file_dir
)
db
.
session
.
add
(
corpus_file
)
db
.
session
.
commit
()
flash
(
'
Corpus created!
'
)
flash
(
'
Corpus created!
'
)
return
redirect
(
url_for
(
'
main.dashboard
'
))
return
render_template
(
'
main/dashboard.html.j2
'
,
create_corpus_form
=
create_corpus_form
,
...
...
@@ -169,15 +161,3 @@ def delete_job(job_id):
delete_thread
.
start
()
flash
(
'
Job has been deleted!
'
)
return
redirect
(
url_for
(
'
main.dashboard
'
))
@main.route
(
'
/corpora/<int:corpus_id>/delete
'
)
@login_required
def
delete_corpus
(
corpus_id
):
delete_thread
=
threading
.
Thread
(
target
=
background_delete_corpus
,
args
=
(
current_app
.
_get_current_object
(),
corpus_id
)
)
delete_thread
.
start
()
flash
(
'
Corpus has been deleted!
'
)
return
redirect
(
url_for
(
'
main.dashboard
'
))
This diff is collapsed.
Click to expand it.
app/models.py
+
25
−
10
View file @
7fb37dcb
...
...
@@ -410,6 +410,19 @@ class CorpusFile(db.Model):
title
=
db
.
Column
(
db
.
String
(
64
))
corpus_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
corpora.id
'
))
def
delete
(
self
):
logger
=
logging
.
getLogger
(
__name__
)
path
=
os
.
path
.
join
(
current_app
.
config
[
'
OPAQUE_STORAGE_DIRECTORY
'
],
self
.
dir
,
self
.
filename
)
try
:
os
.
remove
(
path
)
except
:
logger
.
warning
(
'
[ERROR] CorpusFile.delete
'
)
return
db
.
session
.
delete
(
self
)
db
.
session
.
commit
()
class
Corpus
(
db
.
Model
):
"""
...
...
@@ -444,17 +457,19 @@ class Corpus(db.Model):
'
title
'
:
self
.
title
,
'
user_id
'
:
self
.
user_id
}
def
delete
_corpus
(
self
):
def
delete
(
self
):
logger
=
logging
.
getLogger
(
__name__
)
delete_path
=
os
.
path
.
join
(
'
/mnt/opaque/
'
,
str
(
self
.
user_id
),
'
corpora
'
,
str
(
self
.
id
))
logger
.
warning
(
'
Delete path is: {}
'
.
format
(
delete_path
))
while
os
.
path
.
exists
(
delete_path
):
try
:
shutil
.
rmtree
(
delete_path
,
ignore_errors
=
True
)
logger
.
warning
(
'
Path does still exist.
'
)
except
OSError
:
pass
for
corpus_file
in
self
.
files
:
corpus_file
.
delete
()
path
=
os
.
path
.
join
(
current_app
.
config
[
'
OPAQUE_STORAGE_DIRECTORY
'
],
self
.
user_id
,
'
corpora
'
,
self
.
id
)
try
:
shutil
.
rmtree
(
path
)
except
:
logger
.
warning
(
'
[ERROR] Corpus.delete
'
)
return
db
.
session
.
delete
(
self
)
db
.
session
.
commit
()
...
...
This diff is collapsed.
Click to expand it.
app/utils.py
+
1
−
4
View file @
7fb37dcb
...
...
@@ -63,7 +63,4 @@ def background_delete_corpus(app, corpus_id):
logger
.
warning
(
'
Called by delete_thread.
'
)
logger
.
warning
(
'
Corpus id is: {}.
'
.
format
(
corpus_id
))
corpus
=
Corpus
.
query
.
filter_by
(
id
=
corpus_id
).
first
()
for
corpus_file
in
corpus
.
files
:
db
.
session
.
delete
(
corpus_file
)
logger
.
warning
(
'
Corpus object is: {}
'
.
format
(
corpus
))
corpus
.
delete_corpus
()
corpus
.
delete
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment