def run(): # Print services if self.service.get_subservices(): yield termcolor.colored(' ** Services **', 'cyan') def column_iterator(): for name, service in self.service.get_subservices(): yield termcolor.colored(name, type_of_service(service).color), len(name) for line in in_columns(column_iterator(), self.shell.pty): yield line # Print actions if self.service.get_actions(): yield termcolor.colored(' ** Actions **', 'cyan') def column_iterator(): for name, action in self.service.get_actions(): yield termcolor.colored(name, type_of_action(action).color), len(name) for line in in_columns(column_iterator(), self.shell.pty): yield line
def print_all_completions(self, all_completions): self.stdout.write('\r\n') # Create an iterator which yields all the comments (in their color), # and pass it through in_columns/lesspipe def column_items(): for w in all_completions: handler_type = w[1].handler_type text = '%s%s' % (termcolor.colored(w[0], handler_type.color), termcolor.colored(handler_type.postfix, handler_type.postfix_color)) length = len(w[0]) + len(handler_type.postfix) yield text, length lesspipe(in_columns(column_items(), self.pty), self.pty)
def print_all_completions(self, all_completions): self.stdout.write('\r\n') # Create an iterator which yields all the comments (in their color), # and pass it through in_columns/lesspipe def column_items(): for w in all_completions: handler_type = w[1].handler_type text = '%s%s' % ( termcolor.colored(w[0], handler_type.color), termcolor.colored(handler_type.postfix, handler_type.postfix_color)) length = len(w[0]) + len(handler_type.postfix) yield text, length lesspipe(in_columns(column_items(), self.pty), self.pty)
def inspect(): # Print full name yield termcolor.colored(' Service: ', 'cyan') + \ termcolor.colored(self.service.__repr__(path_only=True), 'yellow') # Service class definition created on yield termcolor.colored(' Created on: ', 'cyan') + \ termcolor.colored(self.service._creation_date, 'red') # Print mro yield termcolor.colored(' Mro:', 'cyan') i = 1 for m in self.service.__class__.__mro__: if m.__module__ != 'deployer.service' and m != object: yield termcolor.colored(' %i ' % i, 'cyan') + \ termcolor.colored('%s.' % m.__module__, 'red') + \ termcolor.colored('%s' % m.__name__, 'yellow') i += 1 # Print host mappings yield termcolor.colored(' Hosts:', 'cyan') for role in sorted(self.service.hosts._hosts.keys()): items = self.service.hosts._hosts[role] yield termcolor.colored(' "%s"' % role, 'yellow') i = 1 for host in sorted(items, key=lambda h:h.slug): yield termcolor.colored(' %3i ' % i, 'cyan') + \ termcolor.colored('%-25s (%s)' % (host.slug, getattr(host, 'address', '')), 'red') i += 1 # Print the first docstring (look to the parents) for m in self.service.__class__.__mro__: if m.__module__ != 'deployer.service' and m != object and m.__doc__: yield termcolor.colored(' Docstring:\n', 'cyan') + \ termcolor.colored(m.__doc__ or '<None>', 'red') break # Actions yield termcolor.colored(' Actions:', 'cyan') def item_iterator(): for name, a in self.service.get_actions(): yield termcolor.colored(name, 'red'), len(name) for line in in_columns(item_iterator(), self.shell.pty, margin_left=13): yield line # Services yield termcolor.colored(' Sub services:', 'cyan') # Group by service group grouper = lambda i:i[1].get_group() for group, services in groupby(sorted(self.service.get_subservices(), key=grouper), grouper): yield termcolor.colored(' "%s"' % group.__name__, 'yellow') # Create iterator for all the items in this group def item_iterator(): for name, s in services: if s.parent == self.service: text = termcolor.colored(name, type_of_service(s).color) length = len(name) else: text = termcolor.colored('%s -> %s' % (name, s.__repr__(path_only=True)), type_of_service(s).color) length = len('%s -> %s' % (name, s.__repr__(path_only=True))) yield text, length # Show in columns for line in in_columns(item_iterator(), self.shell.pty, margin_left=13): yield line
def inspect(): # Print full name yield termcolor.colored(' Service: ', 'cyan') + \ termcolor.colored(self.service.__repr__(path_only=True), 'yellow') # Service class definition created on yield termcolor.colored(' Created on: ', 'cyan') + \ termcolor.colored(self.service._creation_date, 'red') # Print mro yield termcolor.colored(' Mro:', 'cyan') i = 1 for m in self.service.__class__.__mro__: if m.__module__ != 'deployer.service' and m != object: yield termcolor.colored(' %i ' % i, 'cyan') + \ termcolor.colored('%s.' % m.__module__, 'red') + \ termcolor.colored('%s' % m.__name__, 'yellow') i += 1 # File names yield termcolor.colored(' Files:', 'cyan') i = 1 for m in self.service.__class__.__mro__: if m.__module__ != 'deployer.service' and m != object: yield termcolor.colored(' %i ' % i, 'cyan') + \ termcolor.colored(getfile(m), 'red') i += 1 # Print host mappings yield termcolor.colored(' Hosts:', 'cyan') for role in sorted(self.service.hosts._hosts.keys()): items = self.service.hosts._hosts[role] yield termcolor.colored(' "%s"' % role, 'yellow') i = 1 for host in sorted(items, key=lambda h:h.slug): yield termcolor.colored(' %3i ' % i, 'cyan') + \ termcolor.colored('%-25s (%s)' % (host.slug, getattr(host, 'address', '')), 'red') i += 1 # Print the first docstring (look to the parents) for m in self.service.__class__.__mro__: if m.__module__ != 'deployer.service' and m != object and m.__doc__: yield termcolor.colored(' Docstring:\n', 'cyan') + \ termcolor.colored(m.__doc__ or '<None>', 'red') break # Actions yield termcolor.colored(' Actions:', 'cyan') def item_iterator(): for name, a in self.service.get_actions(): yield termcolor.colored(name, 'red'), len(name) for line in in_columns(item_iterator(), self.shell.pty, margin_left=13): yield line # Services yield termcolor.colored(' Sub services:', 'cyan') # Group by service group grouper = lambda i:i[1].get_group() for group, services in groupby(sorted(self.service.get_subservices(), key=grouper), grouper): yield termcolor.colored(' "%s"' % group.__name__, 'yellow') # Create iterator for all the items in this group def item_iterator(): for name, s in services: if s.parent == self.service: text = termcolor.colored(name, type_of_service(s).color) length = len(name) else: text = termcolor.colored('%s -> %s' % (name, s.__repr__(path_only=True)), type_of_service(s).color) length = len('%s -> %s' % (name, s.__repr__(path_only=True))) yield text, length # Show in columns for line in in_columns(item_iterator(), self.shell.pty, margin_left=13): yield line