Skip to content

Instantly share code, notes, and snippets.

@traeblain
Created December 10, 2012 18:54
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save traeblain/4252511 to your computer and use it in GitHub Desktop.
Save traeblain/4252511 to your computer and use it in GitHub Desktop.
Batch file for Pelican since make doesn't work on Windows
@echo off
SETLOCAL EnableDelayedExpansion
set _PELICAN=$pelican
set _PELICANOPTS=$pelicanopts
set _BASEDIR=%cd%
set _INPUTDIR=%_BASEDIR%/content
set _OUTPUTDIR=%_BASEDIR%/output
set _CONFFILE=%_BASEDIR%/pelicanconf.py
set _cmmd=tasklist /FI "IMAGENAME eq python.exe" /FO CSV /NH
IF EXIST %_BASEDIR%\devserver.pid (
echo DevServer already running...killing...
GOTO :killpydevserver
)
call :startpydevserver
GOTO:EOF
:startpelican
cd %_BASEDIR%
start %_PELICAN% --debug --autoreload -r %_INPUTDIR% -o %_OUTPUTDIR% -s %_CONFFILE% %_PELICANOPTS%
GOTO:EOF
:killpelican
taskkill /F /T /IM pelican.exe
GOTO:EOF
:startpydevserver
cd %_OUTPUTDIR%
start python -m SimpleHTTPServer
set o=
FOR /F "tokens=2* delims=," %%G IN ('%_cmmd%') DO (
set /a o+=1
set _srvpid=%%G
)
echo %_srvpid:~1,-1% > %_BASEDIR%\devserver.pid
call :startpelican
GOTO:EOF
:killpydevserver
FOR /F %%a in ('type "%_BASEDIR%\devserver.pid"') DO (
echo Killing DevServer running at PID = %%a
taskkill /PID %%a
)
del %_BASEDIR%\devserver.pid
call :killpelican
GOTO:EOF
ENDLOCAL
@echo off
SETLOCAL
set _PELICAN=$pelican
set _PELICANOPTS=$pelicanopts
set _BASEDIR=%cd%
set _INPUTDIR=%_BASEDIR%\content
set _OUTPUTDIR=%_BASEDIR%\output
set _CONFFILE=%_BASEDIR%\pelicanconf.py
set _PUBLISHCONF=%_BASEDIR%\publishconf.py
set _FTP_HOST=$ftp_host
set _FTP_USER=$ftp_user
set _FTP_TARGET_DIR=$ftp_target_dir
set _SSH_HOST=$ssh_host
set _SSH_PORT=$ssh_port
set _SSH_USER=$ssh_user
set _SSH_TARGET_DIR=$ssh_target_dir
set _DROPBOX_DIR=$dropbox_dir
set _DEF=%1
set _UPLOAD=%2
IF "%_DEF%"=="html" (
GOTO :html
)
IF "%_DEF%"=="clean" (
GOTO :clean
)
IF "%_DEF%"=="regenerate" (
GOTO :regenerate
)
IF "%_DEF%"=="publish" (
GOTO :publish
)
IF "%_DEF%"=="serve" (
GOTO :serve
)
IF "%_DEF%"=="devserver" (
GOTO :devserver
)
IF "%_DEF%"=="upload" (
GOTO :upload
)
IF "%_DEF%"=="help" (
GOTO :help
)
echo No or incorrect argument given, please review your input or type
echo 'pmake help' for help.
GOTO :end
:help
echo Batch file for a pelican Web site
echo.
echo Usage:
echo pmake COMMAND(S)
echo.
echo Commands:
echo html (re)generate the web site
echo clean remove the generated files
echo regenerate regenerate files upon modification
echo publish generate using production settings
echo serve serve site at http://localhost:8000
echo devserver start/restart develop_server.sh
echo upload ssh upload the web site via SSH
echo upload rsync upload the web site via rsync+ssh
echo upload dropbox upload the web site via Dropbox
echo upload ftp upload the web site via FTP
echo upload github upload the web site via gh-pages
echo.
GOTO :end
:html
echo Running Pelican to generate HTML output
%_PELICAN% %_INPUTDIR% -o %_OUTPUTDIR% -s %_CONFFILE% %_PELICANOPTS%
echo Done
GOTO :end
:clean
echo Cleaning Output directory (deleting everything)
rmdir /S %_OUTPUTDIR%
mkdir %_OUTPUTDIR%
GOTO :end
:regenerate
echo Running Pelican and regenerating upon file changes
echo Press Ctrl-C to end, Y or N on batch job, either will work.
%_PELICAN% -r %_INPUTDIR% -o %_OUTPUTDIR% -s %_CONFFILE% %_PELICANOPTS%
GOTO :end
:serve
echo Press Ctrl-C to end the server.
echo Then Y or N to end the batch job. Both will end it.
cd %_OUTPUTDIR% && python -m SimpleHTTPServer
GOTO :end
:devserver
call %_BASEDIR%/devserver.cmd
GOTO :end
:publish
echo Generating production ready HTML
%_PELICAN% %_INPUTDIR% -o %_OUTPUTDIR% -s %_PUBLISHCONF% %_PELICANOPTS%
GOTO:EOF
:upload
IF "%_UPLOAD%"=="ssh" (
GOTO :ssh
)
IF "%_UPLOAD%"=="rsync" (
GOTO :rsync
)
IF "%_UPLOAD%"=="dropbox" (
GOTO :dropbox
)
IF "%_UPLOAD%"=="ftp" (
GOTO :ftp
)
IF "%_UPLOAD%"=="github" (
GOTO :github
)
echo No upload location given. Please provide a destination/protocol.
echo You can use 'pmake help' to see the available options.
GOTO :end
:ssh
echo Running Pelican and publishing output through SSH
call :publish
echo You must have WinSCP in your PATH variable.
winscp.com /console /command "open scp://%_SSH_USER%@%_SSH_HOST%:%_SSH_PORT%" "option batch on" "option confirm off" "cd %_SSH_TARGET_DIR%" "put %_OUTPUTDIR%\*" "exit"
GOTO :end
:rsync
echo Running Pelican and publishing output through Rsync
call :publish
echo You must have Rsync in your PATH variable.
echo Current best Windows Rsync version located at:
echo http://sourceforge.net/projects/sereds/files/cwRsync/4.0.5/
set _RSYNC_OUTPUT=%_OUTPUTDIR:\=/%
rsync.exe -e "ssh -p %_SSH_PORT%" -P -rvz --delete "/cygdrive/c%_RSYNC_OUTPUT:~2%/*" %_SSH_USER%@%_SSH_HOST%:%_SSH_TARGET_DIR%
GOTO :end
:dropbox
echo Running Pelican and publishing output to Dropbox
%_PELICAN% %_INPUTDIR% -o %_DROPBOX_DIR% -s %_PUBLISHCONF% %_PELICANOPTS%
GOTO :end
:ftp
echo Running Pelican and publishing output through FTP
call :publish
echo You must have WinSCP in your PATH variable.
winscp.com /console /command "open ftp://%_FTP_USER%@%_FTP_HOST%" "option batch on" "option confirm off" "cd %_FTP_TARGET_DIR%" "put %_OUTPUTDIR\*" "exit"
GOTO :end
:github
echo Running Pelican and publishing output to Github
call :publish
ghp-import %_OUTPUTDIR%
git push origin gh-pages
:end
ENDLOCAL
@felciano
Copy link

Thanks for pulling this together and sharing it. What's the deal with the $variables? Should those be interpolated at runtime?

@traeblain
Copy link
Author

So these are .in files that could be used in the Pelican codebase. What you want to do is replace the $variables with the explicit commands/arguments/etc. These $variables would be replaced in the pelican-quickstart with the stuff you actually enter. Therefore:

$pelican in windows is the pelican command so set _PELICAN=pelican should work for you.
$pelicanopts is any additional options you may want, works just fine as set _PELICANOPTS=

For all the FTP and SSH items replace the $variables with what you want. For _DROPBOX_DIR setup have it equal something in the format: C:\Users\user\Dropbox\weboutput

Edit that and it should fire right off.

@uknick
Copy link

uknick commented May 30, 2013

Thanks a lot for this! I finally got Pelican to generate on Windows - spent a lot of time messing around with cygwin :)

c:\wamp\www\pelican>make.bat html
Running Pelican to generate HTML output
Done: Processed 2 articles and 1 pages in 0.31 seconds.
Done

@opilar
Copy link

opilar commented Jun 21, 2013

Doesn't work. Image. Output folder is empty.
UPD: sorry, forgot set _PELICANOPTS=. Works fine.

@professorplumb
Copy link

Thanks very much for this! Got me up and running in a flash.

For others who are using pmake upload ssh: if WinSCP doesn't already have your host key cached, it will ask you if you want to add it, which will abort the pmake script before you get a chance to answer:

The server's host key was not found in the cache. You have no guarantee that the server is the computer you think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 [etc]
If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel.
Continue connecting and add host key to the cache?
(Y)es, (N)o, C(a)ncel, (C)opy Key:

C:\Users\Eric\IdeaProjects\blog>

The fix is to create a profile for your remote server in WinSCP and make sure its hostname is the same as your $ssh_host in pmake.cmd.

@TheBlusky
Copy link

Ok, this old, but still in use.
You should (for the FTP command), replace "put %_OUTPUTDIR\*" by "put %_OUTPUTDIR%\*"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment