From a23bf5af6e7be3fcea03e4b81f4d54a2c916e087 Mon Sep 17 00:00:00 2001
From: neodarz <neodarz@neodarz.net>
Date: Sun, 26 May 2019 17:59:42 +0200
Subject: Move gen_deploy to external file

---
 pyblog | 63 +--------------------------------------------------------------
 1 file changed, 1 insertion(+), 62 deletions(-)

(limited to 'pyblog')

diff --git a/pyblog b/pyblog
index b4ff6391..54714e94 100755
--- a/pyblog
+++ b/pyblog
@@ -53,67 +53,6 @@ from generators import generators
 from cli import cli
 
 
-def gen_deploy(args):
-    """Regenerate and deploy."""
-    # pylint: disable=unused-argument,too-many-branches
-
-    # try to smartly determine the latest post, and prompt to touch it
-    current_time = time.time()
-    latest_post = None
-    latest_postdate = 0
-    latest_mtime = 0
-    for name in os.listdir(POSTSDIR):
-        matchobj = re.match(r"^([0-9]{4})-([0-9]{2})-([0-9]{2})-.*\.md", name)
-        if not matchobj:
-            continue
-        fullpath = os.path.join(POSTSDIR, name)
-        mtime = os.path.getmtime(fullpath)
-        # get post date from the date metadata field of the post
-        postdate = 0
-        with open(fullpath) as postobj:
-            for line in postobj:
-                dateregex = r"^date: (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:?\d{2})"
-                datematch = re.match(dateregex, line.rstrip())
-                if datematch:
-                    postdate = dateutil.parser.parse(datematch.group(1)).timestamp()
-                    break
-        # skip the post if it is dated more than three days ago
-        if current_time - postdate > 3 * 24 * 3600:
-            continue
-        if mtime > latest_mtime:
-            latest_post = name
-            latest_postdate = postdate
-            latest_mtime = mtime
-    # prompt for touching if the latest post determined above was
-    # modified within the last hour but the date registered in the post
-    # isn't within the last ten minutes
-    if ((latest_post is not None and current_time - latest_mtime < 3600 and
-         current_time - latest_postdate > 600)):
-        sys.stderr.write("%sIt appears that %s might be a new post.\n"
-                         "Do you want to touch its timestamp?%s\n" %
-                         (GREEN, latest_post, RESET))
-        while True:
-            yesnoquit = input("[ynq]: ")
-            if yesnoquit.startswith(("Y", "y")):
-                yesno = True
-                break
-            elif yesnoquit.startswith(("N", "n")):
-                yesno = False
-                break
-            elif yesnoquit.startswith(("Q", "q")):
-                sys.stderr.write("%saborting gen_deploy%s\n" % (RED, RESET))
-                return 1
-            else:
-                sys.stderr.write("Please answer yes, no, or quit.\n")
-        if yesno:
-            sys.stderr.write("%stouching %s%s\n" % (BLUE, latest_post, RESET))
-            cli.touch(latest_post)
-            sys.stderr.write("\n")
-
-    generators.generate_blog(fresh=True)
-    cli.deploy(None)
-
-
 class HTTPServerProcess(multiprocessing.Process):
     """This class can be used to run an HTTP server."""
 
@@ -424,7 +363,7 @@ def main():
     parser_new_post = subparsers.add_parser(
         "gen_deploy", aliases=["gd", "gendep"],
         description="Rebuild entire blog and deploy build/ to origin/master.")
-    parser_new_post.set_defaults(func=gen_deploy)
+    parser_new_post.set_defaults(func=cli.gen_deploy)
 
     parser_new_post = subparsers.add_parser(
         "edit", aliases=["e", "ed"],
-- 
cgit v1.2.1