Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e6afebb0
authored
Jul 30, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite Excpetions to HumanReadable
parent
65e7d88a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
41 deletions
+70
-41
circle/storage/models.py
+70
-41
No files found.
circle/storage/models.py
View file @
e6afebb0
...
@@ -27,13 +27,13 @@ from celery.contrib.abortable import AbortableAsyncResult
...
@@ -27,13 +27,13 @@ from celery.contrib.abortable import AbortableAsyncResult
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
ForeignKey
)
ForeignKey
)
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
from
sizefield.models
import
FileSizeField
from
sizefield.models
import
FileSizeField
from
.tasks
import
local_tasks
,
storage_tasks
from
.tasks
import
local_tasks
,
storage_tasks
from
celery.exceptions
import
TimeoutError
from
celery.exceptions
import
TimeoutError
from
common.models
import
WorkerNotFound
from
common.models
import
WorkerNotFound
,
HumanReadableException
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -104,43 +104,72 @@ class Disk(TimeStampedModel):
...
@@ -104,43 +104,72 @@ class Disk(TimeStampedModel):
(
'create_empty_disk'
,
_
(
'Can create an empty disk.'
)),
(
'create_empty_disk'
,
_
(
'Can create an empty disk.'
)),
(
'download_disk'
,
_
(
'Can download a disk.'
)))
(
'download_disk'
,
_
(
'Can download a disk.'
)))
class
WrongDiskTypeError
(
Exception
):
class
DiskError
(
HumanReadableException
):
admin_message
=
None
def
__init__
(
self
,
type
,
message
=
None
):
if
message
is
None
:
def
__init__
(
self
,
disk
,
params
=
None
,
level
=
None
,
**
kwargs
):
message
=
(
"Operation can't be invoked on a disk of type '
%
s'."
kwargs
.
update
(
params
or
{})
%
type
)
self
.
disc
=
kwargs
[
"disk"
]
=
disk
super
(
Disk
.
DiskError
,
self
)
.
__init__
(
Exception
.
__init__
(
self
,
message
)
level
,
self
.
message
,
self
.
admin_message
or
self
.
message
,
kwargs
)
self
.
type
=
type
class
WrongDiskTypeError
(
DiskError
):
class
DiskInUseError
(
Exception
):
message
=
ugettext_noop
(
"Operation can't be invoked on disk "
"'
%(name)
s' of type '
%(type)
s'."
)
def
__init__
(
self
,
disk
,
message
=
None
):
if
message
is
None
:
admin_message
=
ugettext_noop
(
message
=
(
"The requested operation can't be performed on "
"Operation can't be invoked on disk "
"disk '
%
s (
%
s)' because it is in use."
%
"'
%(name)
s' (
%(pk)
s) of type '
%(type)
s'."
)
(
disk
.
name
,
disk
.
filename
))
def
__init__
(
self
,
disk
,
params
=
None
,
**
kwargs
):
Exception
.
__init__
(
self
,
message
)
super
(
Disk
.
WrongDiskTypeError
,
self
)
.
__init__
(
disk
,
params
,
type
=
disk
.
type
,
name
=
disk
.
name
,
pk
=
disk
.
pk
)
self
.
disk
=
disk
class
DiskInUseError
(
DiskError
):
class
DiskIsNotReady
(
Exception
):
message
=
ugettext_noop
(
"The requested operation can't be performed on "
""" Exception for operations that need a deployed disk.
"disk '
%(name)
s' because it is in use."
)
"""
admin_message
=
ugettext_noop
(
def
__init__
(
self
,
disk
,
message
=
None
):
"The requested operation can't be performed on "
if
message
is
None
:
"disk '
%(name)
s' (
%(pk)
s) because it is in use."
)
message
=
(
"The requested operation can't be performed on "
"disk '
%
s (
%
s)' because it has never been"
def
__init__
(
self
,
disk
,
params
=
None
,
**
kwargs
):
"deployed."
%
(
disk
.
name
,
disk
.
filename
))
super
(
Disk
.
WrongDiskTypeError
,
self
)
.
__init__
(
disk
,
params
,
name
=
disk
.
name
,
pk
=
disk
.
pk
)
Exception
.
__init__
(
self
,
message
)
class
DiskIsNotReady
(
DiskError
):
self
.
disk
=
disk
message
=
ugettext_noop
(
"The requested operation can't be performed on "
"disk '
%(name)
s' because it has never been deployed."
)
admin_message
=
ugettext_noop
(
"The requested operation can't be performed on "
"disk '
%(name)
s' (
%(pk)
s) [
%(filename)
s] because it has never been"
"deployed."
)
def
__init__
(
self
,
disk
,
params
=
None
,
**
kwargs
):
super
(
Disk
.
WrongDiskTypeError
,
self
)
.
__init__
(
disk
,
params
,
name
=
disk
.
name
,
pk
=
disk
.
pk
,
filename
=
disk
.
filename
)
class
DiskBaseIsNotReady
(
DiskError
):
message
=
ugettext_noop
(
"The requested operation can't be performed on "
"disk '
%(name)
s' because its base has never been deployed."
)
admin_message
=
ugettext_noop
(
"The requested operation can't be performed on "
"disk '
%(name)
s' (
%(pk)
s) [
%(filename)
s] because its base "
"'
%(b_name)
s' (
%(b_pk)
s) [
%(b_filename)
s] has never been"
"deployed."
)
def
__init__
(
self
,
disk
,
params
=
None
,
**
kwargs
):
super
(
Disk
.
WrongDiskTypeError
,
self
)
.
__init__
(
disk
,
params
,
name
=
disk
.
name
,
pk
=
disk
.
pk
,
filename
=
disk
.
filename
,
b_name
=
base
.
name
,
b_pk
=
base
.
pk
,
b_filename
=
base
.
filename
)
@property
@property
def
path
(
self
):
def
path
(
self
):
...
@@ -240,7 +269,7 @@ class Disk(TimeStampedModel):
...
@@ -240,7 +269,7 @@ class Disk(TimeStampedModel):
}
}
if
self
.
type
not
in
type_mapping
.
keys
():
if
self
.
type
not
in
type_mapping
.
keys
():
raise
self
.
WrongDiskTypeError
(
self
.
type
)
raise
self
.
WrongDiskTypeError
(
self
)
new_type
=
type_mapping
[
self
.
type
]
new_type
=
type_mapping
[
self
.
type
]
...
@@ -417,7 +446,7 @@ class Disk(TimeStampedModel):
...
@@ -417,7 +446,7 @@ class Disk(TimeStampedModel):
'iso'
:
(
"iso"
,
self
),
'iso'
:
(
"iso"
,
self
),
}
}
if
self
.
type
not
in
mapping
.
keys
():
if
self
.
type
not
in
mapping
.
keys
():
raise
self
.
WrongDiskTypeError
(
self
.
type
)
raise
self
.
WrongDiskTypeError
(
self
)
if
self
.
is_in_use
:
if
self
.
is_in_use
:
raise
self
.
DiskInUseError
(
self
)
raise
self
.
DiskInUseError
(
self
)
...
...
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