From 4e750371e020c55cde6e72a001cc3943cf01642f Mon Sep 17 00:00:00 2001 From: dupre Date: Sun, 15 Feb 2015 13:51:49 +0100 Subject: [PATCH] updating automation code to publish the documentation and the setups --- build_help_on_windows.bat | 45 +++++++ .../automation/ftp_publish_helper.py | 123 ++++++++++++++++++ .../automation/project_helper.py | 4 +- 3 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 build_help_on_windows.bat create mode 100644 src/ensae_teaching_cs/automation/ftp_publish_helper.py diff --git a/build_help_on_windows.bat b/build_help_on_windows.bat new file mode 100644 index 000000000..a6d4af490 --- /dev/null +++ b/build_help_on_windows.bat @@ -0,0 +1,45 @@ +echo off +IF EXIST dist del /Q dist\*.* + +set pythonexe=c:\Python34_x64\python + + +:presentation: +%pythonexe% -u setup.py build_pres +if %errorlevel% neq 0 exit /b %errorlevel% +%pythonexe% -u setup.py build_pres_2A +if %errorlevel% neq 0 exit /b %errorlevel% +%pythonexe% -u setup.py build_pres_3A +if %errorlevel% neq 0 exit /b %errorlevel% +echo ####################################################### + +:documentation: +%pythonexe% -u setup.py build_sphinx +if %errorlevel% neq 0 exit /b %errorlevel% +echo ####################################################### + +:copyfiles: +if not exist dist\html mkdir dist\html +if not exist dist\html2 mkdir dist\html2 +if not exist dist\html3 mkdir dist\html3 +if not exist dist\latex mkdir dist\latex +if not exist dist\html_pres mkdir dist\html_pres +if not exist dist\html_pres_2A mkdir dist\html_pres_2A +if not exist dist\html_pres_3A mkdir dist\html_pres_3A + +echo #######################################################F + +xcopy /E /C /I /Y _doc\presentation_2A\build\html dist\html_pres_2A +if %errorlevel% neq 0 exit /b %errorlevel% +xcopy /E /C /I /Y _doc\presentation_3A\build\html dist\html_pres_3A +if %errorlevel% neq 0 exit /b %errorlevel% +xcopy /E /C /I /Y _doc\presentation\build\html dist\html_pres +if %errorlevel% neq 0 exit /b %errorlevel% +xcopy /E /C /I /Y _doc\sphinxdoc\build\html dist\html +if %errorlevel% neq 0 exit /b %errorlevel% +xcopy /E /C /I /Y _doc\sphinxdoc\build2\html dist\html2 +if %errorlevel% neq 0 exit /b %errorlevel% +xcopy /E /C /I /Y _doc\sphinxdoc\build3\html dist\html3 +if %errorlevel% neq 0 exit /b %errorlevel% +xcopy /E /C /I /Y _doc\sphinxdoc\build\latex dist\latex +if %errorlevel% neq 0 exit /b %errorlevel% \ No newline at end of file diff --git a/src/ensae_teaching_cs/automation/ftp_publish_helper.py b/src/ensae_teaching_cs/automation/ftp_publish_helper.py new file mode 100644 index 000000000..21e872ed3 --- /dev/null +++ b/src/ensae_teaching_cs/automation/ftp_publish_helper.py @@ -0,0 +1,123 @@ +#-*- coding: utf-8 -*- +""" +@file +@brief Helpers to publish the documentation of python to a website +""" + +import os +from pyquickhelper import TransferFTP, FileTreeNode, FolderTransferFTP, open_window_params +from pyquickhelper.filehelper.ftp_transfer_files import content_as_binary + +def trigger_on_specific_strings(content): + """ + look for specific string such as *USERNAME*, *USERDNSDOMAIN*, *HOMEPATH*, *USERNAME*, + *COMPUTERNAME*, *LOGONSERVER*, and returns None if it was found + or modifies the content to remove it + """ + lower_content = content.lower() + for st in ["USERNAME", "USERDNSDOMAIN", "HOMEPATH", "USERNAME", + "COMPUTERNAME", "LOGONSERVER"]: + s = os.environ[st].lower() + if s in lower_content: + return None + return content + +def publish_documentation( + docs, + ftpsite = None, + login = None, + password = None, + key_save = "my_password", + footer_html = None, + content_filter = trigger_on_specific_strings, + is_binary = content_as_binary, + fLOG = print + ): + """ + publish the documentation and the setups of a python module on a webiste, + it assumes the modules is organized the same way as + `pyquickhelper `_. + + @param docs list of dictionaries (see below) + @param ftpsite something like ``ftp.something.`` + @param login login + @param password password + @param key_save see function `open_window_params `_ + @param footer_html append this HTML code to any uploaded page (such a javascript code to count the audience) + @param content_filter filter the content of a file (it raises an exception if the result is None), + appies only on text files + @param is_binary a function to tell if a content of a file is binary or not + @param fLOG logging function + + *docs* is a list of dictionaries which must contain for each folder + to transfer: + - ``local``: local folder + - ``root_local``: local paths will be related to this root + - ``root_web``: prefix to add to the remote paths + - ``status_file``: a file where the function populates the transfered files and some information about them + + A local file is composed by ``/``, it + will be uploaded to ``/``. + + If one of the three first parameters is None, the function + will open a popup windows to ask the missing information. + See `open_window_params `_. + """ + + params = {"ftpsite":ftpsite, + "login":login, + "password":password, + } + + nbnone = len ( [ v for k,v in params.items() if v is None or len(v) == 0 ] ) + if nbnone > 0: + params = open_window_params (params, title="Website and Credentials", help_string = "ftp site + login + password", key_save=key_save) + + nbnone = [ v for k,v in params.items() if v is None or len(v) == 0 ] + if len(nbnone) > 0: + raise Exception("one of the parameters is None:\n" + str(nbnone)) + + password = params["password"] + login = params["login"] + ftpsite = params["ftpsite"] + + ftp = TransferFTP(ftpsite, + login, + password, + fLOG=fLOG) + + for project in docs: + + location = project["local"] + root_local = project["root_local"] + root_web = project["root_web"] + + fLOG("-------------------------",location) + + sfile = project["status_file"] + rootw = project["root_web"] + + ftn = FileTreeNode(root_local) + fftp = FolderTransferFTP (ftn, ftp, sfile, + root_web = rootw, + fLOG=fLOG, + footer_html = footer_html, + content_filter=content_filter, + is_binary=is_binary) + + fftp.start_transfering() + + ftn = FileTreeNode(os.path.join(root_local,".."), + filter = lambda root, path, f, dir: not dir) + fftp = FolderTransferFTP (ftn, ftp, sfile, + root_web = root_web.replace("helpsphinx",""), + fLOG=fLOG, + footer_html = footer_html, + content_filter=content_filter, + is_binary=is_binary) + + fftp.start_transfering() + + + ftp.close() + diff --git a/src/ensae_teaching_cs/automation/project_helper.py b/src/ensae_teaching_cs/automation/project_helper.py index 4744817a7..99a0927e6 100644 --- a/src/ensae_teaching_cs/automation/project_helper.py +++ b/src/ensae_teaching_cs/automation/project_helper.py @@ -270,7 +270,7 @@ def git_clone( hg = os.path.join(local_folder, ".git") if os.path.exists(hg): raise Exception("folder {0} should not exist".format(local_folder)) - + if not os.path.exists(hg): cmds= """ cd {0} @@ -345,7 +345,7 @@ def git_change_remote_origin( """.format(local_folder, url_user).replace(" ","").strip(" \n\r\t") if add_fetch: cmds += "\ngit fetch" - cmd = cmds.replace("\n","&") + cmd = cmds.replace("\n","&") sin = "" #"{0}\n".format(password) out, err = run_cmd(cmd, sin=sin,wait=True, timeout=timeout, fLOG=fLOG) git_check_error(out, err, fLOG)