コード例 #1
0
ファイル: pull_artifact.py プロジェクト: indigo-dc/oneclient
def download_artifact_safe(ssh, plan, branch, exception_handler=None, 
                           exception_handler_args=(), exception_log=""):
    """
    Downloads artifact from repo. Locks file while it's being downloaded.
    If exception is thrown during download, exception_log is printed and
    exception_handler function is called.
    :param ssh: sshclient with opened connection
    :type ssh: paramiko.SSHClient
    :param plan: name of current bamboo plan
    :type plan: str
    :param branch: name of current git branch
    :type branch: str
    :param exception_handler: function called when exception is thrown while
    artifact is being downloaded
    :type exception_handler: function
    :param exception_handler_args: args for exception_handler
    :type exception_handler_args: tuple
    :param exception_log: log that is printed when exception is thrown while
    artifact is being downloaded
    :type exception_log: str
    :return None
    """
    file_name = artifact_path(plan, branch)
    lock_file(ssh, file_name)
    try:
        download_artifact(ssh, plan, branch)
    except SCPException:
        print exception_log
        if exception_handler:
            exception_handler(*exception_handler_args)
    finally:
        unlock_file(ssh, file_name)
コード例 #2
0
ファイル: push_artifact.py プロジェクト: onedata/web-client
def upload_artifact_safe(ssh, artifact, plan, branch):

    file_name = artifact_path(plan, branch)
    partial_file_name = file_name + PARTIAL_EXT
    lock_file(ssh, partial_file_name)
    try:
        upload_artifact(ssh, artifact, plan, branch)
        rename_uploaded_file(ssh, file_name)
    except:
        print "Uploading artifact of plan {0}, on branch {1} failed".format(plan, branch)
        ssh.exec_command("rm -rf {}".format(partial_file_name))
    finally:
        unlock_file(ssh, partial_file_name)
コード例 #3
0
def upload_artifact_safe(ssh, artifact, plan, branch):

    file_name = artifact_path(plan, branch)
    partial_file_name = file_name + PARTIAL_EXT
    lock_file(ssh, partial_file_name)
    try:
        upload_artifact(ssh, artifact, plan, branch)
        rename_uploaded_file(ssh, file_name)
    except:
        print "Uploading artifact of plan {0}, on branch {1} failed" \
            .format(plan, branch)
        ssh.exec_command("rm -rf {}".format(partial_file_name))
    finally:
        unlock_file(ssh, partial_file_name)
コード例 #4
0
def download_artifact_safe(ssh,
                           plan,
                           branch,
                           exception_handler=None,
                           exception_handler_args=(),
                           exception_log=""):
    """
    Downloads artifact from repo. Locks file while it's being downloaded.
    If exception is thrown during download, exception_log is printed and
    exception_handler function is called.
    :param ssh: sshclient with opened connection
    :type ssh: paramiko.SSHClient
    :param plan: name of current bamboo plan
    :type plan: str
    :param branch: name of current git branch
    :type branch: str
    :param exception_handler: function called when exception is thrown while
    artifact is being downloaded
    :type exception_handler: function
    :param exception_handler_args: args for exception_handler
    :type exception_handler_args: tuple
    :param exception_log: log that is printed when exception is thrown while
    artifact is being downloaded
    :type exception_log: str
    :return None
    """
    file_name = artifact_path(plan, branch)

    def signal_handler(_signum, _frame):
        ssh.connect(args.hostname, port=args.port, username=args.username)
        unlock_file(ssh, file_name)
        sys.exit(1)

    signal.signal(signal.SIGINT, signal_handler)

    lock_file(ssh, file_name)
    try:
        download_artifact(ssh, plan, branch)
    except:
        print exception_log
        if exception_handler:
            exception_handler(*exception_handler_args)
    finally:
        unlock_file(ssh, file_name)
コード例 #5
0
ファイル: push_artifact.py プロジェクト: indigo-dc/oneclient
def upload_artifact_safe(ssh, artifact, plan, branch):

    file_name = artifact_path(plan, branch)
    partial_file_name = file_name + PARTIAL_EXT

    def signal_handler(_signum, _frame):
        ssh.connect(args.hostname, port=args.port, username=args.username)
        unlock_file(ssh, partial_file_name)
        delete_file(ssh, partial_file_name)
        unlock_file(ssh, file_name)
        sys.exit(1)
    signal.signal(signal.SIGINT, signal_handler)

    lock_file(ssh, partial_file_name)
    try:
        upload_artifact(ssh, artifact, plan, branch)
        rename_uploaded_file(ssh, file_name)
    except:
        print "Uploading artifact of plan {0}, on branch {1} failed" \
            .format(plan, branch)
        delete_file(ssh, partial_file_name)
    finally:
        unlock_file(ssh, partial_file_name)
コード例 #6
0
def upload_artifact_safe(ssh, artifact, plan, branch):

    file_name = artifact_path(plan, branch)
    partial_file_name = file_name + PARTIAL_EXT

    def signal_handler(_signum, _frame):
        ssh.connect(args.hostname, port=args.port, username=args.username)
        unlock_file(ssh, partial_file_name)
        delete_file(ssh, partial_file_name)
        unlock_file(ssh, file_name)
        sys.exit(1)

    signal.signal(signal.SIGINT, signal_handler)

    lock_file(ssh, partial_file_name)
    try:
        upload_artifact(ssh, artifact, plan, branch)
        rename_uploaded_file(ssh, file_name)
    except:
        print "Uploading artifact of plan {0}, on branch {1} failed" \
            .format(plan, branch)
        delete_file(ssh, partial_file_name)
    finally:
        unlock_file(ssh, partial_file_name)
コード例 #7
0
def rename_uploaded_file(ssh, file_name):
    lock_file(ssh, file_name)
    ssh.exec_command("mv {0}{1} {0}".format(file_name, PARTIAL_EXT))
    unlock_file(ssh, file_name)
コード例 #8
0
ファイル: push_artifact.py プロジェクト: indigo-dc/oneclient
def rename_uploaded_file(ssh, file_name):
    lock_file(ssh, file_name)
    ssh.exec_command("mv {0}{1} {0}".format(file_name, PARTIAL_EXT))
    unlock_file(ssh, file_name)
コード例 #9
0
ファイル: push_artifact.py プロジェクト: indigo-dc/oneclient
 def signal_handler(_signum, _frame):
     ssh.connect(args.hostname, port=args.port, username=args.username)
     unlock_file(ssh, partial_file_name)
     delete_file(ssh, partial_file_name)
     unlock_file(ssh, file_name)
     sys.exit(1)
コード例 #10
0
 def signal_handler(_signum, _frame):
     ssh.connect(args.hostname, port=args.port, username=args.username)
     unlock_file(ssh, partial_file_name)
     delete_file(ssh, partial_file_name)
     unlock_file(ssh, file_name)
     sys.exit(1)