Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
c13f128d
authored
Apr 29, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common, vm: refactor activity code manipulating code
parent
b1fe6a20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
circle/common/operations.py
+10
-6
circle/vm/models/activity.py
+3
-2
No files found.
circle/common/operations.py
View file @
c13f128d
from
inspect
import
getargspec
from
inspect
import
getargspec
from
logging
import
getLogger
from
logging
import
getLogger
from
.models
import
activity_context
,
activity_code_separator
from
.models
import
activity_context
,
has_suffix
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
...
@@ -172,11 +172,15 @@ class OperatedMixin(object):
...
@@ -172,11 +172,15 @@ class OperatedMixin(object):
yield
op
yield
op
def
get_operation_from_activity_code
(
self
,
activity_code
):
def
get_operation_from_activity_code
(
self
,
activity_code
):
sep
=
activity_code_separator
"""Get an instance of the Operation corresponding to the specified
ops
=
getattr
(
self
,
operation_registry_name
,
{})
.
values
()
activity code.
for
op
in
ops
:
if
activity_code
.
endswith
(
sep
+
op
.
activity_code_suffix
):
:returns: A bound instance of an operation, or None if no matching
return
op
operation could be found.
"""
for
op
in
getattr
(
self
,
operation_registry_name
,
{})
.
itervalues
():
if
has_suffix
(
activity_code
,
op
.
activity_code_suffix
):
return
op
(
self
)
else
:
else
:
return
None
return
None
...
...
circle/vm/models/activity.py
View file @
c13f128d
...
@@ -10,7 +10,7 @@ from django.utils import timezone
...
@@ -10,7 +10,7 @@ from django.utils import timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
common.models
import
(
from
common.models
import
(
ActivityModel
,
activitycontextimpl
,
join_activity_code
,
ActivityModel
,
activitycontextimpl
,
join_activity_code
,
split_activity_code
)
)
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
...
@@ -56,7 +56,8 @@ class InstanceActivity(ActivityModel):
...
@@ -56,7 +56,8 @@ class InstanceActivity(ActivityModel):
return
reverse
(
'dashboard.views.vm-activity'
,
args
=
[
self
.
pk
])
return
reverse
(
'dashboard.views.vm-activity'
,
args
=
[
self
.
pk
])
def
get_readable_name
(
self
):
def
get_readable_name
(
self
):
return
self
.
activity_code
.
split
(
'.'
)[
-
1
]
.
replace
(
'_'
,
' '
)
.
capitalize
()
activity_code_last_suffix
=
split_activity_code
(
self
.
activity_code
)[
-
1
]
return
activity_code_last_suffix
.
replace
(
'_'
,
' '
)
.
capitalize
()
def
get_status_id
(
self
):
def
get_status_id
(
self
):
if
self
.
succeeded
is
None
:
if
self
.
succeeded
is
None
:
...
...
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