def getCommandInstance(command): try: module = importCommand(command) commandInstances = [commandClass() for commandClass in Command.__subclasses__()] commandToExec = utils.find(lambda recipes_installedCommand: recipes_installedCommand.name == command, commandInstances) except ImportError, e: logging.error('Unknown command: %s.' % command) print 'Search available commands with "ale search", install new command with "ale install <command>"' return
def execute(self, args=None): files = [] pattern = re.compile('.*/recipes_all.*commands/.*\.py$') for (dp, dn, fn) in os.walk(recipes_allroot): for file in fn: filename = os.path.join(dp, file) if pattern.search(filename) and not '__' in filename: files.append(filename) modules = [] module_names = map(self.module_name_part, files) if not recipes_allroot in sys.path: sys.path.insert(0, recipes_allroot) for module_name in module_names: logging.debug('Importing mod %s as %s' % (module_name, self.package_name_part(module_name))) module = __import__(module_name, globals(), locals(), [self.package_name_part(module_name)]) modules += [module] from ale.base import Command commandList = Command.__subclasses__() print 'Syntax: "ale install <command>" to activate one of these\n' print 'Commands available for install:' for command in commandList: instance = command() if instance.name != 'search': # ourself is in memory when __subclassess__ was called if 'experimental' not in instance.tags: print ' %-20.20s %s' % (instance.name, instance.shorthelp) print '\nCommands which are completely experimental or not working yet (under development)' for command in commandList: instance = command() if instance.name != 'search': # ourself is in memory when __subclassess__ was called if 'experimental' in instance.tags: print ' %-20.20s %s' % (instance.name, instance.shorthelp) sys.path.pop()
def execute(self, args=None): files = [] pattern = re.compile('.*/recipes_installed.*commands/.*\.py$') for (dp, dn, fn) in os.walk(recipes_installedroot): for file in fn: filename = os.path.join(dp, file) if pattern.search(filename) and not '__' in filename: files.append(filename) modules = [] module_names = map(self.module_name_part, files) for module_name in module_names: logging.debug('Importing mod [%s] as %s' % (module_name, self.package_name_part(module_name))) module = __import__(module_name, globals(), locals(), [self.package_name_part(module_name)]) modules += [module] from ale.base import Command commandList = Command.__subclasses__() print 'Syntax: ale <command>\n' print 'Core commands:' for command in commandList: instance = command() if 'core' in instance.tags: print ' %-20.20s %s' % (instance.name, instance.shorthelp) heading = False for command in commandList: instance = command() if 'core' not in instance.tags: if not heading: print '\nAdditional Commands:' heading = True print ' %-20.20s %s' % (instance.name, instance.shorthelp)