Exemplo n.º 1
0
 def exists(self, path):
     cmd = load_hadoop_cmd() + ['fs', '-test', '-e', path]
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
     stdout, stderr = p.communicate()
     if p.returncode == 0:
         return True
     elif p.returncode == 1:
         return False
     else:
         raise hdfs_error.HDFSCliError(cmd, p.returncode, stdout, stderr)
Exemplo n.º 2
0
 def call_check(command):
     p = subprocess.Popen(command,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          close_fds=True,
                          universal_newlines=True)
     stdout, stderr = p.communicate()
     if p.returncode != 0:
         raise hdfs_error.HDFSCliError(command, p.returncode, stdout,
                                       stderr)
     return stdout
Exemplo n.º 3
0
    def exists(self, path):
        """
        Use snakebite.test to check file existence.

        :param path: path to test
        :type path: string
        :return: boolean, True if path exists in HDFS
        """
        try:
            return self.get_bite().test(path, exists=True)
        except Exception as err:  # IGNORE:broad-except
            raise hdfs_error.HDFSCliError("snakebite.test", -1, str(err),
                                          repr(err))
Exemplo n.º 4
0
    def exists(self, path):
        """
        Use ``hadoop fs -stat`` to check file existence.
        """

        cmd = load_hadoop_cmd() + ['fs', '-stat', path]
        logger.debug('Running file existence check: %s', subprocess.list2cmdline(cmd))
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, universal_newlines=True)
        stdout, stderr = p.communicate()
        if p.returncode == 0:
            return True
        else:
            not_found_pattern = "^.*No such file or directory$"
            not_found_re = re.compile(not_found_pattern)
            for line in stderr.split('\n'):
                if not_found_re.match(line):
                    return False
            raise hdfs_error.HDFSCliError(cmd, p.returncode, stdout, stderr)