1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
2 | # contributor license agreements. See the NOTICE file distributed with |
||
3 | # this work for additional information regarding copyright ownership. |
||
4 | # The ASF licenses this file to You under the Apache License, Version 2.0 |
||
5 | # (the "License"); you may not use this file except in compliance with |
||
6 | # the License. You may obtain a copy of the License at |
||
7 | # |
||
8 | # http://www.apache.org/licenses/LICENSE-2.0 |
||
9 | # |
||
10 | # Unless required by applicable law or agreed to in writing, software |
||
11 | # distributed under the License is distributed on an "AS IS" BASIS, |
||
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
13 | # See the License for the specific language governing permissions and |
||
14 | # limitations under the License. |
||
15 | |||
16 | from __future__ import absolute_import |
||
17 | |||
18 | from st2client.models import Timer |
||
19 | from st2client.commands import resource |
||
20 | |||
21 | |||
22 | class TimerBranch(resource.ResourceBranch): |
||
23 | def __init__(self, description, app, subparsers, parent_parser=None): |
||
24 | super(TimerBranch, self).__init__( |
||
25 | Timer, description, app, subparsers, |
||
26 | parent_parser=parent_parser, |
||
27 | read_only=True, |
||
28 | commands={ |
||
29 | 'list': TimerListCommand, |
||
30 | 'get': TimerGetCommand |
||
31 | }) |
||
32 | |||
33 | |||
34 | class TimerListCommand(resource.ResourceListCommand): |
||
35 | display_attributes = ['id', 'uid', 'pack', 'name', 'type', 'parameters'] |
||
36 | |||
37 | def __init__(self, resource, *args, **kwargs): |
||
0 ignored issues
–
show
|
|||
38 | super(TimerListCommand, self).__init__(resource, *args, **kwargs) |
||
39 | |||
40 | self.parser.add_argument('-ty', '--timer-type', type=str, dest='timer_type', |
||
41 | help=("List %s type, example: 'core.st2.IntervalTimer', \ |
||
42 | 'core.st2.DateTimer', 'core.st2.CronTimer'." % |
||
43 | resource.get_plural_display_name().lower()), required=False) |
||
44 | |||
45 | @resource.add_auth_token_to_kwargs_from_cli |
||
46 | def run(self, args, **kwargs): |
||
47 | if args.timer_type: |
||
48 | kwargs['timer_type'] = args.timer_type |
||
49 | |||
50 | if kwargs: |
||
51 | return self.manager.query(**kwargs) |
||
52 | else: |
||
53 | return self.manager.get_all(**kwargs) |
||
54 | |||
55 | |||
56 | class TimerGetCommand(resource.ResourceGetCommand): |
||
57 | display_attributes = ['all'] |
||
58 | attribute_display_order = ['type', 'pack', 'name', 'description', 'parameters'] |
||
59 |
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: