2727from openstackclient .common import exceptions
2828
2929
30- # Decorator for cli-args
31- def arg (* args , ** kwargs ):
32- def _decorator (func ):
33- # Because of the sematics of decorator composition if we just append
34- # to the options list positional options will appear to be backwards.
35- func .__dict__ .setdefault ('arguments' , []).insert (0 , (args , kwargs ))
36- return func
37- return _decorator
38-
39-
40- def pretty_choice_list (l ):
41- return ', ' .join ("'%s'" % i for i in l )
42-
43-
44- def print_list (objs , fields , formatters = {}):
45- pt = prettytable .PrettyTable ([f for f in fields ], caching = False )
46- pt .aligns = ['l' for f in fields ]
47-
48- for o in objs :
49- row = []
50- for field in fields :
51- if field in formatters :
52- row .append (formatters [field ](o ))
53- else :
54- field_name = field .lower ().replace (' ' , '_' )
55- data = getattr (o , field_name , '' )
56- row .append (data )
57- pt .add_row (row )
58-
59- pt .printt (sortby = fields [0 ])
60-
61-
62- def print_dict (d ):
63- pt = prettytable .PrettyTable (['Property' , 'Value' ], caching = False )
64- pt .aligns = ['l' , 'l' ]
65- [pt .add_row (list (r )) for r in d .iteritems ()]
66- pt .printt (sortby = 'Property' )
67-
68-
6930def find_resource (manager , name_or_id ):
7031 """Helper for the _find_* methods."""
7132 # first try to get entity as integer id
@@ -91,21 +52,6 @@ def find_resource(manager, name_or_id):
9152 raise exceptions .CommandError (msg )
9253
9354
94- def skip_authentication (f ):
95- """Function decorator used to indicate a caller may be unauthenticated."""
96- f .require_authentication = False
97- return f
98-
99-
100- def is_authentication_required (f ):
101- """Checks to see if the function requires authentication.
102-
103- Use the skip_authentication decorator to indicate a caller may
104- skip the authentication step.
105- """
106- return getattr (f , 'require_authentication' , True )
107-
108-
10955def string_to_bool (arg ):
11056 return arg .strip ().lower () in ('t' , 'true' , 'yes' , '1' )
11157
0 commit comments