Python 创建HDFS文件夹

直接上代码

#! /usr/bin/python2.7
# -*- coding: utf8 -*-
import os
import sys

reload(sys)
sys.setdefaultencoding("utf-8")
sys.path.append("../")
import datetime
from utils import confUtils


def hadoop_make_dir(hadoop_path, auth, src_path):
    cmd = '%s dfs %s -mkdir -p %s' % (hadoop_path, auth, src_path)
    print(cmd)
    return os.system(cmd)


class HDFSTask(object):
    cf = confUtils.getConfig("../conf/hadoop.conf")

    def __init__(self):
        self.hadoop_path = confUtils.getFilePath(self.cf, "SIM_USERS", "HADOOP_BIN_DIR")
        self.auth = confUtils.getFilePath(self.cf, "SIM_USERS", "AUTH")
        self.out_path = confUtils.getFilePath(self.cf, "SIM_USERS", "OUT_DIR")

    def run(self):
        tomorrow = datetime.datetime.now().strftime('%Y%m%d')
        dir_path = self.out_path + "/" + tomorrow
        hadoop_make_dir(self.hadoop_path, self.auth, dir_path)
        print("mkdir success")


if __name__ == '__main__':
    main_task = HDFSTask()
    try:
        main_task.run()
    except Exception as err:
        print(str(err))

猜你喜欢

转载自blog.csdn.net/jxq0816/article/details/81343780