Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
updating automation code to publish the documentation and the setups
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Feb 15, 2015
1 parent 81b6c20 commit 4e75037
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 2 deletions.
45 changes: 45 additions & 0 deletions 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%
123 changes: 123 additions & 0 deletions 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 <http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/index.html>`_.
@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 <http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/pyquickhelper/funcwin/frame_params.html#pyquickhelper.funcwin.frame_params.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 ``<local_root>/<relative_path>``, it
will be uploaded to ``<web_root>/<relative_path>``.
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 <http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/pyquickhelper/funcwin/frame_params.html#pyquickhelper.funcwin.frame_params.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()

4 changes: 2 additions & 2 deletions src/ensae_teaching_cs/automation/project_helper.py
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4e75037

Please sign in to comment.