aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 17:55:14 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 17:55:14 +0200
commit9bf107a102b8e6e9e199a5a93390c2a9c5cf9d53 (patch)
treeaf3ec23c6d93573f775639b82d0c35a75a01a281
parent699833d933157443b97218e9df378c9d52c66ec2 (diff)
downloadmy_new_personal_website-9bf107a102b8e6e9e199a5a93390c2a9c5cf9d53.tar.xz
my_new_personal_website-9bf107a102b8e6e9e199a5a93390c2a9c5cf9d53.zip
Move deploy to external file
-rw-r--r--cli/cli.py103
-rwxr-xr-xpyblog107
2 files changed, 105 insertions, 105 deletions
diff --git a/cli/cli.py b/cli/cli.py
index 232bca1b..5a386ed6 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -153,3 +153,106 @@ def touch(filename):
def touch_cli(args):
"""CLI wrapper around touch."""
touch(args.filename)
+
+
+def deploy(args):
+ """Deploys build directory to origin/master without regenerating.
+
+ Returns
+ -------
+ 0
+ On success. Exit early with nonzero status otherwise.
+
+ """
+
+ # pylint: disable=unused-argument,too-many-statements
+
+ # check whether root is dirty
+ os.chdir(ROOTDIR)
+ dirty = subprocess.check_output(["git", "status", "--porcelain"])
+ if dirty:
+ sys.stderr.write(YELLOW)
+ sys.stderr.write("Project root is dirty.\n")
+ sys.stderr.write("You may want to commit in your changes "
+ "to the source branch, since the SHA and title "
+ "of the latest commit on the source branch will be "
+ "incorporated into the commit message on "
+ "the deployment branch. Type s[hell] on the "
+ "next prompt to open an interactive shell.\n")
+ sys.stderr.write(RESET)
+ while True:
+ sys.stderr.write("Continue? [yNs] ")
+ answer = input()
+ if not answer:
+ # default
+ abort = True
+ break
+ elif answer.startswith(('y', 'Y')):
+ abort = False
+ break
+ elif answer.startswith(('n', 'N')):
+ abort = True
+ break
+ elif answer.startswith(('s', 'S')):
+ shell = (os.environ['SHELL'] if 'SHELL' in os.environ and os.environ['SHELL']
+ else 'zsh')
+ subprocess.call(shell)
+ stilldirty = subprocess.check_output(["git", "status", "--porcelain"])
+ if stilldirty:
+ sys.stderr.write(YELLOW)
+ sys.stderr.write("Project root is still dirty.\n")
+ sys.stderr.write(RESET)
+ else:
+ sys.stderr.write("Please answer yes or no.\n")
+ if abort:
+ sys.stderr.write("%saborting deployment%s\n" % (RED, RESET))
+ return 1
+
+ # extract latest commit on the source branch
+ source_commit = subprocess.check_output(
+ ["git", "log", "-1", "--pretty=oneline", "source", "--"]).decode('utf-8').strip()
+
+ # cd into BUILDDIR and assemble commit message
+ sys.stderr.write("%scommand: cd '%s'%s\n" % (BLUE, BUILDDIR, RESET))
+ os.chdir(BUILDDIR)
+
+ # extract updated time from atom.xml
+ if not os.path.exists("atom.xml"):
+ sys.stderr.write("atom.xml not found, cannot deploy\naborting\n")
+ return 1
+ atomxml = ET.parse("atom.xml").getroot()
+ updated = atomxml.find('{http://www.w3.org/2005/Atom}updated').text
+
+ commit_message = ("Site updated at %s\n\nsource branch was at:\n%s\n" %
+ (updated, source_commit))
+
+ # commit changes in BUILDDIR
+ sys.stderr.write("%scommand: git add --all%s\n" % (BLUE, RESET))
+ subprocess.check_call(["git", "add", "--all"])
+ sys.stderr.write("%scommand: git commit --no-verify --gpg-sign --message='%s'%s\n" %
+ (BLUE, commit_message, RESET))
+ try:
+ subprocess.check_call(["git", "commit", "--gpg-sign",
+ "--message=%s" % commit_message])
+ except subprocess.CalledProcessError:
+ sys.stderr.write("\n%serror: git commit failed%s\n" % (RED, RESET))
+ return 1
+
+ # check dirty status
+ dirty = subprocess.check_output(["git", "status", "--porcelain"])
+ if dirty:
+ sys.stderr.write(RED)
+ sys.stderr.write("error: failed to commit all changes; "
+ "build directory still dirty\n")
+ sys.stderr.write("error: please manually inspect what was left out\n")
+ sys.stderr.write(RESET)
+ return 1
+
+ # push to origin/master
+ sys.stderr.write("%scommand: git push origin master%s\n" % (BLUE, RESET))
+ try:
+ subprocess.check_call(["git", "push", "origin", "master"])
+ except subprocess.CalledProcessError:
+ sys.stderr.write("\n%serror: git push failed%s\n" % (RED, RESET))
+ return 1
+ return 0
diff --git a/pyblog b/pyblog
index 0eeb82b2..b4ff6391 100755
--- a/pyblog
+++ b/pyblog
@@ -53,109 +53,6 @@ from generators import generators
from cli import cli
-def deploy(args):
- """Deploys build directory to origin/master without regenerating.
-
- Returns
- -------
- 0
- On success. Exit early with nonzero status otherwise.
-
- """
-
- # pylint: disable=unused-argument,too-many-statements
-
- # check whether root is dirty
- os.chdir(ROOTDIR)
- dirty = subprocess.check_output(["git", "status", "--porcelain"])
- if dirty:
- sys.stderr.write(YELLOW)
- sys.stderr.write("Project root is dirty.\n")
- sys.stderr.write("You may want to commit in your changes "
- "to the source branch, since the SHA and title "
- "of the latest commit on the source branch will be "
- "incorporated into the commit message on "
- "the deployment branch. Type s[hell] on the "
- "next prompt to open an interactive shell.\n")
- sys.stderr.write(RESET)
- while True:
- sys.stderr.write("Continue? [yNs] ")
- answer = input()
- if not answer:
- # default
- abort = True
- break
- elif answer.startswith(('y', 'Y')):
- abort = False
- break
- elif answer.startswith(('n', 'N')):
- abort = True
- break
- elif answer.startswith(('s', 'S')):
- shell = (os.environ['SHELL'] if 'SHELL' in os.environ and os.environ['SHELL']
- else 'zsh')
- subprocess.call(shell)
- stilldirty = subprocess.check_output(["git", "status", "--porcelain"])
- if stilldirty:
- sys.stderr.write(YELLOW)
- sys.stderr.write("Project root is still dirty.\n")
- sys.stderr.write(RESET)
- else:
- sys.stderr.write("Please answer yes or no.\n")
- if abort:
- sys.stderr.write("%saborting deployment%s\n" % (RED, RESET))
- return 1
-
- # extract latest commit on the source branch
- source_commit = subprocess.check_output(
- ["git", "log", "-1", "--pretty=oneline", "source", "--"]).decode('utf-8').strip()
-
- # cd into BUILDDIR and assemble commit message
- sys.stderr.write("%scommand: cd '%s'%s\n" % (BLUE, BUILDDIR, RESET))
- os.chdir(BUILDDIR)
-
- # extract updated time from atom.xml
- if not os.path.exists("atom.xml"):
- sys.stderr.write("atom.xml not found, cannot deploy\naborting\n")
- return 1
- atomxml = ET.parse("atom.xml").getroot()
- updated = atomxml.find('{http://www.w3.org/2005/Atom}updated').text
-
- commit_message = ("Site updated at %s\n\nsource branch was at:\n%s\n" %
- (updated, source_commit))
-
- # commit changes in BUILDDIR
- sys.stderr.write("%scommand: git add --all%s\n" % (BLUE, RESET))
- subprocess.check_call(["git", "add", "--all"])
- sys.stderr.write("%scommand: git commit --no-verify --gpg-sign --message='%s'%s\n" %
- (BLUE, commit_message, RESET))
- try:
- subprocess.check_call(["git", "commit", "--gpg-sign",
- "--message=%s" % commit_message])
- except subprocess.CalledProcessError:
- sys.stderr.write("\n%serror: git commit failed%s\n" % (RED, RESET))
- return 1
-
- # check dirty status
- dirty = subprocess.check_output(["git", "status", "--porcelain"])
- if dirty:
- sys.stderr.write(RED)
- sys.stderr.write("error: failed to commit all changes; "
- "build directory still dirty\n")
- sys.stderr.write("error: please manually inspect what was left out\n")
- sys.stderr.write(RESET)
- return 1
-
- # push to origin/master
- sys.stderr.write("%scommand: git push origin master%s\n" % (BLUE, RESET))
- try:
- subprocess.check_call(["git", "push", "origin", "master"])
- except subprocess.CalledProcessError:
- sys.stderr.write("\n%serror: git push failed%s\n" % (RED, RESET))
- return 1
- return 0
-
-
def gen_deploy(args):
"""Regenerate and deploy."""
# pylint: disable=unused-argument,too-many-branches
@@ -214,7 +111,7 @@ def gen_deploy(args):
sys.stderr.write("\n")
generators.generate_blog(fresh=True)
- deploy(None)
+ cli.deploy(None)
class HTTPServerProcess(multiprocessing.Process):
@@ -522,7 +419,7 @@ def main():
parser_new_post = subparsers.add_parser(
"deploy", aliases=["d", "dep"],
description="Deploy build/ to origin/master without regenerating.")
- parser_new_post.set_defaults(func=deploy)
+ parser_new_post.set_defaults(func=cli.deploy)
parser_new_post = subparsers.add_parser(
"gen_deploy", aliases=["gd", "gendep"],