Beispiel #1
0
    def process(self):
        code = 1
        path = "None"
        os.system("rm -rf %s/*" % tmp_path)
        BOOL = get_data_from_gz(self.source, self.target)
        if BOOL is True:
            command = command_define_path + str(self.config["cmd-link"])
            explain = self.config["explain"]
            cmd = explain + " " + command + " " + os.path.join(self.target, self.name + ".csv")
            code = shell(cmd)
            if code == 0:
                path = self.backUp()

        return code, path
Beispiel #2
0
def get_data_from_gz(source_path, target_path):
    name = str(source_path).replace(".gz", "")
    rename = str(name) + ".csv"  # 更改后名称,以csv结尾
    if main_config_read.get("backup-data", False) is True:  # 是否备份数据,在主配置文件中配置
        create_folder(backup_path)
        current_time = time.strftime("_%Y_%m_%d_%H_%M_%S")
        target = os.path.join(backup_path, os.path.basename(name) + str(current_time) + ".gz")
        shutil.copy(source_path, target)
    code = shell("gzip -d %s" % source_path)  # 调用shell命令gzip用于解压gz文件
    if code == 0:
        os.rename(name, rename)
        shutil.copy(rename, target_path)
        os.remove(rename)  # 删除原文件
        return True
    else:
        return False