Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
synnefo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
synnefo
Commits
214789c7
Commit
214789c7
authored
11 years ago
by
Giorgos Korfiatis
Browse files
Options
Downloads
Patches
Plain Diff
astakos: Make project-list a ListCommand
Use --filter-by to filter by owner and name. Refs #5014
parent
928e4359
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
snf-astakos-app/astakos/im/management/commands/project-list.py
+51
-61
51 additions, 61 deletions
...stakos-app/astakos/im/management/commands/project-list.py
with
51 additions
and
61 deletions
snf-astakos-app/astakos/im/management/commands/project-list.py
+
51
−
61
View file @
214789c7
...
@@ -33,15 +33,13 @@
...
@@ -33,15 +33,13 @@
from
optparse
import
make_option
from
optparse
import
make_option
from
snf_django.management.commands
import
SynnefoCommand
,
CommandError
from
snf_django.management.commands
import
ListCommand
from
astakos.im.models
import
Project
,
ProjectApplication
from
astakos.im.models
import
Project
,
ProjectApplication
from
django.db.models
import
Q
from
._common
import
is_uuid
from
snf_django.management
import
utils
from
._common
import
is_uuid
,
is_email
class
Command
(
Synnefo
Command
):
class
Command
(
List
Command
):
help
=
"""
List projects and project status.
help
=
"""
List projects and project status.
Project status can be one of:
Project status can be one of:
...
@@ -66,7 +64,10 @@ class Command(SynnefoCommand):
...
@@ -66,7 +64,10 @@ class Command(SynnefoCommand):
Deleted an uninitialized, deleted project
"""
Deleted an uninitialized, deleted project
"""
option_list
=
SynnefoCommand
.
option_list
+
(
object_class
=
Project
select_related
=
[
"
last_application
"
,
"
owner
"
]
option_list
=
ListCommand
.
option_list
+
(
make_option
(
'
--new
'
,
make_option
(
'
--new
'
,
action
=
'
store_true
'
,
action
=
'
store_true
'
,
dest
=
'
new
'
,
dest
=
'
new
'
,
...
@@ -88,69 +89,58 @@ class Command(SynnefoCommand):
...
@@ -88,69 +89,58 @@ class Command(SynnefoCommand):
dest
=
'
deleted
'
,
dest
=
'
deleted
'
,
default
=
False
,
default
=
False
,
help
=
"
Also so cancelled/terminated projects
"
),
help
=
"
Also so cancelled/terminated projects
"
),
make_option
(
'
--name
'
,
dest
=
'
name
'
,
help
=
'
Filter projects by name
'
),
make_option
(
'
--owner
'
,
dest
=
'
owner
'
,
help
=
'
Filter projects by owner
\'
s email or uuid
'
),
)
)
def
handle
(
self
,
*
args
,
**
options
):
def
get_owner
(
project
):
return
project
.
owner
.
email
if
project
.
owner
else
None
flt
=
Q
()
def
get_status
(
project
):
owner
=
options
[
'
owner
'
]
return
project
.
state_display
()
if
owner
:
flt
&=
filter_by_owner
(
owner
)
name
=
options
[
'
name
'
]
def
get_pending_app
(
project
):
if
name
:
app
=
project
.
last_application
flt
&=
Q
(
realname
=
name
)
return
app
.
id
if
app
and
app
.
state
==
app
.
PENDING
else
""
FIELDS
=
{
"
id
"
:
(
"
uuid
"
,
"
Project ID
"
),
"
name
"
:
(
"
realname
"
,
"
Project Name
"
),
"
owner
"
:
(
get_owner
,
"
Project Owner
"
),
"
status
"
:
(
get_status
,
"
Project Status
"
),
"
pending_app
"
:
(
get_pending_app
,
"
An application pending for the project
"
),
}
fields
=
[
"
id
"
,
"
name
"
,
"
owner
"
,
"
status
"
,
"
pending_app
"
]
def
handle_args
(
self
,
*
args
,
**
options
):
try
:
name_filter
=
self
.
filters
.
pop
(
"
name
"
)
self
.
filters
[
"
realname
"
]
=
name_filter
except
KeyError
:
pass
try
:
owner_filter
=
self
.
filters
.
pop
(
"
owner
"
)
if
owner_filter
is
not
None
:
if
is_uuid
(
owner_filter
):
self
.
filters
[
"
owner__uuid
"
]
=
owner_filter
else
:
self
.
filters
[
"
owner__email
"
]
=
owner_filter
except
KeyError
:
pass
if
not
options
[
'
deleted
'
]:
if
not
options
[
'
deleted
'
]:
flt
&=
~
Q
(
state__in
=
Project
.
SKIP_STATES
)
self
.
excludes
[
"
state__in
"
]
=
Project
.
SKIP_STATES
pending
=
Q
(
last_application__isnull
=
False
,
last_application__state
=
ProjectApplication
.
PENDING
)
if
options
[
'
pending
'
]:
if
options
[
"
pending
"
]:
flt
&=
pending
self
.
filter_
pending
()
else
:
else
:
if
options
[
'
new
'
]:
if
options
[
'
new
'
]:
flt
&=
pending
&
Q
(
state
=
Project
.
UNINITIALIZED
)
self
.
filter_pending
()
self
.
filters
[
"
state
"
]
=
Project
.
UNINITIALIZED
if
options
[
'
modified
'
]:
if
options
[
'
modified
'
]:
flt
&=
pending
&
Q
(
state__in
=
Project
.
INITIALIZED_STATES
)
self
.
filter_pending
()
self
.
filters
[
"
state__in
"
]
=
Project
.
INITIALIZED_STATES
projects
=
Project
.
objects
.
\
select_related
(
"
last_application
"
,
"
owner
"
).
filter
(
flt
)
labels
=
(
'
ProjID
'
,
'
Name
'
,
'
Owner
'
,
'
Status
'
,
'
Pending AppID
'
)
info
=
project_info
(
projects
)
def
filter_pending
(
self
):
utils
.
pprint_table
(
self
.
stdout
,
info
,
labels
,
self
.
filters
[
"
last_application__state
"
]
=
ProjectApplication
.
PENDING
options
[
"
output_format
"
])
def
filter_by_owner
(
s
):
if
is_email
(
s
):
return
Q
(
owner__email
=
s
)
if
is_uuid
(
s
):
return
Q
(
owner__uuid
=
s
)
raise
CommandError
(
"
Expecting either email or uuid.
"
)
def
project_info
(
projects
):
l
=
[]
for
project
in
projects
:
status
=
project
.
state_display
()
app
=
project
.
last_application
pending_appid
=
app
.
id
if
app
and
app
.
state
==
app
.
PENDING
else
""
t
=
(
project
.
uuid
,
project
.
realname
,
project
.
owner
.
email
if
project
.
owner
else
None
,
status
,
pending_appid
,
)
l
.
append
(
t
)
return
l
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