def publish_teachings_to_web(
        login,
        ftpsite="ftp.xavierdupre.fr",
        google_id=None,
        location="c:\\jenkins\\pymy\\%s\\%s%s\\dist\\%s",
        rootw="/www/htdocs/app/%s/%s",
        rootw2="/lesenfantscodaient.fr",
        folder_status=".",
        layout=[("html", "helpsphinx")],
        modules=[
            "pyquickhelper", "cpyquickhelper", "jyquickhelper",
            "tkinterquickhelper", "pyensae", "pymyinstall", "pysqllike",
            "pyrsslocal", "pymmails", "python3_module_template",
            "actuariat_python", "code_beatrix", "ensae_projects", "jupytalk",
            "mlstatpy", "teachpyx", "pandas_streaming", "ensae_teaching_cs"
        ],
        password=None,
        force_allow=None,
        suffix=("_UT_%d%d_std" % sys.version_info[:2], ),
        fLOG=print,
        exc=True):
    """
    Copy the documentation to the website.

    @param      login           login
    @param      ftpsite         ftp site
    @param      google_id       google_id
    @param      location        location of Jenkins build
    @param      rootw           root on ftp site
    @param      rootw2          root for ``lesenfantscodaient.fr``
    @param      folder_status   folder status
    @param      modules         list of modules to publish
    @param      password        if None, if will asked
    @param      layout          last part of the folders
    @param      suffix          suffixes to append to the project name
    @param      force_allow     allow to publish files even if they contain these strings
                                whereas they seem to be credentials
    @param      exc             raise exception if not found (True) or skip (False)
    @param      fLOG            logging function

    Example of use::

        import sys
        import os
        from pyquickhelper.filehelper import TransferFTP, FileTreeNode, FolderTransferFTP
        from tkinterquickhelper.funcwin import open_window_params
        from ensae_teaching_cs.automation.ftp_publish_helper import publish_teachings_to_web

        login = "******"
        website = "ftp...."
        rootw = "/www/htdocs/app/%s/%s"
        rootw2 = "/lesenfantscodaient.fr"

        password = None

        publish_teachings_to_web(login, ftpsite=website,
            google_id="google_id",
            location="<something>\\\\%s\\\\%s%s\\\\dist\\\\%s",
            rootw=rootw,
            rootw2=rootw2,
            folder_status=os.path.abspath("."),
            password=password)

    """
    import os
    from tkinterquickhelper.funcwin import open_window_params
    from ensae_teaching_cs.automation.ftp_publish_helper import publish_documentation

    if google_id is None:
        google_id = ""
    else:
        footer = """
        <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
        <script type="text/javascript">
        _uacct = "{}";
        urchinTracker();
        </script>
        """.format(google_id)

    if password is None:
        params = {"password": ""}
        params = open_window_params(params,
                                    title="password",
                                    help_string="password",
                                    key_save="my_password")
        password = params["password"]

    location = os.path.abspath(location)
    if folder_status is None:
        folder_status = os.path.abspath(os.path.dirname(__file__))
    else:
        folder_status = os.path.abspath(folder_status)

    if not isinstance(suffix, (tuple, list)):
        suffix = [suffix]

    projects = []
    for module in modules:

        fLOG("  +", module, " -- ", layout)

        for lay in layout:
            for suf in suffix:
                root = os.path.abspath(location %
                                       (module, module, suf, lay[0]))
                keepsuf = suf
                if os.path.exists(root):
                    break
            if not os.path.exists(root):
                if exc:
                    raise FileNotFoundError(
                        "first tried '{0}'\n last tried '{1}'".format(
                            root,
                            os.path.abspath(
                                location %
                                (module, module, suffix[0], lay[0]))))
                else:
                    fLOG("[publish_teachings_to_web] skip", root)
                    continue
                fLOG("   ", root)
            if module != "code_beatrix":
                rw = rootw % (module, lay[1])
            else:
                rw = rootw2

            project = dict(status_file=os.path.join(folder_status,
                                                    "status_%s.txt" % module),
                           local=root,
                           root_local=root,
                           root_web=rw)
            projects.append(project)

        if module == "ensae_teaching_cs":
            lay = [_ for _ in layout if _[0] == "html"][0]
            if not os.path.exists(root):
                if exc:
                    raise FileNotFoundError(root)
                else:
                    fLOG("[publish_teachings_to_web] skip", root)
                    continue

            project = dict(status_file=os.path.join(folder_status,
                                                    "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html3"),
                           root_local=root.replace("\\html", "\\html3"),
                           root_web=(rootw % (module, lay[1])).replace(
                               "_no_clean",
                               "").replace("/helpsphinx", "/helpsphinx3"))
            projects.append(project)

            # pres

            for sufpress in ["", "_2A", "_3A"]:
                root = os.path.abspath(location %
                                       (module, module, keepsuf, "html"))
                if not os.path.exists(root):
                    if exc:
                        raise FileNotFoundError(root)
                    else:
                        fLOG("[publish_teachings_to_web] skip", root)
                        continue
                project = dict(
                    status_file=os.path.join(folder_status,
                                             "status_%s.txt" % module),
                    local=root.replace("\\html", "\\html_pres" + sufpress),
                    root_local=root.replace("\\html",
                                            "\\html_pres" + sufpress),
                    root_web=(rootw % (module, lay[1])).replace(
                        "/helpsphinx",
                        "/pressphinx" + sufpress).replace("_no_clean", ""))
                projects.append(project)

        elif module == "python3_module_template":
            lay = [_ for _ in layout if _[0] == "html"][0]
            if not os.path.exists(root):
                if exc:
                    raise FileNotFoundError(root)
                else:
                    fLOG("[publish_teachings_to_web] skip", root)
                    continue

            project = dict(status_file=os.path.join(folder_status,
                                                    "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html2"),
                           root_local=root.replace("\\html", "\\html2"),
                           root_web=(rootw % (module, lay[1])).replace(
                               "_no_clean",
                               "").replace("/helpsphinx", "/helpsphinx2"))
            projects.append(project)

    # publish

    publish_documentation(projects,
                          ftpsite=ftpsite,
                          login=login,
                          password=password,
                          key_save="my_module_password",
                          footer_html=footer,
                          force_allow=force_allow,
                          fLOG=fLOG)
def publish_teachings_to_web(
        login,
        ftpsite="ftp.xavierdupre.fr",
        google_id=None,
        location="C:\\jenkins\\pymy\\%s\\dist\\%s",
        rootw="/www/htdocs/app/%s/%s",
        rootw2="/lesenfantscodaient.fr",
        folder_status=".",
        layout=[("epub", "epub"), ("html", "helpsphinx")],
        modules=["anaconda2_pyquickhelper_27",
                 "pyquickhelper",
                 "pyensae",
                 "anaconda2_pymyinstall_27",
                 "pymyinstall",
                 "pysqllike",
                 "pyrsslocal",
                 "pymmails",
                 "anaconda2_python3_module_template_27",
                 "python3_module_template",
                 "actuariat_python",
                 "code_beatrix",
                 "ensae_teaching_cs"],
        password=None,
        fLOG=print):
    """
    copy the documentation to the website

    @param      login           login
    @param      ftpsite         ftp site
    @param      google_id       google_id
    @param      location        location of Jenkins build
    @param      rootw           root on ftp site
    @param      rootw2          root for ``lesenfantscodaient.fr``
    @param      folder_status   folder status
    @param      modules         list of modules to publish
    @param      password        if None, if will asked
    @param      layout          last part of the folders
    @param      fLOG            logging function

    Example of use::

        import sys
        import os
        from pyquickhelper import TransferFTP, FileTreeNode, FolderTransferFTP, open_window_params
        from ensae_teaching_cs.automation.ftp_publish_helper import publish_teachings_to_web

        login = "******"
        website = "ftp...."
        rootw = "/www/htdocs/app/%s/%s"
        rootw2 = "/lesenfantscodaient.fr"

        password = None

        publish_teachings_to_web(login, ftpsite=website,
            google_id="google_id",
            location="<something>\\\\%s\\\\dist\\\\%s",
            rootw=rootw,
            rootw2=rootw2,
            folder_status=os.path.abspath("."),
            password=password)

    """
    import os
    import shutil
    from pyquickhelper import open_window_params
    from ensae_teaching_cs.automation.ftp_publish_helper import publish_documentation

    if google_id is None:
        google_id = ""
    else:
        footer = """
        <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
        <script type="text/javascript">
        _uacct = "{}";
        urchinTracker();
        </script>
        """.format(google_id)

    if password is None:
        params = {"password": ""}
        params = open_window_params(
            params, title="password", help_string="password", key_save="my_password")
        password = params["password"]

    location = os.path.abspath(location)
    if folder_status is None:
        folder_status = os.path.abspath(os.path.dirname(__file__))
    else:
        folder_status = os.path.abspath(folder_status)

    projects = []
    for module in modules:

        fLOG("+", module, " -- ", layout)

        if module.endswith("27"):
            lay = layout[0]
            # C:\jenkins\pymy\anaconda2_pyquickhelper_27\dist_module27\dist
            root = os.path.abspath(location % (
                module + "\\dist_module27", lay[0]))
            root = os.path.join(root, "..")

            if not os.path.exists(root):
                warnings.warn(
                    "unable to publish: {0},\n{1} not found".format(module, root))
                continue

            for f in os.listdir(root):
                ext = os.path.splitext(f)[-1]
                if ext in [".whl"]:
                    dest = module.replace("anaconda2_", "").replace("_27", "")
                    dest = location % (dest, lay[0])
                    dest = os.path.join(dest, "..")
                    shutil.copy(os.path.join(root, f), dest)
        else:
            for lay in layout:
                root = os.path.abspath(location % (module, lay[0]))
                if module != "code_beatrix":
                    smod = module.replace("_no_clean", "").replace(
                        "anaconda2_", "").replace("_27", "")
                    rw = rootw % (smod, lay[1])
                else:
                    if lay[1] == "epub":
                        rw = rootw2 + "/" + lay[1]
                    else:
                        rw = rootw2

                project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                               local=root,
                               root_local=root,
                               root_web=rw)
                projects.append(project)

        if module == "ensae_teaching_cs":

            lay = [_ for _ in layout if _[0] == "html"][0]
            root = os.path.abspath(location % (module, lay[0]))

            project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html2"),
                           root_local=root.replace("\\html", "\\html2"),
                           root_web=(rootw % (module, lay[1])).replace("_no_clean", "").replace("/helpsphinx", "/helpsphinx2"))
            projects.append(project)

            project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html3"),
                           root_local=root.replace("\\html", "\\html3"),
                           root_web=(rootw % (module, lay[1])).replace("_no_clean", "").replace("/helpsphinx", "/helpsphinx3"))
            projects.append(project)

            # pres

            for suffix in ["", "_2A", "_3A", "_1Ap"]:
                root = os.path.abspath(location % (module, "html"))
                project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                               local=root.replace(
                                   "\\html", "\\html_pres" + suffix),
                               root_local=root.replace(
                                   "\\html", "\\html_pres" + suffix),
                               root_web=(rootw % (module, lay[1])).replace("/helpsphinx", "/pressphinx" + suffix).replace("_no_clean", ""))
                projects.append(project)

    # publish

    publish_documentation(projects,
                          ftpsite=ftpsite,
                          login=login,
                          password=password,
                          key_save="my_module_password",
                          footer_html=footer,
                          fLOG=fLOG)
def publish_teachings_to_web(
        login,
        ftpsite="ftp.xavierdupre.fr",
        google_id=None,
        location="C:\\jenkins\\pymy\\%s\\dist\\%s",
        rootw="/www/htdocs/app/%s/%s",
        rootw2="/lesenfantscodaient.fr",
        folder_status=".",
        layout=[("epub", "epub"), ("html", "helpsphinx")],
        modules=[
            "anaconda2_pyquickhelper_27", "pyquickhelper", "pyensae",
            "anaconda2_pymyinstall_27", "pymyinstall", "pysqllike",
            "pyrsslocal", "pymmails", "anaconda2_python3_module_template_27",
            "python3_module_template", "actuariat_python", "code_beatrix",
            "ensae_teaching_cs"
        ],
        password=None,
        fLOG=print):
    """
    copy the documentation to the website

    @param      login           login
    @param      ftpsite         ftp site
    @param      google_id       google_id
    @param      location        location of Jenkins build
    @param      rootw           root on ftp site
    @param      rootw2          root for ``lesenfantscodaient.fr``
    @param      folder_status   folder status
    @param      modules         list of modules to publish
    @param      password        if None, if will asked
    @param      layout          last part of the folders
    @param      fLOG            logging function

    Example of use::

        import sys
        import os
        from pyquickhelper import TransferFTP, FileTreeNode, FolderTransferFTP, open_window_params
        from ensae_teaching_cs.automation.ftp_publish_helper import publish_teachings_to_web

        login = "******"
        website = "ftp...."
        rootw = "/www/htdocs/app/%s/%s"
        rootw2 = "/lesenfantscodaient.fr"

        password = None

        publish_teachings_to_web(login, ftpsite=website,
            google_id="google_id",
            location="<something>\\\\%s\\\\dist\\\\%s",
            rootw=rootw,
            rootw2=rootw2,
            folder_status=os.path.abspath("."),
            password=password)

    """
    import os
    import shutil
    from pyquickhelper import open_window_params
    from ensae_teaching_cs.automation.ftp_publish_helper import publish_documentation

    if google_id is None:
        google_id = ""
    else:
        footer = """
        <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
        <script type="text/javascript">
        _uacct = "{}";
        urchinTracker();
        </script>
        """.format(google_id)

    if password is None:
        params = {"password": ""}
        params = open_window_params(params,
                                    title="password",
                                    help_string="password",
                                    key_save="my_password")
        password = params["password"]

    location = os.path.abspath(location)
    if folder_status is None:
        folder_status = os.path.abspath(os.path.dirname(__file__))
    else:
        folder_status = os.path.abspath(folder_status)

    projects = []
    for module in modules:

        fLOG("+", module, " -- ", layout)

        if module.endswith("27"):
            lay = layout[0]
            # C:\jenkins\pymy\anaconda2_pyquickhelper_27\dist_module27\dist
            root = os.path.abspath(location %
                                   (module + "\\dist_module27", lay[0]))
            root = os.path.join(root, "..")

            if not os.path.exists(root):
                warnings.warn("unable to publish: {0},\n{1} not found".format(
                    module, root))
                continue

            for f in os.listdir(root):
                ext = os.path.splitext(f)[-1]
                if ext in [".whl"]:
                    dest = module.replace("anaconda2_", "").replace("_27", "")
                    dest = location % (dest, lay[0])
                    dest = os.path.join(dest, "..")
                    shutil.copy(os.path.join(root, f), dest)
        else:
            for lay in layout:
                root = os.path.abspath(location % (module, lay[0]))
                if module != "code_beatrix":
                    smod = module.replace("_no_clean",
                                          "").replace("anaconda2_",
                                                      "").replace("_27", "")
                    rw = rootw % (smod, lay[1])
                else:
                    if lay[1] == "epub":
                        rw = rootw2 + "/" + lay[1]
                    else:
                        rw = rootw2

                project = dict(status_file=os.path.join(
                    folder_status, "status_%s.txt" % module),
                               local=root,
                               root_local=root,
                               root_web=rw)
                projects.append(project)

        if module == "ensae_teaching_cs":

            lay = [_ for _ in layout if _[0] == "html"][0]
            root = os.path.abspath(location % (module, lay[0]))

            project = dict(status_file=os.path.join(folder_status,
                                                    "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html2"),
                           root_local=root.replace("\\html", "\\html2"),
                           root_web=(rootw % (module, lay[1])).replace(
                               "_no_clean",
                               "").replace("/helpsphinx", "/helpsphinx2"))
            projects.append(project)

            project = dict(status_file=os.path.join(folder_status,
                                                    "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html3"),
                           root_local=root.replace("\\html", "\\html3"),
                           root_web=(rootw % (module, lay[1])).replace(
                               "_no_clean",
                               "").replace("/helpsphinx", "/helpsphinx3"))
            projects.append(project)

            # pres

            for suffix in ["", "_2A", "_3A", "_1Ap"]:
                root = os.path.abspath(location % (module, "html"))
                project = dict(
                    status_file=os.path.join(folder_status,
                                             "status_%s.txt" % module),
                    local=root.replace("\\html", "\\html_pres" + suffix),
                    root_local=root.replace("\\html", "\\html_pres" + suffix),
                    root_web=(rootw % (module, lay[1])).replace(
                        "/helpsphinx",
                        "/pressphinx" + suffix).replace("_no_clean", ""))
                projects.append(project)

    # publish

    publish_documentation(projects,
                          ftpsite=ftpsite,
                          login=login,
                          password=password,
                          key_save="my_module_password",
                          footer_html=footer,
                          fLOG=fLOG)
        projects.append(project)

        root = os.path.abspath(location % module)
        project = dict(status_file=os.path.join(this, "status_%s.txt" % module),
                       local=root.replace("\\html", "\\html3"),
                       root_local=root.replace("\\html", "\\html3"),
                       root_web=(rootw % module).replace("/helpsphinx", "/helpsphinx3"))
        projects.append(project)

        # pres

        for suffix in ["", "_2A", "_3A", "_1Ap"]:
            root = os.path.abspath(location % module)
            project = dict(status_file=os.path.join(this, "status_%s.txt" % module),
                           local=root.replace(
                               "\\html", "\\html_pres" + suffix),
                           root_local=root.replace(
                               "\\html", "\\html_pres" + suffix),
                           root_web=(rootw % module).replace("/helpsphinx", "/pressphinx" + suffix).replace("_no_clean", ""))
            projects.append(project)


# publish

publish_documentation(projects,
                      ftpsite=website,
                      login=login,
                      password=password,
                      key_save="my_module_password",
                      footer_html=footer)
Example #5
0
def publish_teachings_to_web(login, ftpsite="ftp.xavierdupre.fr", google_id=None,
                             location="d:\\jenkins\\pymy\\%s%s\\dist\\%s", rootw="/www/htdocs/app/%s/%s",
                             rootw2="/lesenfantscodaient.fr", folder_status=".",
                             layout=[("html", "helpsphinx")],
                             modules=["pyquickhelper",
                                      "jyquickhelper",
                                      "pyensae",
                                      "pymyinstall",
                                      "pysqllike",
                                      "pyrsslocal",
                                      "pymmails",
                                      "python3_module_template",
                                      "actuariat_python",
                                      "code_beatrix",
                                      "ensae_projects",
                                      "jupytalk",
                                      "mlstatpy",
                                      "teachpyx",
                                      "ensae_teaching_cs"
                                      ],
                             password=None,
                             force_allow=None,
                             suffix=("_UT_35_std", "_DOC_35_std", ""),
                             fLOG=print):
    """
    copy the documentation to the website

    @param      login           login
    @param      ftpsite         ftp site
    @param      google_id       google_id
    @param      location        location of Jenkins build
    @param      rootw           root on ftp site
    @param      rootw2          root for ``lesenfantscodaient.fr``
    @param      folder_status   folder status
    @param      modules         list of modules to publish
    @param      password        if None, if will asked
    @param      layout          last part of the folders
    @param      suffix          suffixes to append to the project name
    @param      force_allow     allow to publish files even if they contain these strings
                                whereas they seem to be credentials
    @param      fLOG            logging function

    Example of use::

        import sys
        import os
        from pyquickhelper.filehelper import TransferFTP, FileTreeNode, FolderTransferFTP
        from pyquickhelper.funcwin import open_window_params
        from ensae_teaching_cs.automation.ftp_publish_helper import publish_teachings_to_web

        login = "******"
        website = "ftp...."
        rootw = "/www/htdocs/app/%s/%s"
        rootw2 = "/lesenfantscodaient.fr"

        password = None

        publish_teachings_to_web(login, ftpsite=website,
            google_id="google_id",
            location="<something>\\\\%s%s\\\\dist\\\\%s",
            rootw=rootw,
            rootw2=rootw2,
            folder_status=os.path.abspath("."),
            password=password)

    """
    import os
    from pyquickhelper.funcwin import open_window_params
    from ensae_teaching_cs.automation.ftp_publish_helper import publish_documentation

    if google_id is None:
        google_id = ""
    else:
        footer = """
        <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
        <script type="text/javascript">
        _uacct = "{}";
        urchinTracker();
        </script>
        """.format(google_id)

    if password is None:
        params = {"password": ""}
        params = open_window_params(
            params, title="password", help_string="password", key_save="my_password")
        password = params["password"]

    location = os.path.abspath(location)
    if folder_status is None:
        folder_status = os.path.abspath(os.path.dirname(__file__))
    else:
        folder_status = os.path.abspath(folder_status)

    if not isinstance(suffix, (tuple, list)):
        suffix = [suffix]

    projects = []
    for module in modules:

        fLOG("+", module, " -- ", layout)

        for lay in layout:
            for suf in suffix:
                root = os.path.abspath(location % (module, suf, lay[0]))
                keepsuf = suf
                if os.path.exists(root):
                    break
            if not os.path.exists(root):
                raise FileNotFoundError(os.path.abspath(
                    location % (module, suffix[0], lay[0])))
            if module != "code_beatrix":
                rw = rootw % (module, lay[1])
            else:
                rw = rootw2

            project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                           local=root, root_local=root, root_web=rw)
            projects.append(project)

        if module == "ensae_teaching_cs":
            lay = [_ for _ in layout if _[0] == "html"][0]
            if not os.path.exists(root):
                raise FileNotFoundError(root)

            project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html2"),
                           root_local=root.replace("\\html", "\\html2"),
                           root_web=(rootw % (module, lay[1])).replace("_no_clean", "").replace("/helpsphinx", "/helpsphinx2"))
            projects.append(project)

            project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html3"),
                           root_local=root.replace("\\html", "\\html3"),
                           root_web=(rootw % (module, lay[1])).replace("_no_clean", "").replace("/helpsphinx", "/helpsphinx3"))
            projects.append(project)

            # pres

            for suffix in ["", "_2A", "_3A", "_1Ap"]:
                root = os.path.abspath(location % (module, keepsuf, "html"))
                if not os.path.exists(root):
                    raise FileNotFoundError(root)
                project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                               local=root.replace(
                                   "\\html", "\\html_pres" + suffix),
                               root_local=root.replace(
                                   "\\html", "\\html_pres" + suffix),
                               root_web=(rootw % (module, lay[1])).replace("/helpsphinx", "/pressphinx" + suffix).replace("_no_clean", ""))
                projects.append(project)

        elif module == "python3_module_template":
            lay = [_ for _ in layout if _[0] == "html"][0]
            if not os.path.exists(root):
                raise FileNotFoundError(root)

            project = dict(status_file=os.path.join(folder_status, "status_%s.txt" % module),
                           local=root.replace("\\html", "\\html2"),
                           root_local=root.replace("\\html", "\\html2"),
                           root_web=(rootw % (module, lay[1])).replace("_no_clean", "").replace("/helpsphinx", "/helpsphinx2"))
            projects.append(project)

    # publish

    publish_documentation(projects, ftpsite=ftpsite, login=login, password=password,
                          key_save="my_module_password", footer_html=footer,
                          force_allow=force_allow, fLOG=fLOG)