Exemplo n.º 1
0
Arquivo: task.py Projeto: Oblong/obi
def launch_task(debugger, extras):
    """
    Handles launching the application in obi go
    """

    target = ""
    # Did the user specify a target?
    config_target = env.config.get("target", None)
    if config_target:
        target = os.path.join(env.project_dir, config_target)
    # TODO(jshrake): Consider nesting these conditionals
    # Look for a binary with name env.target_name in the build directory
    if not env.file_exists(target):
        target = os.path.join(env.build_dir, env.target_name)
    # Look for a binary with name env.target_name in the binary directory
    if not env.file_exists(target):
        target = os.path.join(env.project_dir, "bin", env.target_name)
    # Just give up -- can't find the target name
    if not env.file_exists(target):
        abort("Cannot find target binary to launch. Please specify the relative path to the binary via the target key")

    launch_args = env.config.get("launch-args", [])

    formatted_launch = "{0} {1} {2}".format(
        env.relpath(target), # {0}
        " ".join(extras), # {1}
        " ".join(launch_args) # {2}
    )

    env_vars = env.config.get("env-vars", {})
    env_vars = " ".join(["{0}={1}".format(key, val) for key, val in env_vars.items()])

    with env.cd(env.project_dir):
        # Process pre-launch commands
        for cmd in env.config.get("pre-launch-cmds", []):
            env.run(cmd)
        if debugger:
            debug_cmd = debugger
            debuggers = env.config.get("debuggers", None)
            if debuggers:
                debug_cmd = debuggers.get(debugger, debug_cmd)
            default_launch = env.debug_launch_format_str.format(env_vars, debug_cmd, formatted_launch)
            launch_cmd = env.config.get("debug-launch-cmd", default_launch)
            env.background_run(launch_cmd)
        else:
            log_file = env.relpath(os.path.join(env.project_dir, env.target_name + ".log"))
            default_launch = env.launch_format_str.format(env_vars, formatted_launch, log_file)
            launch_cmd = env.config.get("launch-cmd", default_launch)
            env.background_run(launch_cmd)
        # Process the post-launch commands
        for cmd in env.config.get("post-launch-cmds", []):
            env.run(cmd)
Exemplo n.º 2
0
def launch_task(debugger, extras):
    """
    Handles launching the application in obi go
    """

    target = find_launch_target()

    launch_args = env.config.get("launch-args", [])

    formatted_launch = "{0} {1} {2}".format(
        target,  # {0}
        " ".join(extras),  # {1}
        " ".join(launch_args)  # {2}
    )

    env_vars = env.config.get("env-vars", {})
    env_vars = " ".join(
        ["{0}={1}".format(key, val) for key, val in env_vars.items()])

    with env.cd(env.project_dir):
        # Process pre-launch commands
        for cmd in env.config.get("pre-launch-cmds", []):
            env.run(cmd)
        if debugger:
            debug_cmd = debugger
            debuggers = env.config.get("debuggers", None)
            if debuggers:
                debug_cmd = debuggers.get(debugger, debug_cmd)
            default_launch = env.debug_launch_format_str.format(
                env_vars, debug_cmd, formatted_launch)
            launch_cmd = env.config.get("debug-launch-cmd", default_launch)
            env.background_run(launch_cmd)
        else:
            log_file = env.relpath(
                os.path.join(env.project_dir, env.target_name + ".log"))
            default_launch = env.launch_format_str.format(
                env_vars, formatted_launch, log_file)
            launch_cmd = env.config.get("launch-cmd", default_launch)
            env.background_run(launch_cmd)
        # Process the post-launch commands
        for cmd in env.config.get("post-launch-cmds", []):
            env.run(cmd)
Exemplo n.º 3
0
def room_task(room_name, task_name=None):
    """
    Configures the fabric globabl env variable for other tasks
    """
    # Load the project.yaml file so we can extract configuration for the given room_name
    project_config = project_yaml()
    config = load_project_config(project_config)

    # Abort if no project name found
    project_name = config.get("name", None)
    if not project_name:
        abort(
            "No name key found in the project.yaml. Please specify a project name"
        )
    env.project_name = project_name
    env.local_project_dir = os.path.dirname(project_config)
    # Abort if we cannot find room_name in rooms
    rooms = config.get("rooms", {})
    room = rooms.get(room_name, None)
    if not room:
        abort("""{0} is not a room name listed in project.yaml\n
              Available room names: {1}""".format(room_name, rooms.keys()))

    # Extract the top-level config sans the rooms config
    config_no_rooms = config.copy()
    config_no_rooms.pop("rooms", None)
    # Merge the config of our room into the top-level
    env.config = config_no_rooms
    env.config.update(room)

    # Calling basename on project_name should be harmless
    # In the case that the user specified target, say, build/foo,
    # then basename gives us foo
    env.target_name = os.path.basename(
        env.config.get("target", env.project_name))

    # Running locally if:
    # - User specified is-local: True
    # - Room name is localhost
    # - Hosts is empty
    if room.get("is-local", room_name == "localhost"
                or not room.get("hosts", [])):
        env.hosts = ['localhost']
        env.use_ssh_config = False
        env.project_dir = env.local_project_dir
        env.file_exists = os.path.exists
        env.rsync = lambda: None  # Don't rsync when running locally -- noop
        env.cd = fabric.context_managers.lcd
        # Generate a shell script that duplicates the task
        task_name = task_name or env.tasks[-1]
        env.run = local
        env.background_run = env.run
        env.relpath = os.path.relpath
        env.launch_format_str = "{0} {1}"
        env.debug_launch_format_str = "{0} {1} {2}"
    else:
        env.user = room.get("user", env.local_user)  # needed for remote run
        env.hosts = room.get("hosts", [])
        env.use_ssh_config = True
        # Default remote project dir is /tmp/localusername/projectname
        env.project_dir = room.get("project-dir",
                                   default_remote_project_folder())
        env.run = run
        env.background_run = lambda cmd: env.run(cmd, pty=False)
        env.file_exists = fabric.contrib.files.exists
        env.rsync = rsync_task
        env.cd = fabric.context_managers.cd
        env.relpath = lambda p: p
        env.launch_format_str = "sh -c '(({0} nohup {1} > {2} 2> {2}) &)'"
        env.debug_launch_format_str = "tmux new -d -s {0} '{1}'".format(
            env.target_name, "{0} {1} {2}")
    env.build_dir = os.path.abspath(
        env.relpath(
            os.path.join(env.project_dir, env.config.get("build-dir",
                                                         "build"))))
Exemplo n.º 4
0
Arquivo: task.py Projeto: Oblong/obi
def room_task(room_name, task_name=None):
    """
    Configures the fabric globabl env variable for other tasks
    """
    # Load the project.yaml file so we can extract configuration for the given room_name
    project_config = project_yaml()
    config = load_project_config(project_config)

    # Abort if no project name found
    project_name = config.get("name", None)
    if not project_name:
        abort("No name key found in the project.yaml. Please specify a project name")
    env.project_name = project_name
    env.local_project_dir = os.path.dirname(project_config)
    # Abort if we cannot find room_name in rooms
    rooms = config.get("rooms", {})
    room = rooms.get(room_name, None)
    if not room:
        abort("""{0} is not a room name listed in project.yaml\n
              Available room names: {1}""".format(room_name, rooms.keys()))

    # Extract the top-level config sans the rooms config
    config_no_rooms = config.copy()
    config_no_rooms.pop("rooms", None)
    # Merge the config of our room into the top-level
    env.config = config_no_rooms
    env.config.update(room)

    # Calling basename on project_name should be harmless
    # In the case that the user specified target, say, build/foo,
    # then basename gives us foo
    env.target_name = os.path.basename(
        env.config.get("target", env.project_name))

    # Running locally if:
    # - User specified is-local: True
    # - Room name is localhost
    # - Hosts is empty
    if room.get("is-local", room_name == "localhost" or not room.get("hosts", [])):
        env.hosts = ['localhost']
        env.use_ssh_config = False
        env.project_dir = os.path.dirname(project_config)
        env.file_exists = os.path.exists
        env.rsync = lambda: None # Don't rsync when running locally -- noop
        env.cd = fabric.context_managers.lcd
        # Generate a shell script that duplicates the task
        task_name = task_name or env.tasks[-1]
        env.run = local
        env.background_run = env.run
        env.relpath = os.path.relpath
        env.launch_format_str = "{0} {1}"
        env.debug_launch_format_str = "{0} {1} {2}"
    else:
        env.user = room.get("user", env.local_user) # needed for remote run
        env.hosts = room.get("hosts", [])
        env.use_ssh_config = True
        # Default remote project dir is /tmp/localusername/projectname
        env.project_dir = room.get("project-dir",
                                   os.path.join(os.path.sep,
                                                "tmp",
                                                env.local_user,
                                                project_name))
        env.run = run
        env.background_run = lambda cmd: env.run(cmd, pty=False)
        env.file_exists = fabric.contrib.files.exists
        env.rsync = rsync_task
        env.cd = fabric.context_managers.cd
        env.relpath = lambda p: p
        env.launch_format_str = "sh -c '(({0} nohup {1} > {2} 2> {2}) &)'"
        env.debug_launch_format_str = "tmux new -d -s {0} '{1}'".format(env.target_name, "{0} {1} {2}")
    env.build_dir = env.relpath(
        os.path.join(env.project_dir,
                     env.config.get("build-dir", "build")))