def __init__(self, name, **kwargs): self.name = name self.classpath = utility.kwargs_get_string(kwargs, 'classpath', default = None) self.cli_spec = cli.CLISpec(**kwargs) self.dirty_opts = False self.dirty_args = False self.command_arguments = utility.flatten_to_list(kwargs.get('command_arguments', None)) utility.debug(str(self))
def add_options(self, *args): """ Add options if not already present as an option or argument. """ for o in args: dest_name = o.get_dest() if self.cli_spec.find_option(dest_name): utility.debug('Not adding "%s" option more than once.' % dest_name) else: self.cli_spec.add_to_list('options', o) self.dirty_opts = True
def load_verbspace(command_name, command_dir, config, version, description, package): #=============================================================================== """ Build a verb space by searching for source files with verbs in this source file's directory, the calling script location (if provided), and the working directory. """ utility.debug('Loading verbspace for "%s" version "%s" from "%s"...' % (command_name, version, command_dir)) scan_base_dirs = [os.path.dirname(__file__)] verbs_subdir = '%s.d' % command_name if command_dir is not None and command_dir not in scan_base_dirs: scan_base_dirs.append(command_dir) cwd = os.getcwd() if cwd not in scan_base_dirs: scan_base_dirs.append(cwd) # Build the VOLT namespace with the specific set of classes, functions and # decorators we make available to command implementations. verbs = {} verb_decorators = VerbDecorators(verbs) namespace_VOLT = VOLT(verb_decorators) # Build the verbspace by executing modules found based on the calling # script location and the location of this module. The executed modules # have decorator calls that populate the verbs dictionary. finder = utility.PythonSourceFinder() scan_dirs = [os.path.join(d, verbs_subdir) for d in scan_base_dirs] for scan_dir in scan_dirs: finder.add_path(scan_dir) # If running from a zip package add resource locations. if package: finder.add_resource('__main__', os.path.join('voltcli', verbs_subdir)) finder.search_and_execute(VOLT=namespace_VOLT) # Add standard verbs if they aren't supplied. def default_func(runner): runner.go() for verb_name, verb_cls in (('help', HelpVerb), ('package', PackageVerb)): if verb_name not in verbs: verbs[verb_name] = verb_cls(verb_name, default_func) return VerbSpace(command_name, version, description, namespace_VOLT, scan_dirs, verbs)
def load_verbspace(command_name, command_dir, config, version, description, package): #=============================================================================== """ Build a verb space by searching for source files with verbs in this source file's directory, the calling script location (if provided), and the working directory. """ utility.debug('Loading verbspace for "%s" version "%s" from "%s"...' % (command_name, version, command_dir)) scan_base_dirs = [os.path.dirname(__file__)] verbs_subdir = '%s.d' % command_name if command_dir is not None and command_dir not in scan_base_dirs: scan_base_dirs.append(command_dir) cwd = os.getcwd() if cwd not in scan_base_dirs: scan_base_dirs.append(cwd) # Build the VOLT namespace with the specific set of classes, functions and # decorators we make available to command implementations. verbs = {} verb_decorators = VerbDecorators(verbs) namespace_VOLT = VOLT(verb_decorators) # Build the verbspace by executing modules found based on the calling # script location and the location of this module. The executed modules # have decorator calls that populate the verbs dictionary. finder = utility.PythonSourceFinder() scan_dirs = [os.path.join(d, verbs_subdir) for d in scan_base_dirs] for scan_dir in scan_dirs: finder.add_path(scan_dir) # If running from a zip package add resource locations. if package: finder.add_resource('__main__', os.path.join('voltcli', verbs_subdir)) finder.search_and_execute(VOLT = namespace_VOLT) # Add standard verbs if they aren't supplied. def default_func(runner): runner.go() for verb_name, verb_cls in (('help', HelpVerb), ('package', PackageVerb)): if verb_name not in verbs: verbs[verb_name] = verb_cls(verb_name, default_func) return VerbSpace(command_name, version, description, namespace_VOLT, scan_dirs, verbs)
def find_log4j_config(self): if 'LOG4J_CONFIG_PATH' in os.environ: path = os.environ['LOG4J_CONFIG_PATH'] utility.debug('LOG4J_CONFIG_PATH=%s' % path) if not os.path.exists( path): # warn only, since this was not previously checked utility.warning( 'LOG4J_CONFIG_PATH refers to a nonexistent file: %s' % path) return path if not self.log4j_default: utility.abort('log4j_default not defined for verb') for fname in self.log4j_default: for dir in ('$VOLTDB_LIB/../src/frontend', '$VOLTDB_VOLTDB'): path = os.path.join(os.path.realpath(os.path.expandvars(dir)), fname) if os.path.exists(path): os.environ[ 'LOG4J_CONFIG_PATH'] = path # define this for back-compatibility utility.debug('LOG4J_CONFIG_PATH=%s' % path) return path utility.abort( 'Could not find log4j configuration file and LOG4J_CONFIG_PATH variable not set.' )
def debug(self, *msgs): """ Display DEBUG level message(s) if debug is enabled. """ utility.debug(*msgs)
def initialize(standalone_arg, command_name_arg, command_dir_arg, version_arg): """ Set the VOLTDB_LIB and VOLTDB_VOLTDB environment variables based on the script location and the working directory. """ global command_name, command_dir, version, pro_version command_name = command_name_arg command_dir = command_dir_arg version = version_arg # Stand-alone scripts don't need a develoopment environment. global standalone standalone = standalone_arg if standalone: return # Add the working directory, the command directory, and VOLTCORE as # starting points for the scan. dirs = [] def add_dir(dir): if dir and os.path.isdir(dir) and dir not in dirs: dirs.append(os.path.realpath(dir)) add_dir(os.getcwd()) add_dir(command_dir) add_dir(os.environ.get('VOLTCORE', None)) utility.verbose_info('Base directories for scan:', dirs) lib_search_globs = [] voltdb_search_globs = [] for dir in dirs: # Crawl upward and look for the lib and voltdb directories. # They may be the same directory when installed by a Linux installer. # Set the VOLTDB_... environment variables accordingly. # Also locate the voltdb jar file. global voltdb_jar while (dir and dir != '/' and ('VOLTDB_LIB' not in os.environ or not voltdb_jar)): utility.debug('Checking potential VoltDB root directory: %s' % os.path.realpath(dir)) # Try to set VOLTDB_LIB if not set. if not os.environ.get('VOLTDB_LIB', ''): for subdir in ('lib', os.path.join('lib', 'voltdb')): glob_chk = os.path.join(os.path.realpath(os.path.join(dir, subdir)), 'snappy*.jar') lib_search_globs.append(glob_chk) if glob.glob(glob_chk): os.environ['VOLTDB_LIB'] = os.path.join(dir, subdir) utility.debug('VOLTDB_LIB=>%s' % os.environ['VOLTDB_LIB']) # Try to set VOLTDB_VOLTDB if not set. Look for the voltdb jar file. if not os.environ.get('VOLTDB_VOLTDB', '') or voltdb_jar is None: for subdir in ('voltdb', os.path.join('lib', 'voltdb')): # Need the hyphen to avoid the volt client jar. glob_chk = os.path.join(os.path.realpath(os.path.join(dir, subdir)), 'voltdb-*.jar') voltdb_search_globs.append(glob_chk) for voltdb_jar_chk in glob.glob(glob_chk): if re_voltdb_jar.match(os.path.basename(voltdb_jar_chk)): voltdb_jar = os.path.realpath(voltdb_jar_chk) utility.debug('VoltDB jar: %s' % voltdb_jar) if not os.environ.get('VOLTDB_VOLTDB', ''): os.environ['VOLTDB_VOLTDB'] = os.path.dirname(voltdb_jar) utility.debug('VOLTDB_VOLTDB=>%s' % os.environ['VOLTDB_VOLTDB']) # Capture the base third_party python path? third_party_python_chk = os.path.join(dir, 'third_party', 'python') if os.path.isdir(third_party_python_chk): global third_party_python third_party_python = third_party_python_chk dir = os.path.dirname(dir) # If the VoltDB jar was found then VOLTDB_VOLTDB will also be set. if voltdb_jar is None: utility.abort('Failed to find the VoltDB jar file.', ('You may need to perform a build.', 'Searched the following:', voltdb_search_globs)) if not os.environ.get('VOLTDB_LIB', ''): utility.abort('Failed to find the VoltDB library directory.', ('You may need to perform a build.', 'Searched the following:', lib_search_globs)) pro_version = utility.is_pro_version(voltdb_jar) utility.debug('VoltDB Pro Version: %s' % pro_version) # LOG4J configuration if 'LOG4J_CONFIG_PATH' not in os.environ: for chk_dir in ('$VOLTDB_LIB/../src/frontend', '$VOLTDB_VOLTDB'): path = os.path.join(os.path.realpath(os.path.expandvars(chk_dir)), 'log4j.xml') if os.path.exists(path): os.environ['LOG4J_CONFIG_PATH'] = path utility.debug('LOG4J_CONFIG_PATH=>%s' % os.environ['LOG4J_CONFIG_PATH']) break else: utility.abort('Could not find log4j configuration file or LOG4J_CONFIG_PATH variable.') for var in ('VOLTDB_LIB', 'VOLTDB_VOLTDB', 'LOG4J_CONFIG_PATH'): utility.verbose_info('Environment: %s=%s' % (var, os.environ[var])) # Classpath is the voltdb jar and all the jars in VOLTDB_LIB, and if present, # any user supplied jars under VOLTDB/lib/extension global classpath classpath = [voltdb_jar] for path in glob.glob(os.path.join(os.environ['VOLTDB_LIB'], '*.jar')): classpath.append(path) for path in glob.glob(os.path.join(os.environ['VOLTDB_LIB'], 'extension', '*.jar')): classpath.append(path) utility.verbose_info('Classpath: %s' % ':'.join(classpath))
def initialize(standalone_arg, command_name_arg, command_dir_arg, version_arg): """ Set the VOLTDB_LIB and VOLTDB_VOLTDB environment variables based on the script location and the working directory. """ global command_name, command_dir, version, pro_version command_name = command_name_arg command_dir = command_dir_arg version = version_arg # Stand-alone scripts don't need a develoopment environment. global standalone standalone = standalone_arg if standalone: return # Add the working directory, the command directory, and VOLTCORE as # starting points for the scan. dirs = [] def add_dir(dir): if dir and os.path.isdir(dir) and dir not in dirs: dirs.append(os.path.realpath(dir)) add_dir(os.getcwd()) add_dir(command_dir) add_dir(os.environ.get('VOLTCORE', None)) utility.verbose_info('Base directories for scan:', dirs) lib_search_globs = [] voltdb_search_globs = [] for dir in dirs: # Crawl upward and look for the lib and voltdb directories. # They may be the same directory when installed by a Linux installer. # Set the VOLTDB_... environment variables accordingly. # Also locate the voltdb jar file. global voltdb_jar while (dir and dir != '/' and ('VOLTDB_LIB' not in os.environ or not voltdb_jar)): utility.debug('Checking potential VoltDB root directory: %s' % os.path.realpath(dir)) # Try to set VOLTDB_LIB if not set. if not os.environ.get('VOLTDB_LIB', ''): for subdir in ('lib', os.path.join('lib', 'voltdb')): glob_chk = os.path.join( os.path.realpath(os.path.join(dir, subdir)), 'snappy*.jar') lib_search_globs.append(glob_chk) if glob.glob(glob_chk): os.environ['VOLTDB_LIB'] = os.path.join(dir, subdir) utility.debug('VOLTDB_LIB=>%s' % os.environ['VOLTDB_LIB']) # Try to set VOLTDB_VOLTDB if not set. Look for the voltdb jar file. if not os.environ.get('VOLTDB_VOLTDB', '') or voltdb_jar is None: for subdir in ('voltdb', os.path.join('lib', 'voltdb')): # Need the hyphen to avoid the volt client jar. glob_chk = os.path.join( os.path.realpath(os.path.join(dir, subdir)), 'voltdb-*.jar') voltdb_search_globs.append(glob_chk) for voltdb_jar_chk in glob.glob(glob_chk): if re_voltdb_jar.match( os.path.basename(voltdb_jar_chk)): voltdb_jar = os.path.realpath(voltdb_jar_chk) utility.debug('VoltDB jar: %s' % voltdb_jar) if not os.environ.get('VOLTDB_VOLTDB', ''): os.environ['VOLTDB_VOLTDB'] = os.path.dirname( voltdb_jar) utility.debug('VOLTDB_VOLTDB=>%s' % os.environ['VOLTDB_VOLTDB']) # Capture the base third_party python path? third_party_python_chk = os.path.join(dir, 'third_party', 'python') if os.path.isdir(third_party_python_chk): global third_party_python third_party_python = third_party_python_chk dir = os.path.dirname(dir) # If the VoltDB jar was found then VOLTDB_VOLTDB will also be set. if voltdb_jar is None: utility.abort('Failed to find the VoltDB jar file.', ('You may need to perform a build.', 'Searched the following:', voltdb_search_globs)) if not os.environ.get('VOLTDB_LIB', ''): utility.abort('Failed to find the VoltDB library directory.', ('You may need to perform a build.', 'Searched the following:', lib_search_globs)) pro_version = utility.is_pro_version(voltdb_jar) utility.debug('VoltDB Pro Version: %s' % pro_version) # LOG4J configuration if 'LOG4J_CONFIG_PATH' not in os.environ: for chk_dir in ('$VOLTDB_LIB/../src/frontend', '$VOLTDB_VOLTDB'): path = os.path.join(os.path.realpath(os.path.expandvars(chk_dir)), 'log4j.xml') if os.path.exists(path): os.environ['LOG4J_CONFIG_PATH'] = path utility.debug('LOG4J_CONFIG_PATH=>%s' % os.environ['LOG4J_CONFIG_PATH']) break else: utility.abort( 'Could not find log4j configuration file or LOG4J_CONFIG_PATH variable.' ) for var in ('VOLTDB_LIB', 'VOLTDB_VOLTDB', 'LOG4J_CONFIG_PATH'): utility.verbose_info('Environment: %s=%s' % (var, os.environ[var])) # Classpath is the voltdb jar and all the jars in VOLTDB_LIB, and if present, # any user supplied jars under VOLTDB/lib/extension global classpath classpath = [voltdb_jar] for path in glob.glob(os.path.join(os.environ['VOLTDB_LIB'], '*.jar')): classpath.append(path) for path in glob.glob( os.path.join(os.environ['VOLTDB_LIB'], 'extension', '*.jar')): classpath.append(path) utility.verbose_info('Classpath: %s' % ':'.join(classpath))
def initialize(standalone_arg, command_name_arg, command_dir_arg, version_arg): """ Set the VOLTDB_LIB and VOLTDB_VOLTDB environment variables based on the script location and the working directory. """ global command_name, command_dir, version command_name = command_name_arg command_dir = command_dir_arg version = version_arg # Stand-alone scripts don't need a develoopment environment. global standalone standalone = standalone_arg if standalone: return # Add the working directory, the command directory, and VOLTCORE as # starting points for the scan. dirs = [] def add_dir(dir): if dir and os.path.isdir(dir) and dir not in dirs: dirs.append(os.path.realpath(dir)) add_dir(os.getcwd()) add_dir(command_dir) add_dir(os.environ.get("VOLTCORE", None)) utility.verbose_info("Base directories for scan:", dirs) lib_search_globs = [] voltdb_search_globs = [] for dir in dirs: # Crawl upward and look for the lib and voltdb directories. # They may be the same directory when installed by a Linux installer. # Set the VOLTDB_... environment variables accordingly. # Also locate the voltdb jar file. global voltdb_jar while dir and dir != "/" and ("VOLTDB_LIB" not in os.environ or not voltdb_jar): utility.debug("Checking potential VoltDB root directory: %s" % os.path.realpath(dir)) # Try to set VOLTDB_LIB if not set. if not os.environ.get("VOLTDB_LIB", ""): for subdir in ("lib", os.path.join("lib", "voltdb")): glob_chk = os.path.join(os.path.realpath(os.path.join(dir, subdir)), "zmq*.jar") lib_search_globs.append(glob_chk) if glob.glob(glob_chk): os.environ["VOLTDB_LIB"] = os.path.join(dir, subdir) utility.debug("VOLTDB_LIB=>%s" % os.environ["VOLTDB_LIB"]) # Try to set VOLTDB_VOLTDB if not set. Look for the voltdb jar file. if not os.environ.get("VOLTDB_VOLTDB", "") or voltdb_jar is None: for subdir in ("voltdb", os.path.join("lib", "voltdb")): # Need the hyphen to avoid the volt client jar. glob_chk = os.path.join(os.path.realpath(os.path.join(dir, subdir)), "voltdb-*.jar") voltdb_search_globs.append(glob_chk) for voltdb_jar_chk in glob.glob(glob_chk): if re_voltdb_jar.match(os.path.basename(voltdb_jar_chk)): voltdb_jar = os.path.realpath(voltdb_jar_chk) utility.debug("VoltDB jar: %s" % voltdb_jar) if not os.environ.get("VOLTDB_VOLTDB", ""): os.environ["VOLTDB_VOLTDB"] = os.path.dirname(voltdb_jar) utility.debug("VOLTDB_VOLTDB=>%s" % os.environ["VOLTDB_VOLTDB"]) # Capture the base third_party python path? third_party_python_chk = os.path.join(dir, "third_party", "python") if os.path.isdir(third_party_python_chk): global third_party_python third_party_python = third_party_python_chk dir = os.path.dirname(dir) # If the VoltDB jar was found then VOLTDB_VOLTDB will also be set. if voltdb_jar is None: utility.abort( "Failed to find the VoltDB jar file.", ("You may need to perform a build.", "Searched the following:", voltdb_search_globs), ) if not os.environ.get("VOLTDB_LIB", ""): utility.abort( "Failed to find the VoltDB library directory.", ("You may need to perform a build.", "Searched the following:", lib_search_globs), ) # LOG4J configuration if "LOG4J_CONFIG_PATH" not in os.environ: for chk_dir in ("$VOLTDB_LIB/../src/frontend", "$VOLTDB_VOLTDB"): path = os.path.join(os.path.realpath(os.path.expandvars(chk_dir)), "log4j.xml") if os.path.exists(path): os.environ["LOG4J_CONFIG_PATH"] = path utility.debug("LOG4J_CONFIG_PATH=>%s" % os.environ["LOG4J_CONFIG_PATH"]) break else: utility.abort("Could not find log4j configuration file or LOG4J_CONFIG_PATH variable.") for var in ("VOLTDB_LIB", "VOLTDB_VOLTDB", "LOG4J_CONFIG_PATH"): utility.verbose_info("Environment: %s=%s" % (var, os.environ[var])) # Classpath is the voltdb jar and all the jars in VOLTDB_LIB, and if present, # any user supplied jars under VOLTDB/lib/extension global classpath classpath = [voltdb_jar] for path in glob.glob(os.path.join(os.environ["VOLTDB_LIB"], "*.jar")): classpath.append(path) for path in glob.glob(os.path.join(os.environ["VOLTDB_LIB"], "extension", "*.jar")): classpath.append(path) utility.verbose_info("Classpath: %s" % ":".join(classpath))