def loadFromUserPlugins(self): '''允许用户通过ckstyle install添加plugin,执行的时候载入之''' include = self.config.include exclude = self.config.exclude safeMode = self.config.safeMode safeModeExcludes = 'combine-same-rulesets' def import_module(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod root = os.path.realpath(os.path.join(__file__, '../userplugins/plugins')) modulePath = self.getModulePath(root) pluginClassName = 'PluginClass' for filename in os.listdir(root): if filename.startswith('.') or filename.startswith('_'): continue if not os.path.isdir(os.path.realpath(os.path.join(root, filename))): continue plugin = None try: plugin = import_module(modulePath + filename + '.index') except Exception as e: console.showError('Orz... can not load %s' % modulePath + filename + '.index') continue pluginClass = None if hasattr(plugin, pluginClassName): pluginClass = getattr(plugin, pluginClassName) else: console.showError('class %s should exist in %s.py' % (pluginClassName, filename + '/index')) continue self.registerPluginClass(pluginClass)
def loadFromUserPlugins(self): '''允许用户通过ckstyle install添加plugin,执行的时候载入之''' include = self.config.include exclude = self.config.exclude safeMode = self.config.safeMode safeModeExcludes = 'combine-same-rulesets' def import_module(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod root = os.path.realpath( os.path.join(__file__, '../userplugins/plugins')) modulePath = self.getModulePath(root) pluginClassName = 'PluginClass' for filename in os.listdir(root): if filename.startswith('.') or filename.startswith('_'): continue if not os.path.isdir(os.path.realpath(os.path.join(root, filename))): continue plugin = None try: plugin = import_module(modulePath + filename + '.index') except Exception as e: console.showError('Orz... can not load %s' % modulePath + filename + '.index') continue pluginClass = None if hasattr(plugin, pluginClassName): pluginClass = getattr(plugin, pluginClassName) else: console.showError('class %s should exist in %s.py' % (pluginClassName, filename + '/index')) continue self.registerPluginClass(pluginClass)
def fetch(name, version, url, root, pluginType): if noVersion: version = '' pluginDir = realpath(root, './' + name) replacedVer = '' if version == '' else version.replace('.', '_') if not os.path.exists(pluginDir): os.mkdir(pluginDir) open(realpath(pluginDir, './__init__.py'), 'w').write('') versionDir = pluginDir if version is not None and version != '': versionDir = realpath(pluginDir, './v' + replacedVer) if not os.path.exists(versionDir): os.mkdir(versionDir) open(realpath(versionDir, './__init__.py'), 'w').write('') filePath = realpath(versionDir, './index.py') if debug or not os.path.exists(filePath): realUrl = url % (name, '' if version == '' else ('' + version + '/')) console.showOk('Downloading %s%s from %s' % (name, version, realUrl)) request = urllib.urlopen(realUrl) if request.getcode() != 200: console.showError('Can not download file, status code : ' + str(request.getcode())) return try: f = open(filePath, 'w') f.write(request.read()) console.showOk('%s%s Downloaded in %s' % (name, version, filePath)) if pluginType == 'commands': console.showOk('Download successfully!') console.showOk('Please type "ckstyle %s" to execute.' % name) #urllib.urlretrieve(realUrl, realUrl) except IOError as e: console.error(str(e)) versionPath = '' if replacedVer == '' else '.v' + replacedVer whatIWant = getWhatIWant(pluginType) moduleName = "ckstyle.userplugins.%s.%s%s.index" % (pluginType, name, versionPath) try: plugin = __import__(moduleName, fromlist=["ckstyle.userplugins.%s.%s%s" % (pluginType, name, versionPath)]) except ImportError as e: console.showError(('Can not import plugin %s : ' % name) + str(e)) return filePath = realpath(versionDir, './index.pyc') if os.path.exists(filePath): os.remove(filePath) if pluginType == 'commands': if hasattr(plugin, 'doCommand'): return getattr(plugin, 'doCommand') else: console.showError('%s do not contain %s' % (moduleName, whatIWant)) return None
def fetch(name, version, url, root, pluginType): if noVersion: version = '' pluginDir = realpath(root, './' + name) replacedVer = '' if version == '' else version.replace('.', '_') if not os.path.exists(pluginDir): os.mkdir(pluginDir) open(realpath(pluginDir, './__init__.py'), 'w').write('') versionDir = pluginDir if version is not None and version != '': versionDir = realpath(pluginDir, './v' + replacedVer) if not os.path.exists(versionDir): os.mkdir(versionDir) open(realpath(versionDir, './__init__.py'), 'w').write('') filePath = realpath(versionDir, './index.py') if debug or not os.path.exists(filePath): realUrl = url % (name, '' if version == '' else ('' + version + '/')) console.showOk('Downloading %s%s from %s' % (name, version, realUrl)) request = urllib.urlopen(realUrl) if request.getcode() != 200: console.showError('Can not download file, status code : ' + str(request.getcode())) return try: f = open(filePath, 'w') f.write(request.read()) console.showOk('%s%s Downloaded in %s' % (name, version, filePath)) if pluginType == 'commands': console.showOk('Download successfully!') console.showOk('Please type "ckstyle %s" to execute.' % name) #urllib.urlretrieve(realUrl, realUrl) except IOError as e: console.error(str(e)) versionPath = '' if replacedVer == '' else '.v' + replacedVer whatIWant = getWhatIWant(pluginType) moduleName = "ckstyle.userplugins.%s.%s%s.index" % (pluginType, name, versionPath) try: plugin = __import__(moduleName, fromlist=[ "ckstyle.userplugins.%s.%s%s" % (pluginType, name, versionPath) ]) except ImportError as e: console.showError(('Can not import plugin %s : ' % name) + str(e)) return filePath = realpath(versionDir, './index.pyc') if os.path.exists(filePath): os.remove(filePath) if pluginType == 'commands': if hasattr(plugin, 'doCommand'): return getattr(plugin, 'doCommand') else: console.showError('%s do not contain %s' % (moduleName, whatIWant)) return None