1616# You should have received a copy of the GNU Lesser General Public License
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
19- import inspect
2019import operator
2120import sys
2221
@@ -72,7 +71,7 @@ def do_custom(self):
7271if self .mgr ._from_parent_attrs :
7372for k in self .mgr ._from_parent_attrs :
7473data [k ]= self .args [k ]
75- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .cls ):
74+ if not issubclass (self .cls , gitlab . mixins . GetWithoutIdMixin ):
7675data [self .cls ._id_attr ]= self .args .pop (self .cls ._id_attr )
7776o = self .cls (self .mgr ,data )
7877method_name = self .action .replace ("-" ,"_" )
@@ -103,7 +102,7 @@ def do_list(self):
103102
104103def do_get (self ):
105104id = None
106- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .mgr_cls ):
105+ if not issubclass (self .mgr_cls , gitlab . mixins . GetWithoutIdMixin ):
107106id = self .args .pop (self .cls ._id_attr )
108107
109108try :
@@ -120,7 +119,7 @@ def do_delete(self):
120119
121120def do_update (self ):
122121id = None
123- if gitlab . mixins . GetWithoutIdMixin not in inspect . getmro (self .mgr_cls ):
122+ if not issubclass (self .mgr_cls , gitlab . mixins . GetWithoutIdMixin ):
124123id = self .args .pop (self .cls ._id_attr )
125124try :
126125return self .mgr .update (id ,self .args )
@@ -160,7 +159,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
160159sub_parser_action .add_argument ("--%s" % id_attr ,required = True )
161160
162161if action_name == "get" :
163- if gitlab .mixins .GetWithoutIdMixin not in inspect . getmro ( cls ):
162+ if not issubclass ( cls , gitlab .mixins .GetWithoutIdMixin ):
164163if cls ._id_attr is not None :
165164id_attr = cls ._id_attr .replace ("_" ,"-" )
166165sub_parser_action .add_argument ("--%s" % id_attr ,required = True )
@@ -210,7 +209,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
210209sub_parser_action .add_argument ("--sudo" ,required = False )
211210
212211# 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 ):
214213if cls ._id_attr is not None :
215214id_attr = cls ._id_attr .replace ("_" ,"-" )
216215sub_parser_action .add_argument ("--%s" % id_attr ,required = True )
@@ -268,12 +267,11 @@ def extend_parser(parser):
268267# populate argparse for all Gitlab Object
269268classes = []
270269for 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 )
277275classes .sort (key = operator .attrgetter ("__name__" ))
278276
279277for cls in classes :