コード例 #1
0
def extract(target_path, creds=None):
    """
    unzipps or untars a files or multiple files under a directory
        either locally or on a remote host
    @target_path: string - directory or file path
    @creds: a dictionary or Bunch object used for remote execution
    """
    if not executor.path_exists(target_path, creds):
        logging.warn("Invalid path: %s" % target_path)
        return

    cmds = []
    if executor.is_file(target_path, creds):
        target_dir = os.path.dirname(target_path)
        filename = os.path.basename(target_path)
        cmd = get_unzip_cmd(filename)
        if cmd is not None:
            cmds.append("cd {}; {} {}".format(target_dir, get_unzip_cmd(filename), filename))

    else:  # directory
        files = executor.find_files(target_path, creds, include=["*.gz", "*.zip"])
        for path in files:
            target_dir = os.path.dirname(path)
            filename = os.path.basename(path)
            unzip_cmd = get_unzip_cmd(filename)
            if unzip_cmd is not None:
                cmds.append("cd {}; {} {}".format(target_dir, unzip_cmd, filename))

    executor.run(cmds, creds)
コード例 #2
0
def extract(target_path, creds=None):
    """
    unzipps or untars a files or multiple files under a directory
        either locally or on a remote host
    @target_path: string - directory or file path
    @creds: a dictionary or Bunch object used for remote execution
    """
    if not executor.path_exists(target_path, creds):
        logging.warn('Invalid path: %s' % target_path)
        return

    cmds = []
    if executor.is_file(target_path, creds):
        target_dir = os.path.dirname(target_path)
        filename = os.path.basename(target_path)
        cmd = get_unzip_cmd(filename)
        if cmd is not None:
            cmds.append('cd {}; {} {}'\
                        .format(target_dir,\
                                get_unzip_cmd(filename),\
                                filename))

    else: # directory
        files = executor.find_files(target_path, creds, include=['*.gz', '*.zip'])
        for path in files:
            target_dir = os.path.dirname(path)
            filename = os.path.basename(path)
            unzip_cmd = get_unzip_cmd(filename)
            if unzip_cmd is not None:
                cmds.append('cd {}; {} {}'\
                    .format(target_dir, unzip_cmd, filename))

    executor.run(cmds, creds)
コード例 #3
0
ファイル: test.py プロジェクト: kouroshparsa/parallel_sync
 def test_run(self):
     path = "/tmp"
     output = executor.run("pwd", creds=TEST_DATA.creds, curr_dir=path).strip()
     assert output == path, "run command returned: {} but expected {}.".format(output, path)
コード例 #4
0
ファイル: test.py プロジェクト: thanakijwanavit/parallel_sync
 def test_run(self):
     path = '/tmp'
     output = executor.run('pwd', creds=TEST_DATA.creds,
                           curr_dir=path).strip()
     assert output == path,\
         "run command returned: {} but expected {}.".format(output, path)