import posixpath import logging import time import ccdb 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.vers") def create_util_instance(): log.debug(" registring AddData") return VersionsUtility() class VersionsUtility(ConsoleUtilBase): command = "vers" name = "Versions" short_descr = "Show versions of data for specified type table" 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("VersionsUtility 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.raw_table_path = "" self.variation = "" self.run = -1 if not self.process_arguments(args): return 1 if self.run == -1: self.run = self.context.current_run if not self.validate(): return 1 #correct path self.table_path = self.context.prepare_path(self.raw_table_path) #check xuch table really exists table = provider.get_type_table(self.table_path, False) if not table: logging.warning("Type table %s not found in the DB"% self.table_path) return 1 assignments = provider.get_assignments(self.table_path, self.run) print "(Created) (Modified) (variation) (run range) (comments)" for asgmnt in assignments: assert isinstance(asgmnt, ccdb.Assignment) print time.strftime("%Y-%m-%d_%H-%M-%S ", time.localtime(asgmnt.created_time)) +" "+\ time.strftime("%Y-%m-%d_%H-%M-%S ", time.localtime(asgmnt.modified_time)) +" "+\ asgmnt.variation.name+" "+\ repr(asgmnt.run_range.min) + "-" + repr(asgmnt.run_range.max) +" "+\ asgmnt.comment 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