aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 16:34:05 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 16:34:05 +0200
commit0e1fd56310060d269d798aadb80784651abcba0e (patch)
treecf9ac06121d9f402eb013db4b9a13e24b3732182
parent3fbed66ded190db27d67b006172f10bb03f54cc7 (diff)
downloadmy_new_personal_website-0e1fd56310060d269d798aadb80784651abcba0e.tar.xz
my_new_personal_website-0e1fd56310060d269d798aadb80784651abcba0e.zip
Move edit_post_with_editor to external file
-rw-r--r--cli/cli.py19
-rwxr-xr-xpyblog20
2 files changed, 21 insertions, 18 deletions
diff --git a/cli/cli.py b/cli/cli.py
index 33bd1422..4c9733b1 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -1,5 +1,8 @@
#/bin/python3
+import os
+import subprocess
+
from generators import generators
@@ -13,3 +16,19 @@ def regenerate(args):
"""Wrapper for generate_blog(fresh=True)."""
# pylint: disable=unused-argument
exit(generators.generate_blog(fresh=True))
+
+
+def edit_post_with_editor(path):
+ """Launch text editor to edit post at a given path.
+
+ Text editor is $VISUAL, then if empty, $EDITOR, then if still empty,
+ vi.
+
+ """
+ if "VISUAL" in os.environ:
+ editor = os.environ["VISUAL"]
+ elif "EDITOR" in os.environ:
+ editor = os.environ["EDITOR"]
+ else:
+ editor = "vi"
+ subprocess.call([editor, path])
diff --git a/pyblog b/pyblog
index de24d075..cf8a3bf1 100755
--- a/pyblog
+++ b/pyblog
@@ -53,22 +53,6 @@ from generators import generators
from cli import cli
-def edit_post_with_editor(path):
- """Launch text editor to edit post at a given path.
-
- Text editor is $VISUAL, then if empty, $EDITOR, then if still empty,
- vi.
-
- """
- if "VISUAL" in os.environ:
- editor = os.environ["VISUAL"]
- elif "EDITOR" in os.environ:
- editor = os.environ["EDITOR"]
- else:
- editor = "vi"
- subprocess.call([editor, path])
-
-
def new_post(title):
"""Create a new post with metadata pre-filled.
@@ -103,7 +87,7 @@ def new_post(title):
newpost.write("---\n\n")
sys.stderr.write("New post created in:\n")
print(fullpath)
- edit_post_with_editor(fullpath)
+ cli.edit_post_with_editor(fullpath)
return 0
@@ -598,7 +582,7 @@ def edit_existing_post(args):
selection = selector.select()
if selection:
print(selection)
- edit_post_with_editor(selection)
+ cli.edit_post_with_editor(selection)
else:
return 1