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)
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)
def test_make_dir_local(self): TEST_DIR = "/tmp/some_dir_123/1234" if executor.path_exists(TEST_DIR): executor.delete_dir(TEST_DIR) executor.make_dirs(TEST_DIR) assert os.path.exists(TEST_DIR), "Failed tp create directory {}".format(TEST_DIR) shutil.rmtree("/tmp/some_dir_123")
def test_make_dir_local(self): TEST_DIR = '/tmp/some_dir_123/1234' if executor.path_exists(TEST_DIR): executor.delete_dir(TEST_DIR) executor.make_dirs(TEST_DIR) assert os.path.exists(TEST_DIR),\ 'Failed tp create directory {}'.format(TEST_DIR) shutil.rmtree('/tmp/some_dir_123')