Example #1
0
 def env2compile(cls, env):
     h = cls.env2dict(env)
     lines = ["{}={}".format(k, v) for k, v in h.items()]
     filepath = os.path.join(REPO_DIR, "henrique", "env", "docker",
                             "env.{}.list".format(env))
     FileTool.makedirs_or_skip(os.path.dirname(filepath))
     FileTool.utf82file("\n".join(lines), filepath)
Example #2
0
    def env2compile(cls, env):
        logger = HenriqueLogger.func_level2logger(cls.env2compile,
                                                  logging.DEBUG)
        logger.debug({"env": env})

        uwsgi_mode = HenriqueUwsgi.env2mode(env)

        nginx_mode = HenriqueNginx.env2mode(env)
        uid = HenriqueNginx.Mode.mode2user(nginx_mode)
        gid = HenriqueNginx.Mode.mode2group(nginx_mode)

        data = {
            "env": env,
            "uid": uid,
            "gid": gid,
            "uwsgi_mode": uwsgi_mode,
        }

        filepath = os.path.join(FILE_DIR, "conf",
                                "henrique.supervisord.{}.conf".format(env))
        utf8 = Jinja2Renderer.template2text(cls.template(), data=data)
        FileTool.utf82file(utf8, filepath)

        logger.debug({
            "filepath": filepath,
            "data": data,
        })
Example #3
0
    def mode2compile(cls, mode):
        data = {
            "mode": mode,
        }

        filepath = os.path.join(FILE_DIR, "ini",
                                "henrique.uwsgi.{}.ini".format(mode))
        utf8 = Jinja2Renderer.template2text(cls.template(), data=data)
        FileTool.utf82file(utf8, filepath)
Example #4
0
def main():
    logging.basicConfig(level=logging.INFO)
    envname = os.environ.get("ENV")

    filepath_yaml = os.path.join(REPO_DIR, "config.yaml")
    filepath_dotenv = os.path.join(REPO_DIR, ".envrc")

    s_env = yaml_envname2kv_list(filepath_yaml, envname)

    FileTool.utf82file(s_env, filepath_dotenv)
Example #5
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
Example #6
0
    def attach_filepath2rootname_list(
        cls,
        rootname_list,
        filepath,
        level,
    ):
        from foxylib.tools.file.file_tool import FileTool
        FileTool.dirpath2mkdirs(os.path.dirname(filepath))

        handler = LoggerTool.handler2formatted(
            LoggerTool.filepath2handler_default(filepath))
        handler.setLevel(level)
        cls.attach_handler2rootname_list(
            rootname_list,
            handler,
        )
Example #7
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})
Example #8
0
    def filepath2j(cls, filepath):
        logger = FoxylibLogger.func2logger(cls.filepath2j)

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

        j = yaml.load(utf8)
        return j
Example #9
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
Example #10
0
    def attach_filepath2rootname_list(
        cls,
        rootname_list,
        filepath,
        level,
    ):
        from foxylib.tools.file.file_tool import FileTool
        FileTool.makedirs_or_skip(os.path.dirname(filepath))

        handler = LoggerTool.handler_formatter2formatted(
            LoggerTool.filepath2handler_default(filepath),
            FoxylibLogFormatter.formatter(),
        )
        handler.setLevel(level)
        cls.attach_handler2rootname_list(
            rootname_list,
            handler,
        )
Example #11
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())
Example #12
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
Example #13
0
    def env2compile(cls, env):
        domain_name = cls.env2domain_name(env)

        mode = cls.env2mode(env)
        nginx_dir = cls.Mode.mode2nginx_dir(mode)
        socket = cls.Mode.mode2socket(mode)
        uid = cls.Mode.mode2user(mode)
        gid = cls.Mode.mode2group(mode)

        data = {"DOMAIN_NAME": domain_name,
                "NGINX_DIR": nginx_dir,
                "socket": socket,
                "uid": uid,
                "gid": gid,
                "FILEPATH_SSL_CERTI": None,
                "FILEPATH_SSL_PRIVATE_KEY": None,
                }

        filepath = os.path.join(FILE_DIR, "conf","henrique.nginx.{}.conf".format(env))
        utf8 = Jinja2Renderer.template2text(cls.template(), data=data)
        FileTool.utf82file(utf8, filepath)
Example #14
0
    def filepath2read(cls, filepath):
        logger = FoxylibLogger.func_level2logger(cls.filepath2read,
                                                 logging.DEBUG)
        logger.debug({"filepath": filepath})

        if not os.path.exists(filepath):
            return None

        bytes = FileTool.filepath2bytes(filepath)
        # logger.debug({"bytes":bytes})
        obj = pickle.loads(bytes)
        return obj
Example #15
0
    def invoke(cls, web_client, channel, filepath):
        mimetype = FileTool.filepath2mimetype(filepath)
        filetype = SlackFiletype.mimetype2filetype(mimetype)

        j_files_upload_in = {
            "channels": channel,
            "file": filepath,
            "filename": os.path.basename(filepath),
            "filetype": filetype,
        }

        response = web_client.files_upload(**j_files_upload_in)
        return response
Example #16
0
    def test_03(self):
        logger = FoxylibLogger.func_level2logger(self.test_02, logging.DEBUG)
        cls = self.__class__

        filepath_hwp = os.path.join(FILE_DIR, "hwp샘플.hwp")
        bytes = FileTool.filepath2bytes(filepath_hwp)

        with NamedTemporaryFile() as f:
            f.write(bytes)
            hyp = HWPTool.filepath2text(f.name,)

        logger.debug({"hyp":hyp})
        self.assertEqual(hyp, cls.ref())
Example #17
0
 def fileurl_token2file(cls, url, xoxp_token, filepath,):
     bytes = cls.fileurl_token2bytes(url, xoxp_token)
     FileTool.bytes2file(bytes, filepath)
Example #18
0
    def test_01(self):
        filepath = os.path.join(os.path.dirname(FILE_DIR), "file_tool.py")
        hyp = FileTool.filepath2mimetype(filepath)

        self.assertEqual(hyp, MimetypeTool.V.TEXT_XPYTHON)
Example #19
0
 def filepath2utf8(cls, textfile):
     return FileTool.filepath2utf8(textfile)
Example #20
0
 def htmlfile2markup(cls, htmlfile, data=None, env=None):
     text = FileTool.filepath2utf8(htmlfile)
     return cls.markup2markup(Markup(text), data=data, env=env)
Example #21
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)
Example #22
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
Example #23
0
 def obj_filepath2write(cls, obj, filepath):
     bytes = pickle.dumps(obj)
     FileTool.bytes2file(bytes, filepath)
Example #24
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)
Example #25
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)
Example #26
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
Example #27
0
 def lang2str(cls, lang):
     filepath = os.path.join(FILE_DIR,"{}.txt".format(lang))
     s = FileTool.filepath2utf8(filepath)
     return s
Example #28
0
 def filepath2xml(cls, filepath):
     utf8 = FileTool.filepath2utf8(filepath)
     return cls.utf82xml(utf8)