'Return the job deployment directory in HDFS, creating it if necessary.
The actual deployment dir should be 0711 owned by the user'

def _create_deployment_dir(self):

    create_directories(self.fs)
    has_deployment_dir_access = False
    if (self.job.deployment_dir and self.fs.exists(self.job.deployment_dir)):
        statbuf = self.fs.stats(self.job.deployment_dir)
        has_deployment_dir_access = (statbuf and (statbuf.user == self.user.username))
    if ((self.job.document and (self.user != self.job.document.owner)) or (not has_deployment_dir_access)):
        path = REMOTE_DEPLOYMENT_DIR.get().replace('$USER', self.user.username).replace('$TIME', str(time.time())).replace('$JOBID', str(self.job.id))
        if self.fs.exists(self.job.deployment_dir):
            self.fs.copy_remote_dir(self.job.deployment_dir, path, owner=self.user)
        else:
            self._create_dir(path)
    else:
        path = self.job.deployment_dir
        self._create_dir(path)
    return path
