Exemple #1
0
    def test_02(self):
        logger = FoxylibLogger.func_level2logger(self.test_02, logging.DEBUG)

        web_client = FoxylibSlack.web_client()
        channel = FoxylibChannel.V.FOXYLIB
        filepath = os.path.join(FILE_DIR, "test_01.txt")
        response = FilesUploadMethod.invoke(web_client, channel, filepath)
        self.assertTrue(SlackResponseTool.response2is_ok(response))

        j_response = SlackResponseTool.response2j_resopnse(response)
        j_file = FilesUploadMethod.j_response2j_file(j_response)
        logger.debug(json.dumps({"j_file":j_file}, indent=2))
        self.assertEqual(SlackFile.j_file2mimetype(j_file), MimetypeTool.V.TEXT_PLAIN)

        # download
        url_private = SlackFile.j_file2url_private(j_file)
        self.assertEqual(MimetypeTool.url2mimetype(url_private), MimetypeTool.V.TEXT_PLAIN)

        token = FoxylibSlack.xoxp_token()
        logger.debug({"url_private":url_private,
                      "token":token,
                      })
        utf8 = SlackTool.fileurl_token2utf8(url_private, token)
        logger.debug({"utf8": utf8})
        # FileTool.utf82file(utf8, "/tmp/t.html")
        self.assertEqual(utf8, FileTool.filepath2utf8(filepath))

        # cleanup
        file_id = SlackFile.j_file2id(j_file)
        web_client.files_delete(**{"file":file_id})
Exemple #2
0
    def filepath2j(cls, filepath):
        logger = FoxylibLogger.func2logger(cls.filepath2j)

        utf8 = FileTool.filepath2utf8(filepath)
        # logger.info({"utf8": utf8})

        j = yaml.load(utf8)
        return j
Exemple #3
0
    def filepath2j(cls, filepath):
        logger = FoxylibLogger.func_level2logger(cls.filepath2j, logging.DEBUG)

        from foxylib.tools.file.file_tool import FileTool
        utf8 = FileTool.filepath2utf8(filepath)
        if not utf8: return None

        j = json.loads(utf8)
        return j
Exemple #4
0
    def test_02(self):
        cls = self.__class__

        filepath_hwp = os.path.join(FILE_DIR, "hwp샘플.hwp")
        filepath_text = "/tmp/t.txt"
        HWPTool.filepath2textfile(filepath_hwp, filepath_text)

        hyp = FileTool.filepath2utf8(filepath_text)
        self.assertEqual(hyp, cls.ref())
Exemple #5
0
def yaml_envname2kv_list(filepath_yaml, envname):
    yaml_str = FileTool.filepath2utf8(filepath_yaml)
    kv_list = EnvTool.yaml_str2kv_list(yaml_str, [envname, '_DEFAULT_'])

    logger.info({
        "kv_list": kv_list,
        "filepath_yaml": filepath_yaml,
    })

    s_env = "\n".join(["{0}={1}".format(k, v_yaml) for k, v_yaml in kv_list])
    return s_env
Exemple #6
0
    def f_or_file2utf8(cls, f, filepath):
        logger = FoxylibLogger.func2logger(cls.f_or_file2utf8)
        # logger.debug({"filepath": filepath, "f": f})

        FileTool.dirpath2mkdirs(os.path.dirname(filepath))

        utf8 = FileTool.filepath2utf8(filepath)

        if utf8:
            return utf8

        utf8 = f()
        if utf8 is not None:
            FileTool.utf82file(utf8, filepath)
        return utf8
Exemple #7
0
 def template(cls):
     filepath = os.path.join(FILE_DIR, "henrique.supervisord.conf.tmplt")
     utf8 = FileTool.filepath2utf8(filepath)
     template = Jinja2Renderer.env_text2template(None, utf8)
     return template
Exemple #8
0
 def filepath2utf8(cls, textfile):
     return FileTool.filepath2utf8(textfile)
Exemple #9
0
 def htmlfile2markup(cls, htmlfile, data=None, env=None):
     text = FileTool.filepath2utf8(htmlfile)
     return cls.markup2markup(Markup(text), data=data, env=env)
Exemple #10
0
    def textfile2text(cls, textfile, data=None, env=None):
        text = FileTool.filepath2utf8(textfile)
        if text is None:
            return None

        return cls.text2text(text, data=data, env=env)
Exemple #11
0
 def lang2str(cls, lang):
     filepath = os.path.join(FILE_DIR,"{}.txt".format(lang))
     s = FileTool.filepath2utf8(filepath)
     return s
Exemple #12
0
 def tmplt_file2html(cls, filepath, data=None, autoescape=None):
     str_tmplt = FileTool.filepath2utf8(filepath)
     return cls.tmplt_str2html(str_tmplt, data=data, autoescape=autoescape)
Exemple #13
0
 def tmplt_file2str(cls, filepath, data=None, autoescape=None):
     logger = FoxylibLogger.func_level2logger(cls.tmplt_file2str,
                                              logging.DEBUG)
     str_tmplt = FileTool.filepath2utf8(filepath)
     # logger.debug({"filepath":filepath,"str_tmplt": str_tmplt})
     return cls.tmplt_str2str(str_tmplt, data=data, autoescape=autoescape)
Exemple #14
0
 def yaml(cls):
     filepath = os.path.join(FILE_DIR, "{0}.yaml".format(ClassTool.cls2name(cls)))
     utf8 = FileTool.filepath2utf8(filepath)
     j_yaml = yaml.load(utf8, yaml.SafeLoader)
     return j_yaml
Exemple #15
0
 def filepath2xml(cls, filepath):
     utf8 = FileTool.filepath2utf8(filepath)
     return cls.utf82xml(utf8)