From 9b80a5ddb81644c17005cd846416fe0f7ae6f7b9 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Tue, 3 Dec 2019 13:15:58 -0500 Subject: [PATCH 1/4] Support --exclude-from for rsync publishing using excludes.txt Add an excludes.txt example file where users can list rsync exclude specifications. If the site you are publishing has any paths on the remote site that Pelican should ignore and not remove, list them in excludes.txt so they are not removed each time you do: make rsync_upload The example file has a comment pointing users to the rsync man page for information on the format used in exclude files. The only entry in it by default is the .DS_Store entry which was from the rsync command in tasks.py. --- pelican/tools/pelican_quickstart.py | 27 +++++++++++++++++++-- pelican/tools/templates/Makefile.jinja2 | 2 +- pelican/tools/templates/excludes.txt.jinja2 | 4 +++ pelican/tools/templates/tasks.py.jinja2 | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 pelican/tools/templates/excludes.txt.jinja2 diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 77657162..0eb031a5 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -391,8 +391,31 @@ needed by Pelican. render_jinja_template("publishconf.py.jinja2", CONF, "publishconf.py") if automation: - render_jinja_template("tasks.py.jinja2", CONF, "tasks.py") - render_jinja_template("Makefile.jinja2", CONF, "Makefile") + try: + with open(os.path.join(CONF['basedir'], 'tasks.py'), + 'w', 'utf-8') as fd: + _template = _jinja_env.get_template('tasks.py.jinja2') + fd.write(_template.render(**CONF)) + fd.close() + except OSError as e: + print('Error: {0}'.format(e)) + try: + with open(os.path.join(CONF['basedir'], 'Makefile'), + 'w', 'utf-8') as fd: + py_v = 'python3' + _template = _jinja_env.get_template('Makefile.jinja2') + fd.write(_template.render(py_v=py_v, **CONF)) + fd.close() + except OSError as e: + print('Error: {0}'.format(e)) + try: + with open(os.path.join(CONF['basedir'], 'excludes.txt'), + 'w', 'utf-8') as fd: + _template = _jinja_env.get_template('excludes.txt.jinja2') + fd.write(_template.render(**CONF)) + fd.close() + except OSError as e: + print('Error: {0}'.format(e)) print("Done. Your new project is available at {}".format(CONF["basedir"])) diff --git a/pelican/tools/templates/Makefile.jinja2 b/pelican/tools/templates/Makefile.jinja2 index 67571b47..b7d7812d 100644 --- a/pelican/tools/templates/Makefile.jinja2 +++ b/pelican/tools/templates/Makefile.jinja2 @@ -132,7 +132,7 @@ sftp_upload: publish {% set upload = upload + ["rsync_upload"] %} rsync_upload: publish - rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --include tags --cvs-exclude --delete "$(OUTPUTDIR)"/ "$(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR)" + rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --include tags --cvs-exclude --exclude-from=excludes.txt --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) {% endif %} {% if dropbox %} diff --git a/pelican/tools/templates/excludes.txt.jinja2 b/pelican/tools/templates/excludes.txt.jinja2 new file mode 100644 index 00000000..fbf831ca --- /dev/null +++ b/pelican/tools/templates/excludes.txt.jinja2 @@ -0,0 +1,4 @@ +# Files to exclude with rsync(1) during publishing. +# See the INCLUDE/EXCLUDE PATTERN RULES section of the rsync man page. + +.DS_Store diff --git a/pelican/tools/templates/tasks.py.jinja2 b/pelican/tools/templates/tasks.py.jinja2 index 26af6f0d..a20f93e3 100644 --- a/pelican/tools/templates/tasks.py.jinja2 +++ b/pelican/tools/templates/tasks.py.jinja2 @@ -169,7 +169,7 @@ def publish(c): """Publish to production via rsync""" pelican_run("-s {settings_publish}".format(**CONFIG)) c.run( - 'rsync --delete --exclude ".DS_Store" -pthrvz -c ' + 'rsync --delete --exclude-from=excludes.txt -pthrvz -c ' '-e "ssh -p {ssh_port}" ' "{} {ssh_user}@{ssh_host}:{ssh_path}".format( CONFIG["deploy_path"].rstrip("/") + "/", **CONFIG From 2a5b826180e501412e924246814248ad80518214 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Tue, 3 Dec 2019 15:12:26 -0500 Subject: [PATCH 2/4] excludes.txt -> rsync_excludes.txt (#2659) Give the rsync excludes file a bit more of a descriptive name. --- pelican/tools/pelican_quickstart.py | 4 ++-- pelican/tools/templates/Makefile.jinja2 | 2 +- .../{excludes.txt.jinja2 => rsync_excludes.txt.jinja2} | 0 pelican/tools/templates/tasks.py.jinja2 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename pelican/tools/templates/{excludes.txt.jinja2 => rsync_excludes.txt.jinja2} (100%) diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 0eb031a5..134b16fb 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -409,9 +409,9 @@ needed by Pelican. except OSError as e: print('Error: {0}'.format(e)) try: - with open(os.path.join(CONF['basedir'], 'excludes.txt'), + with open(os.path.join(CONF['basedir'], 'rsync_excludes.txt'), 'w', 'utf-8') as fd: - _template = _jinja_env.get_template('excludes.txt.jinja2') + _template = _jinja_env.get_template('rsync_excludes.txt.jinja2') fd.write(_template.render(**CONF)) fd.close() except OSError as e: diff --git a/pelican/tools/templates/Makefile.jinja2 b/pelican/tools/templates/Makefile.jinja2 index b7d7812d..6e4d4052 100644 --- a/pelican/tools/templates/Makefile.jinja2 +++ b/pelican/tools/templates/Makefile.jinja2 @@ -132,7 +132,7 @@ sftp_upload: publish {% set upload = upload + ["rsync_upload"] %} rsync_upload: publish - rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --include tags --cvs-exclude --exclude-from=excludes.txt --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) + rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --include tags --cvs-exclude --exclude-from=rsync_excludes.txt --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) {% endif %} {% if dropbox %} diff --git a/pelican/tools/templates/excludes.txt.jinja2 b/pelican/tools/templates/rsync_excludes.txt.jinja2 similarity index 100% rename from pelican/tools/templates/excludes.txt.jinja2 rename to pelican/tools/templates/rsync_excludes.txt.jinja2 diff --git a/pelican/tools/templates/tasks.py.jinja2 b/pelican/tools/templates/tasks.py.jinja2 index a20f93e3..8e047104 100644 --- a/pelican/tools/templates/tasks.py.jinja2 +++ b/pelican/tools/templates/tasks.py.jinja2 @@ -169,7 +169,7 @@ def publish(c): """Publish to production via rsync""" pelican_run("-s {settings_publish}".format(**CONFIG)) c.run( - 'rsync --delete --exclude-from=excludes.txt -pthrvz -c ' + 'rsync --delete --exclude-from=rsync_excludes.txt -pthrvz -c ' '-e "ssh -p {ssh_port}" ' "{} {ssh_user}@{ssh_host}:{ssh_path}".format( CONFIG["deploy_path"].rstrip("/") + "/", **CONFIG From 283a8b9c9ff1d86ec5427516f8d161d8868ca3eb Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Tue, 3 Dec 2019 16:39:50 -0500 Subject: [PATCH 3/4] Remove rsync_excludes.txt.jinja2, just make it a string. (#2659) No need to have this file be a template. It can just be written out as a string. --- pelican/tools/pelican_quickstart.py | 10 ++++++++-- pelican/tools/templates/rsync_excludes.txt.jinja2 | 4 ---- 2 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 pelican/tools/templates/rsync_excludes.txt.jinja2 diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 134b16fb..7ff3c67a 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -86,6 +86,13 @@ class _DEFAULT_PATH_TYPE(str): # noqa: SLOT000 _DEFAULT_PATH = _DEFAULT_PATH_TYPE(os.curdir) +RSYNC_EXCLUDES = """\ +# Files to exclude with rsync(1) during publishing. +# See the INCLUDE/EXCLUDE PATTERN RULES section of the rsync man page. + +.DS_Store +""" + def ask(question, answer=str, default=None, length=None): if answer is str: r = "" @@ -411,8 +418,7 @@ needed by Pelican. try: with open(os.path.join(CONF['basedir'], 'rsync_excludes.txt'), 'w', 'utf-8') as fd: - _template = _jinja_env.get_template('rsync_excludes.txt.jinja2') - fd.write(_template.render(**CONF)) + fd.write(RSYNC_EXCLUDES) fd.close() except OSError as e: print('Error: {0}'.format(e)) diff --git a/pelican/tools/templates/rsync_excludes.txt.jinja2 b/pelican/tools/templates/rsync_excludes.txt.jinja2 deleted file mode 100644 index fbf831ca..00000000 --- a/pelican/tools/templates/rsync_excludes.txt.jinja2 +++ /dev/null @@ -1,4 +0,0 @@ -# Files to exclude with rsync(1) during publishing. -# See the INCLUDE/EXCLUDE PATTERN RULES section of the rsync man page. - -.DS_Store From 59e2702c8529e9af51c0556afd97ed0aef6c5cbf Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Tue, 3 Dec 2019 16:51:18 -0500 Subject: [PATCH 4/4] Fix flake8 E302 in pelican_quickstart.py --- pelican/tools/pelican_quickstart.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 7ff3c67a..cb3ac807 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -93,6 +93,7 @@ RSYNC_EXCLUDES = """\ .DS_Store """ + def ask(question, answer=str, default=None, length=None): if answer is str: r = ""