Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
709ba370
authored
Mar 09, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: refactor is_deletable
parent
31cb5abf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
15 deletions
+14
-15
circle/storage/models.py
+9
-10
circle/storage/tests/test_models.py
+5
-5
No files found.
circle/storage/models.py
View file @
709ba370
...
...
@@ -51,7 +51,7 @@ class DataStore(Model):
def
get_deletable_disks
(
self
):
return
[
disk
.
filename
for
disk
in
self
.
disk_set
.
filter
(
destroyed__isnull
=
False
)
if
disk
.
is_deletable
()
]
destroyed__isnull
=
False
)
if
disk
.
is_deletable
]
class
Disk
(
AclBase
,
TimeStampedModel
):
...
...
@@ -159,21 +159,20 @@ class Disk(AclBase, TimeStampedModel):
result
=
celery
.
AsyncResult
(
id
=
task
)
return
result
.
info
.
get
(
"percent"
)
@property
def
is_deletable
(
self
):
"""Returns whether the file can be deleted.
Checks if all children and the disk itself is destroyed.
"""True if the associated file can be deleted.
"""
# Check if all children and the disk itself is destroyed.
yesterday
=
timezone
.
now
()
-
timedelta
(
days
=
1
)
return
(
self
.
destroyed
is
not
None
and
self
.
destroyed
<
yesterday
)
and
not
self
.
has_active_child
()
and
self
.
destroyed
<
yesterday
)
and
self
.
children_deletable
def
has_active_child
(
self
):
"""Returns if disk has children that are not destroyed.
@property
def
children_deletable
(
self
):
"""True if all children of the disk are deletable.
"""
return
any
((
not
i
.
is_deletable
()
for
i
in
self
.
derivatives
.
all
()))
return
all
(
i
.
is_deletable
for
i
in
self
.
derivatives
.
all
())
@property
def
is_in_use
(
self
):
...
...
circle/storage/tests/test_models.py
View file @
709ba370
...
...
@@ -25,24 +25,24 @@ class DiskTestCase(TestCase):
def
test_deletable_not_destroyed
(
self
):
d
=
self
.
_disk
()
assert
not
d
.
is_deletable
()
assert
not
d
.
is_deletable
def
test_deletable_newly_destroyed
(
self
):
d
=
self
.
_disk
(
destroyed
=
new
)
assert
not
d
.
is_deletable
()
assert
not
d
.
is_deletable
def
test_deletable_no_child
(
self
):
d
=
self
.
_disk
(
destroyed
=
old
)
assert
d
.
is_deletable
()
assert
d
.
is_deletable
def
test_deletable_child_not_destroyed
(
self
):
d
=
self
.
_disk
()
self
.
_disk
(
base
=
d
,
destroyed
=
old
)
self
.
_disk
(
base
=
d
)
assert
not
d
.
is_deletable
()
assert
not
d
.
is_deletable
def
test_deletable_child_newly_destroyed
(
self
):
d
=
self
.
_disk
(
destroyed
=
old
)
self
.
_disk
(
base
=
d
,
destroyed
=
new
)
self
.
_disk
(
base
=
d
)
assert
not
d
.
is_deletable
()
assert
not
d
.
is_deletable
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment