Batch Files are your friend

Published:

By jeffmackinnon

Something that my pelican experience was missing was a little automation that my Unix friends enjoy with makerfiles. I'm sure that there is a windows workaround, or I could just continue to work in WSL for my pelican life.

I do enjoy working in WSL and all the Linux life that brings, but it was starting to become a pain, and I never could figure out how to get lftp working the way that I wanted.

I bought Filezilla Pro CLI

Rather than burning a bunch more hours trying to figure out lftp, or the various built-in ftp clients, I srung for Filezilla Pro. I have used the free version of Filezilla for as long as I can remember, probably since it was a thing on windows, so spending a bit of money to solve the inconvenience I have now and have the functionality to connet to various cloud platforms was a no brainer.

Something that the CLI version has is the ability to do some scripting, so in the batchfile I call the script to update the site on the remote server.

I don't have to include any sensitive information in the script because it shares the site manager with the GUI version.

The scripts

To make everything work cleanly I need two script files, and to manually pipenv shell into the environment.

The Batch File

To start the batchfile looks like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@echo off
cd jeffmackinnon.com-Sourcecode
pelican content -o C:\projects\_publish\jeffmackinnon.com -s publishconf.py
pelican content -o \\bilbo\web -s publishbilbo.py

rem When everything is made it is time to sync with the interwebs. This takes another script for now.

"C:\Program Files\FileZilla Pro CLI\fzcli.exe" --mode standalone --script C:\projects\pelican\cliuploadjeff.txt

cd c:\projects\pelican

This batchfile requires me to be in the proper pipenv, but then it just runs, the reason there is two is because I'm strange. I have have my online version and a local NAS version that I typically use for testing things, and yes all my servers are LOTR based.

This batch file does the following:

  • Changes the directory to where the site source is located
  • Create the html files for the public site
  • Create the html files for the local copy
  • Call the filezilla script to sync the remote site
  • Change the directory back to the main projects file.

The Filezilla Script

To make things "clean" the Filezilla CLI script looks like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
site 0/jeffsite
lcd c:/projects/_publish/jeffmackinnon.com
sync -d b -e n C:/projects/_publish/jeffmackinnon.com/ /
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/author/ /author/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/category /category/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/feeds/ /feeds/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/images/ /images/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/pages/ /pages/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/photos/ /photos/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/tag/ /tag/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/theme/ /theme/
sync -d b -e n -r C:/projects/_publish/jeffmackinnon.com/videos/ /videos/
exit

If I only had the pelican based site on this server, I could simply use sync -d b -e n C:/projects/_publish/jeffmackinnon.com/ /, but since I have a lot of different sub-directories, etc, I needed to make it a bit longer.

So to go through everything that this does:

  • The first line connects to the bookmarked Filezilla jeffsite
  • lcd changes the local directory to where the files to be published is located.
  • The first sync line non-recursively syncs the root folder.
  • The remaining sync lines recursively syncs the pelican created folders
  • And finally I disconnect and exit from Filezilla CLI (fzcli).

Closing

I have only used this a couple times and haven't run into any issues. Some of the things that I would like to add to these scripts are logfiles and include some error catching.

I also want to figure out how to call a pipenv shell within a batch file and then continue, or call another batch file.

There are no comments here right now, so if you have requests/suggestions check me out on twitter.

This post is part 5 of the "How I Pelican" series:

  1. Installing Pelican for the first time again
  2. I updated a theme
  3. EXIF data with a pelican-photos Gallery
  4. Custom CSS per page or article with pelican
  5. Batch Files are your friend

To join a conversation on Twitter click here.