예제 #1
0
def lookup_removed_profile_callback(ctx, _, value):
    """Callback function for looking up the profile which will be removed

    Profile can either be represented as an index tag (e.g. 0@i), as an index tag range (e.g.
    0@i-5@i) or as a path in the index

    :param Context ctx: context of the called command
    :param click.Option _: parameter that is being parsed and read from commandline
    :param str value: value that is being read from the commandline
    :returns str: filename of the profile to be removed
    """
    def add_to_removed(index):
        """Helper function for adding stuff to massaged values

        :param int index: index we are looking up and registering to massaged values
        """
        index_filename = commands.get_nth_profile_of(index,
                                                     ctx.params['minor'])
        start = index_filename.rfind('objects') + len('objects')
        # Remove the .perun/objects/... prefix and merge the directory and file to sha
        massaged_values.add("".join(index_filename[start:].split('/')))

    massaged_values = set()
    for single_value in value:
        index_match = store.INDEX_TAG_REGEX.match(single_value)
        range_match = store.INDEX_TAG_RANGE_REGEX.match(single_value)
        if index_match:
            add_to_removed(int(index_match.group(1)))
        elif range_match:
            from_range, to_range = int(range_match.group(1)), int(
                range_match.group(2))
            for i in range(from_range, to_range + 1):
                try:
                    add_to_removed(i)
                except click.BadParameter:
                    log.warn("skipping nonexisting tag {}@i".format(i))
        else:
            massaged_values.add(single_value)
    return massaged_values
예제 #2
0
def _loaded_stap_kernel_modules():
    """Extracts the names of all systemtap kernel modules that are currently loaded

    :return set: the list of names of loaded systemtap kernel modules
    """
    # Check that dependencies are not missing
    if (not utils.check_dependency('lsmod')
            or not utils.check_dependency('grep')
            or not utils.check_dependency('awk')
            or not utils.check_dependency('rmmod')):
        log.warn(
            'Unable to perform cleanup of systemtap kernel modules, please terminate them '
            'manually or install the missing dependencies')
    # Build the extraction command
    extractor = 'lsmod | grep stap_ | awk \'{print $1}\''

    # Run the command and save the found modules
    out, _ = utils.run_safely_external_command(extractor, False)
    modules = set()
    for line in out.decode('utf-8'):
        modules.add(line)
    return modules
예제 #3
0
파일: cli.py 프로젝트: petr-muller/perun
def validate_value(ctx, _, value):
    """Validates the value parameter for different modes.

    Value is required for set operation, while in get and set has no effect.

    Arguments:
        ctx(click.Context): called context of the command line
        _(click.Option): called option (in this case value)
        value(object): assigned value to the <value> argument

    Returns:
        object: value for the <key> argument
    """
    operation = ctx.params['operation']
    if operation in ('edit', 'get') and value:
        perun_log.warn(
            'setting <value> argument has no effect in {} config operation'.
            format(operation))
    elif operation == 'set' and not value:
        raise click.BadParameter(
            "missing <value> argument for set config operation")

    return value
예제 #4
0
파일: run.py 프로젝트: petr-muller/perun
def validate_func_parameter(ctx, _, value):
    """Validates that the func is called for func parameter (do'h!).

    Arguments:
        ctx(click.Context): called click context
        _(click.Option): parameter (either --from-time or --to-time)
        value(object): value for the given parameter

    Returns:
        object: value of the validated parameter
    """
    mode = ctx.params['mode']

    if '--function' in " ".join(sys.argv):
        if mode != 'func':
            log.warn(
                "--function option has no effect in '{}' mode".format(mode))
    elif mode == 'func':
        print(sys.argv)
        raise click.BadParameter(
            "missing specified function for list. Use --function=<f>.")

    return value
예제 #5
0
파일: run.py 프로젝트: petr-muller/perun
def validate_timestamp_parameter(ctx, param, value):
    """Validates the timestamp parameter, that it was stated with correct functions.

    If the parameter was called with mode for which it has no effect, the warning is issued.

    Arguments:
        ctx(click.Context): called click context
        param(click.Option): parameter (either --from-time or --to-time)
        value(object): value for the given parameter

    Returns:
        object: value of the validated parameter
    """
    mode = ctx.params['mode']
    param_name = param.human_readable_name
    param_cmd_name = param.human_readable_name.replace('_', '-')

    if param_cmd_name in " ".join(sys.argv) and mode != 'all':
        log.warn(
            "value '{}' for parameter '{}' has no effect in '{}' mode".format(
                value, param_name, mode))

    return value