16
16
# You should have received a copy of the GNU Lesser General Public License
17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
19
- import inspect
20
19
import operator
21
20
import sys
22
21
@@ -72,7 +71,7 @@ def do_custom(self):
72
71
if self .mgr ._from_parent_attrs :
73
72
for k in self .mgr ._from_parent_attrs :
74
73
data [k ] = self .args [k ]
75
- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .cls ):
74
+ if not issubclass (self .cls , gitlab . mixins . GetWithoutIdMixin ):
76
75
data [self .cls ._id_attr ] = self .args .pop (self .cls ._id_attr )
77
76
o = self .cls (self .mgr , data )
78
77
method_name = self .action .replace ("-" , "_" )
@@ -103,7 +102,7 @@ def do_list(self):
103
102
104
103
def do_get (self ):
105
104
id = None
106
- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .mgr_cls ):
105
+ if not issubclass (self .mgr_cls , gitlab . mixins . GetWithoutIdMixin ):
107
106
id = self .args .pop (self .cls ._id_attr )
108
107
109
108
try :
@@ -120,7 +119,7 @@ def do_delete(self):
120
119
121
120
def do_update (self ):
122
121
id = None
123
- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .mgr_cls ):
122
+ if not issubclass (self .mgr_cls , gitlab . mixins . GetWithoutIdMixin ):
124
123
id = self .args .pop (self .cls ._id_attr )
125
124
try :
126
125
return self .mgr .update (id , self .args )
@@ -160,7 +159,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
160
159
sub_parser_action .add_argument ("--%s" % id_attr , required = True )
161
160
162
161
if action_name == "get" :
163
- if gitlab .mixins .GetWithoutIdMixin not in inspect . getmro ( cls ):
162
+ if not issubclass ( cls , gitlab .mixins .GetWithoutIdMixin ):
164
163
if cls ._id_attr is not None :
165
164
id_attr = cls ._id_attr .replace ("_" , "-" )
166
165
sub_parser_action .add_argument ("--%s" % id_attr , required = True )
@@ -210,7 +209,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
210
209
sub_parser_action .add_argument ("--sudo" , required = False )
211
210
212
211
# We need to get the object somehow
213
- if gitlab .mixins .GetWithoutIdMixin not in inspect . getmro ( cls ):
212
+ if not issubclass ( cls , gitlab .mixins .GetWithoutIdMixin ):
214
213
if cls ._id_attr is not None :
215
214
id_attr = cls ._id_attr .replace ("_" , "-" )
216
215
sub_parser_action .add_argument ("--%s" % id_attr , required = True )
@@ -268,12 +267,11 @@ def extend_parser(parser):
268
267
# populate argparse for all Gitlab Object
269
268
classes = []
270
269
for cls in gitlab .v4 .objects .__dict__ .values ():
271
- try :
272
- if gitlab .base .RESTManager in inspect .getmro (cls ):
273
- if cls ._obj_cls is not None :
274
- classes .append (cls ._obj_cls )
275
- except AttributeError :
276
- pass
270
+ if not isinstance (cls , type ):
271
+ continue
272
+ if issubclass (cls , gitlab .base .RESTManager ):
273
+ if cls ._obj_cls is not None :
274
+ classes .append (cls ._obj_cls )
277
275
classes .sort (key = operator .attrgetter ("__name__" ))
278
276
279
277
for cls in classes :
0 commit comments