From: biao716.wang Date: Mon, 15 Aug 2022 08:33:58 +0000 (+0900) Subject: change metaclass with python3 style X-Git-Tag: accepted/tools/devbase/tools/20250527.103804~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=382c204d0209bc6f715d3eb517bfcc99e4d5c0d0;p=tools%2Fmic.git change metaclass with python3 style Change-Id: Icc022572d61129607de63e04b4b79cd07594c46b Signed-off-by: biao716.wang --- diff --git a/mic/3rdparty/pykickstart/commands/partition.py b/mic/3rdparty/pykickstart/commands/partition.py index 2ed4bdc..a4d6fc0 100644 --- a/mic/3rdparty/pykickstart/commands/partition.py +++ b/mic/3rdparty/pykickstart/commands/partition.py @@ -117,7 +117,7 @@ class FC4_PartData(FC3_PartData): retval += " --bytes-per-inode=%d" % self.bytesPerInode if self.fsopts: retval += " --fsoptions=\"%s\"" % self.fsopts - if self.label + if self.label: retval += " --label=%s" % self.label if self.fslabel != "": retval += " --fslabel=%s" % self.fslabel diff --git a/mic/pluginbase.py b/mic/pluginbase.py index 0bb1bad..65351c5 100644 --- a/mic/pluginbase.py +++ b/mic/pluginbase.py @@ -1,8 +1,3 @@ -#!/usr/bin/python3 -tt -# -# Copyright (c) 2011 Intel, Inc. -# -# This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; version 2 of the License # @@ -20,25 +15,31 @@ import shutil from mic import msger from mic.utils import errors -class _Plugin(object): - class __metaclass__(type): - def __init__(cls, name, bases, attrs): - if not hasattr(cls, 'plugins'): - cls.plugins = {} +class pluginMetaClass(type): + def __new__(cls, name, bases, attrs): + + return type.__new__(cls,name, bases, attrs) + + def __init__(cls, name, bases, attrs): + if not hasattr(cls, 'plugins'): + cls.plugins = {} + elif 'mic_plugin_type' in attrs: + if attrs['mic_plugin_type'] not in cls.plugins: + cls.plugins[attrs['mic_plugin_type']] = {} + + elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs: + cls.plugins[cls.mic_plugin_type][attrs['name']] = cls - elif 'mic_plugin_type' in attrs: - if attrs['mic_plugin_type'] not in cls.plugins: - cls.plugins[attrs['mic_plugin_type']] = {} + def show_plugins(cls): + for cls in cls.plugins[cls.mic_plugin_type]: + print (cls) - elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs: - cls.plugins[cls.mic_plugin_type][attrs['name']] = cls + def get_plugins(cls): + return cls.plugins - def show_plugins(cls): - for cls in cls.plugins[cls.mic_plugin_type]: - print (cls) - def get_plugins(cls): - return cls.plugins +class _Plugin(object, metaclass=pluginMetaClass): + pass class ImagerPlugin(_Plugin): mic_plugin_type = "imager"