aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/baseline.sh33
-rwxr-xr-xscripts/document_path_handlers.py6
-rwxr-xr-xscripts/generate_symlinked_list.sh8
-rwxr-xr-xscripts/getbaseline.sh14
-rwxr-xr-xscripts/github-release.py20
-rwxr-xr-xscripts/jinjify.py36
-rwxr-xr-xscripts/langstatus.py22
-rwxr-xr-xscripts/release159
-rwxr-xr-xscripts/set_version.py47
9 files changed, 273 insertions, 72 deletions
diff --git a/scripts/baseline.sh b/scripts/baseline.sh
new file mode 100755
index 0000000..2553a07
--- /dev/null
+++ b/scripts/baseline.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+PYVER=$(scripts/getpyver.py short)
+if [[ $PYVER == '3.5' || $PYVER == '2.7' ]]; then
+ if [[ "$1" == "check" ]]; then
+ echo -e "\033[36m>> Downloading baseline for $PYVER...\033[0m"
+ # we only support 2.7 and 3.5
+ wget https://github.com/getnikola/invariant-builds/archive/v$PYVER'.zip'
+ unzip -q 'v'$PYVER'.zip'
+ rm -rf baseline$PYVER
+ mv invariant-builds-$PYVER baseline
+ rm 'v'$PYVER'.zip'
+ fi
+else
+ echo -e "\033[35m>> Version $PYVER does not support baseline testing.\033[0m"
+ exit 0
+fi
+nikola init -qd nikola-baseline-build
+cd nikola-baseline-build
+cp ../tests/data/1-nolinks.rst posts/1.rst
+rm "pages/creating-a-theme.rst" "pages/extending.txt" "pages/internals.txt" "pages/manual.rst" "pages/social_buttons.txt" "pages/theming.rst" "pages/path_handlers.txt" "pages/charts.txt"
+LC_ALL='en_US.UTF-8' PYTHONHASHSEED=0 nikola build --invariant
+if [[ "$1" == "check" ]]; then
+ echo -e "\033[36m>> Testing baseline...\033[0m"
+ diff -ubwr ../baseline output
+ if [[ $? == 0 ]]; then
+ echo -e "\033[32;1m>> Baseline test successful\033[0m"
+ else
+ CODE=$?
+ echo -e "\033[31;1m>> Failed with exit code $CODE\033[0m"
+ echo "If this change was intentional, the baseline site needs to be rebuilt (maintainers only). Otherwise, please fix this issue."
+ exit $CODE
+ fi
+fi
diff --git a/scripts/document_path_handlers.py b/scripts/document_path_handlers.py
index 692c8e0..4c2e378 100755
--- a/scripts/document_path_handlers.py
+++ b/scripts/document_path_handlers.py
@@ -9,8 +9,8 @@ print(""".. title: Path Handlers for Nikola
.. slug: path-handlers
.. author: The Nikola Team
-Nikola supports special links with the syntax ``link://kind/name``. Here is
-the description for all the supported kinds.
+Nikola supports special links with the syntax ``link://kind/name``. In the templates you can also
+use ``_link(kind, name)`` Here is the description for all the supported kinds.
.. class:: dl-horizontal
""")
@@ -18,5 +18,5 @@ the description for all the supported kinds.
for k in sorted(n.path_handlers.keys()):
v = n.path_handlers[k]
print(k)
- print('\n'.join(' '+l.strip() for l in v.__doc__.splitlines()))
+ print('\n'.join(' ' + l.strip() for l in v.__doc__.splitlines()))
print()
diff --git a/scripts/generate_symlinked_list.sh b/scripts/generate_symlinked_list.sh
index fe7a7cc..56f514b 100755
--- a/scripts/generate_symlinked_list.sh
+++ b/scripts/generate_symlinked_list.sh
@@ -6,4 +6,12 @@ WDir="${PWD##*/}"
[[ $WDir == 'scripts' ]] && cd ..
dst='nikola/data/symlinked.txt'
+
+# Remove stale symlinks
+for f in $(git ls-files -s | awk '/120000/{print $4}'); do
+ if [[ ! -e $f ]]; then
+ git rm -f $f
+ fi
+done
+
git ls-files -s | awk '/120000/{print $4}' > $dst
diff --git a/scripts/getbaseline.sh b/scripts/getbaseline.sh
deleted file mode 100755
index 9006579..0000000
--- a/scripts/getbaseline.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-cd tests/data
-for i in $@; do
- if [[ $i == '3.5' || $i == '2.7' ]]; then
- # we only support 2.7 and 3.5
- wget https://github.com/getnikola/invariant-builds/archive/v$i'.zip'
- unzip 'v'$i'.zip'
- rm -rf baseline$i
- mv invariant-builds-$i baseline$i
- rm 'v'$i'.zip'
- else
- echo 'Version '$i' does not support baseline testing.'
- fi
-done
diff --git a/scripts/github-release.py b/scripts/github-release.py
index 8280fda..a9ab898 100755
--- a/scripts/github-release.py
+++ b/scripts/github-release.py
@@ -1,7 +1,7 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import subprocess
-import sys
import os
+import argparse
if not os.path.exists('.pypt/gh-token'):
print("To use this script, you must create a GitHub token first.")
@@ -9,11 +9,19 @@ if not os.path.exists('.pypt/gh-token'):
print("Then, put it in a file named .pypt/gh-token")
exit(1)
-inpf = input if sys.version_info[0] == 3 else raw_input
+parser = argparse.ArgumentParser(description="GitHub Release helper")
+parser.add_argument("FILE", nargs=1, help="Markdown file to use")
+parser.add_argument("TAG", nargs=1, help="Tag name (usually vX.Y.Z)")
+
+args = parser.parse_args()
+
+if not args.TAG[0].startswith("v"):
+ print("WARNING: tag should start with v")
+ i = input("Add `v` to tag? [y/n] ")
+ if i.lower().strip().startswith('y'):
+ args.TAG[0] = 'v' + args.TAG[0]
-FILE = inpf("Markdown file to use: ")
BASEDIR = os.getcwd()
REPO = 'getnikola/nikola'
-TAG = inpf("Tag name (usually vX.Y.Z): ")
-subprocess.call(['.pypt/ghrel', FILE, BASEDIR, REPO, TAG])
+subprocess.call(['.pypt/ghrel', args.FILE[0], BASEDIR, REPO, args.TAG[0]])
diff --git a/scripts/jinjify.py b/scripts/jinjify.py
index 3a3a9d8..8f14323 100755
--- a/scripts/jinjify.py
+++ b/scripts/jinjify.py
@@ -6,6 +6,7 @@ import os
import re
import json
import shutil
+import tempfile
import colorama
import jinja2
@@ -216,6 +217,24 @@ def mako2jinja(input_file):
return output
+
+def jinjify_shortcodes(in_dir, out_dir):
+ for fname in os.listdir(in_dir):
+ if not fname.endswith('.tmpl'):
+ continue
+ in_file = os.path.join(in_dir, fname)
+ out_file = os.path.join(out_dir, fname)
+ with open(in_file) as inf:
+ data = mako2jinja(inf)
+ with open(out_file, 'w') as outf:
+ outf.write(data)
+
+
+def usage():
+ print("Usage: python {} [in-dir] [out-dir]".format(sys.argv[0]))
+ print("OR")
+ print("Usage: python {} [in-file] [out-file]".format(sys.argv[0]))
+
if __name__ == "__main__":
if len(sys.argv) == 1:
print('Performing standard conversions:')
@@ -225,7 +244,20 @@ if __name__ == "__main__":
):
print(' {0} -> {1}'.format(m, j))
jinjify(m, j)
+ jinjify_shortcodes('nikola/data/shortcodes/mako', 'nikola/data/shortcodes/jinja')
elif len(sys.argv) != 3:
- print('ERROR: needs input and output directory, or no arguments for default conversions.')
- else:
+ print('ERROR: needs input and output directory (file), or no arguments for default conversions.')
+ usage()
+ elif os.path.isdir(sys.argv[1]) and (os.path.isdir(sys.argv[2]) or not os.path.exists(sys.argv[2])):
jinjify(sys.argv[1], sys.argv[2])
+ elif os.path.isfile(sys.argv[1]) and (os.path.isfile(sys.argv[2]) or not os.path.exists(sys.argv[2])):
+ tmpdir = tempfile.mkdtemp()
+ indir = os.path.sep.join((tmpdir, 'in', 'templates'))
+ outdir = os.path.sep.join((tmpdir, 'out', 'templates'))
+ os.makedirs(indir)
+ shutil.copy(sys.argv[1], indir)
+ jinjify(os.path.dirname(indir), os.path.dirname(outdir))
+ shutil.move(os.path.sep.join((outdir, os.path.basename(sys.argv[1]))), sys.argv[2])
+ else:
+ print('ERROR: the two arguments must be both directories or files')
+ usage()
diff --git a/scripts/langstatus.py b/scripts/langstatus.py
new file mode 100755
index 0000000..c31067d
--- /dev/null
+++ b/scripts/langstatus.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+import nikola.nikola
+import os.path
+import glob
+
+used = []
+exist = []
+for tr in nikola.nikola.LEGAL_VALUES['TRANSLATIONS']:
+ if isinstance(tr, tuple):
+ used.append(tr[0])
+ used.append(tr)
+
+for file in glob.glob(os.path.join('nikola', 'data', 'themes', 'base',
+ 'messages', 'messages_*.py')):
+ lang = file.split('_', 1)[1][:-3]
+ exist.append(lang)
+ if lang in used:
+ print('{0}: found'.format(lang))
+ elif os.path.islink(file):
+ print('\x1b[1;1m\x1b[1;30m{0}: symlink\x1b[0m'.format(lang))
+ else:
+ print('\x1b[1;1m\x1b[1;31m{0}: NOT found\x1b[0m'.format(lang))
diff --git a/scripts/release b/scripts/release
new file mode 100755
index 0000000..ce7b49e
--- /dev/null
+++ b/scripts/release
@@ -0,0 +1,159 @@
+#!/bin/zsh
+# The Release Script
+# Based on Python Project Template by Chris Warrick
+# Copyright © 2013-2016, Chris Warrick.
+# All rights reserved.
+
+# Permission is hereby granted, free of charge, to any
+# person obtaining a copy of this software and associated
+# documentation files (the "Software"), to deal in the
+# Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the
+# Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice
+# shall be included in all copies or substantial portions of
+# the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+function status {
+ echo $@
+}
+
+function warning {
+ echo 'WARNING: '$@
+}
+
+function error {
+ echo 'ERROR: '$@
+}
+
+function cleanup {
+ rm -rf Nikola.egg-info build || true
+ rm -rf **/__pycache__ || true
+}
+
+status '*** Nikola Release Scripts'
+dates=$(date '+%s')
+
+# Make sure we're up-to-date
+git checkout master
+git pull origin master
+
+echo -n "Version (in format X.Y.Z): "
+read version
+
+echo $version | grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$' > /dev/null
+
+if [[ $? != 0 ]]; then
+ echo $version | grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\-[0-9A-Za-z-]\{1,\}$' > /dev/null
+ if [[ $? != 0 ]]; then
+ warning 'version number is not compliant with versioning scheme (Semantic Versioning 2.0)'
+ echo -n 'Continue? [y/N] '
+ read vercont
+ if [[ $vercont == 'y' || $vercont == 'Y' ]]; then
+ echo 'Continuing.'
+ else
+ exit 2
+ fi
+ else
+ status 'NOTICE: pre-release version number in use.'
+ echo -n 'Continue? [Y/n] '
+ read vercont
+ if [[ $vercont == 'n' || $vercont == 'N' ]]; then
+ exit 2
+ else
+ echo 'Continuing.'
+ fi
+ fi
+fi
+
+
+cleanup
+
+status 'Replacing versions in files...'
+
+sed "s/version=.*/version='$version',/g" setup.py -i
+sed "s/version = .*/version = '$version'/g" docs/sphinx/conf.py -i
+sed "s/release = .*/release = '$version'/g" docs/sphinx/conf.py -i
+sed "s/:Version: .*/:Version: $version/g" docs/*.txt docs/*.rst -i
+sed "s/:Version: .*/:Version: Nikola $version/g" docs/man/nikola.rst -i
+sed "s/__version__ = .*/__version__ = '$version'/g" nikola/__init__.py -i
+sed "s/version: .*/version: $version/g" snapcraft/stable/snapcraft.yaml -i
+sed "s/source-tag: .*/source-tag: v$version/g" snapcraft/stable/snapcraft.yaml -i
+sed "s/Nikola==.*'/Nikola==$version'/g" snapcraft/nikola.py -i
+
+setopt errexit # Exit on errors
+
+# Slightly convoluted underline automation
+underline=$(python -c "import sys; sys.stdout.write((len('v$version')) * '=')")
+perl -0777 -i -pe "s/master\n======/v$version\n$underline/" CHANGES.txt
+# Man pages
+rst2man.py docs/man/nikola.rst > docs/man/nikola.1
+gzip -f docs/man/nikola.1
+
+status 'Updating path handler documentation...'
+scripts/document_path_handlers.py > docs/path_handlers.txt
+status 'Updating Jinja2 templates...'
+scripts/jinjify.py
+status 'Updating Bower...'
+scripts/update-bower.sh
+status 'Updating symlinked list...'
+scripts/generate_symlinked_list.sh
+status 'Updating website (conf.py and docs)...'
+scripts/generate_conf.py > ../nikola-site/listings/conf.py
+cp AUTHORS.txt CHANGES.txt ../nikola-site/stories
+cp docs/*.* ../nikola-site/stories
+sed 's/Nikola v[0-9\.A_Za-z-]\{1,\}/Nikola'" v$version/g" ../nikola-site/stories/conf.txt -i
+status 'Generating locales...'
+scripts/import_po.py
+status 'List of locales:'
+scripts/langstatus.py
+
+unsetopt errexit
+
+status 'If any locales are shown as "NOT found" and they have full translations, please add them in nikola.py. Check this in another terminal (or not) and press Enter to continue.'
+read localefix
+
+status 'Importing...'
+python -c "import nikola"
+if [[ $? == 1 ]]; then
+ error "Import failed. Fix your code or don't come back."
+ exit 1
+fi
+
+status 'This is the last chance to quit. Hit ^C now if you want to.'
+read bailout
+
+cleanup
+
+./setup.py sdist bdist_wheel || exit $?
+twine upload -s dist/Nikola-$version.tar.gz dist/Nikola-$version*.whl || exit $?
+
+cleanup
+
+git add -A --ignore-errors . || exit $?
+
+git commit -S -asm "Version $version" || exit $?
+git tag -sm "Version $version" v$version || exit $?
+git push --follow-tags origin master || exit $?
+
+status "Done!"
+
+echo "Next steps (see Release Checklist):"
+echo " * Write announcements, create blog posts"
+echo " * Create a GitHub release"
+echo " * Update GitHub Issues milestones"
+echo " * Update Nikola’s website"
+echo " * Send out announcement e-mails"
+echo " * Update AUR PKGBUILDs"
diff --git a/scripts/set_version.py b/scripts/set_version.py
deleted file mode 100755
index 7e6c3e0..0000000
--- a/scripts/set_version.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""Script to set the version number wherever it's needed before a release."""
-
-from __future__ import unicode_literals, print_function
-import io
-import os
-import re
-import sys
-import glob
-import subprocess
-import io
-
-
-def sed_like_thing(pattern, repl, path):
- """Like re.sub but applies to a file instead of a string."""
-
- with io.open(path, 'r', encoding='utf8') as inf:
- data = inf.read()
-
- data = re.sub(pattern, repl, data)
-
- with io.open(path, 'w+', encoding='utf8') as outf:
- outf.write(data)
-
-if __name__ == "__main__":
- inpf = raw_input if sys.version_info[0] == 2 else input
- version = inpf("New version number (in format X.Y.Z): ").strip()
-
- for doc in glob.glob(os.path.join("docs/*.txt")):
- sed_like_thing(":Version: .*", ":Version: {0}".format(version), doc)
-
- sed_like_thing("version='.+'", "version='{0}'".format(version), 'setup.py')
- sed_like_thing("version = .*", "version = '{0}'".format(version), os.path.join('docs', 'sphinx', 'conf.py'))
- sed_like_thing("release = .*", "release = '{0}'".format(version), os.path.join('docs', 'sphinx', 'conf.py'))
- sed_like_thing('__version__ = ".*"', '__version__ = "{0}"'.format(version), os.path.join('nikola', '__init__.py'))
- sed_like_thing('New in master', 'New in v{0}'.format(version), 'CHANGES.txt')
- sed_like_thing(':Version: .*', ':Version: Nikola v{0}'.format(version), os.path.join('docs', 'man', 'nikola.rst'))
- man = subprocess.check_output(["rst2man", os.path.join('docs', 'man', 'nikola.rst')])
- with io.open(os.path.join('docs', 'man', 'nikola.1'), 'w', encoding='utf-8') as fh:
- try:
- man = man.decode('utf-8')
- except AttributeError:
- pass
- fh.write(man)
- subprocess.call(["gzip", "-f", os.path.join('docs', 'man', 'nikola.1')])