Пример #1
0
def main():
    """
        Main function of the Swarmrob CLI

    :return:
    """
    if os.geteuid():
        sys.exit(
            colored.red("Swarmrob needs to be started with root privileges"))
    llogger = local_logger.LocalLogger()
    llogger.log_call(sys._getframe().f_code.co_name)
    params = CMDParser(include_help=False).parse_arguments()
    llogger.enable = params.verbose
    args = Args()

    with indent(4, quote=''):
        puts(
            colored.green(
                "Swarmbot - Container Orchestration for Robotic Applications"))

    try:
        switch_command(str(args.get(0)))
    except KeyError:
        with indent(4, quote='>>'):
            puts(colored.red(str(args.get(0)) + " is not a valid command"))
            puts(colored.red("Type 'swarmrob help' for a command list"))
    except Exception as e:
        puts(colored.red("An unknown error occurred"))
        llogger.exception(e, "An unknown error occurred")
        llogger.error(traceback.format_exc())
        sys.exit(1)
Пример #2
0
def main():
    """
        Main function of the Swarmrob Master CLI
    :return:
    """
    llogger = local_logger.LocalLogger()
    llogger.log_call(sys._getframe().f_code.co_name)
    console_arguments = Args()
    try:
        switch_command(str(console_arguments.get(1)))
    except KeyError:
        llogger.exception(traceback.format_exc())
        with indent(4, quote='>>'):
            puts(
                colored.red(
                    str(console_arguments.get(1)) + " is not a valid command"))
            puts(colored.red("Type 'swarmrob help' for a command list"))
Пример #3
0
def main():
    args = Args()

    input_path = os.path.realpath(args.get(0))
    output_path = os.path.realpath(args.get(1))

    image_names = ['homographies', 'masks', 'stitched']

    # Scan the input directory to get the structure
    whiteboards = {}  # whiteboards[whiteboard name] = list of stitching names
    num_stitchings = 0
    for whiteboard_path in subdirs(input_path):
        stitchings = []
        for stitching_path in subdirs(whiteboard_path):
            files = [os.path.join(stitching_path, part + '.png') for part in image_names]
            if all(os.path.exists(file) for file in files):
                stitchings.append(os.path.basename(stitching_path))
                num_stitchings += 1
        if stitchings:
            whiteboards[os.path.basename(whiteboard_path)] = stitchings

    # Remake the output directory
    shutil.rmtree(output_path)
    os.mkdir(output_path)

    # Write the structure
    with open(os.path.join(output_path, 'whiteboards.json'), 'w') as f:
        json.dump(whiteboards, f)

    # Write the deepzooms
    num_deepzooms_written = 0
    for whiteboard_name, stitchings in whiteboards.iteritems():
        input_whiteboard_path = os.path.join(input_path, whiteboard_name)
        output_whiteboard_path = os.path.join(output_path, whiteboard_name)
        os.mkdir(output_whiteboard_path)
        for stitching_name in stitchings:
            input_stitching_path = os.path.join(input_whiteboard_path, stitching_name)
            output_stitching_path = os.path.join(output_whiteboard_path, stitching_name)
            os.mkdir(output_stitching_path)
            for image_name in image_names:
                print (num_deepzooms_written + 1), '/', len(image_names) * num_stitchings
                cached_deepzoom(
                    os.path.join(input_stitching_path, image_name + '.png'),
                    os.path.join(output_stitching_path, image_name)
                )
                num_deepzooms_written += 1
Пример #4
0
import os
import glob
import sys

from clint.arguments import Args
import yaml

import stitching
import spimage

if __name__ == "__main__":
    args = Args()

    config_path_rel = args.get(0)

    config = yaml.load(open(config_path_rel))

    c_files = config['files']
    c_feature_detection = config['feature_detection']
    c_stitching = config['stitching']

    config_dir = os.path.dirname(os.path.realpath(config_path_rel))

    establishing = spimage.Image.from_file(os.path.join(config_dir, c_files['establishing']))
    # TODO: allow arrays of images rather than just globs
    closes = map(spimage.Image.from_file, glob.glob(os.path.join(config_dir, c_files['closes'])))

    output_dir = os.path.join(
        config_dir,
        os.path.basename(config_path_rel).replace('.', '_') + '_out')
    if not os.path.exists(output_dir):
Пример #5
0
def main():
    args = Args()

    puts(colored.yellow('Aruments passed in: ') + str(args.all))
    puts(colored.yellow('Flags detected: ') + str(args.flags))
    arg_cmd = args.get(0)
    puts(colored.cyan('Command: ') + str(arg_cmd))

    if arg_cmd == 'start':
        start_ec2()
    elif arg_cmd == 'stop':
        stop_ec2()
    elif arg_cmd == 'ssh':
        ssh_login()
    elif arg_cmd == 'launch':
        ssh_launch()
    elif arg_cmd == 'scp':
        scp()
    elif arg_cmd == 'attach-volume':
        attach_volume()
    elif arg_cmd == 'detach-volume':
        detach_volume()
    elif arg_cmd == 'create-stack':
        arg1 = args.get(1)
        if arg1:
            stack_name = args.get(1)
            stack_exists = validate_stack_exists(stack_name)
        else:
            stack_name = prompt.query("What's the name of your stack?")
            stack_exists = validate_stack_exists(stack_name)

        if (stack_exists):
            puts(colored.red(f'Stack named {stack_name} already exists'))
        else:
            create_stack(stack_name)

    elif arg_cmd == 'update-stack':
        arg1 = args.get(1)
        if arg1:
            stack_name = args.get(1)
            stack_exists = validate_stack_exists(stack_name)
        else:
            stack_name = choose_stack()
            stack_exists = True

        if not stack_exists:
            puts(colored.red(f'Stack named {stack_name} does not exist'))
        else:
            update_stack(stack_name)

    elif arg_cmd == 'check-status':
        list_all_ec2()
    elif arg_cmd == 'create-ecr':
        # Should this be part of the stack?
        create_ecr_registry()
    elif arg_cmd == 'attach-volume':
        attach_volume()
    elif arg_cmd == 'choose-stack':
        choose_stack()
    elif arg_cmd == 'list-keypairs':
        list_keypairs()
    elif arg_cmd == 'upload-keys':
        upload_keys()
    elif arg_cmd == 'delete-stack':
        arg1 = args.get(1)
        if arg1:
            stack_name = args.get(1)
            stack_exists = validate_stack_exists(stack_name)
        else:
            stack_name = choose_stack()
            stack_exists = True

        if stack_exists:
            delete_stack(stack_name)
        else:
            puts(colored.red(f'Stack {stack_name} does not exist'))