import posixpath import logging import time from ccdb.ccdb_pyllapi import Directory, ConstantsTypeTable, ConstantsTypeColumn, Variation from ccdb import MySQLProvider from ccdb.cmd import ConsoleUtilBase from ccdb.cmd import Theme from ccdb.cmd import is_verbose, is_debug_verbose log = logging.getLogger("ccdb.cmd.utils.info") def create_util_instance(): log.debug(" registring Info") return Info() class Info(ConsoleUtilBase): command = "info" name = "Info" short_descr = "Prints extended information of object by the path" uses_db = True #variables for each process rawentry = "/" #object path with possible pattern, like /mole/* path = "/" #parent path #---------------------------------------- # process #---------------------------------------- def process(self, args): log.debug("InfoUtil is gained a control over the process.") log.debug(" " + " ".join(args)) assert self.context != None provider = self.context.provider isinstance(provider, MySQLProvider) #process arguments self.rawentry = "" self.object_type = "type_table" self.process_arguments(args) #correct ending / self.path = self.context.prepare_path(self.rawentry) if not self.rawentry: log.warning("No path is given. Use 'help info' or 'usage info' for getting help.") #it is a type table if self.object_type == "type_table": self.type_table = provider.get_type_table(self.path, True) if self.type_table: self.print_type_table(self.type_table) else: log.warning("No type table with this path") return 1 #it is a directory if self.object_type == "directory": parent_dir = provider.get_directory(self.path) if(parent_dir): self.print_directory(parent_dir) else: log.warning("No directory with this path") return 1 #it is a variation if self.object_type == "variation": variation = provider.get_variation(self.rawentry) if(variation): self.print_variation(variation) else: log.warning("No variation with this name") return 1 #everything is fine! return 0 #---------------------------------------- # process_arguments #---------------------------------------- def process_arguments(self, args): #parse loop i=0 token = "" while i < len(args): token = args[i].strip() i+=1 if token.startswith('-'): #it is some command, lets parse what is the command #variation if token == "-v" or token.startswith("--variation"): if i - info about type table with given path info -d - info about directory with given path info -v - info about variation with given name """