aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-25 23:33:13 +0200
committerneodarz <neodarz@neodarz.net>2019-05-25 23:33:13 +0200
commita8e56413815123b4bb10f3ddd597f42d11c8ad46 (patch)
treeadb03287655abeff06032028768ea82f8acafa8a
parentcba15003ea9e0df9ea81206e8e425f16f875bb0b (diff)
downloadmy_new_personal_website-a8e56413815123b4bb10f3ddd597f42d11c8ad46.tar.xz
my_new_personal_website-a8e56413815123b4bb10f3ddd597f42d11c8ad46.zip
Move init_colorama function to external file
-rwxr-xr-xpyblog23
-rw-r--r--utils/__init__.py0
-rw-r--r--utils/utils.py23
3 files changed, 26 insertions, 20 deletions
diff --git a/pyblog b/pyblog
index f4ae79ab..1511dce4 100755
--- a/pyblog
+++ b/pyblog
@@ -44,6 +44,8 @@ import toml
from rss import *
+from utils import utils
+
ROOTDIR = os.path.dirname(os.path.realpath(__file__))
@@ -96,25 +98,6 @@ WHITE = ""
YELLOW = ""
RESET = ""
-@contextmanager
-def init_colorama():
- """Set global foreground modifying ANSI codes.
-
- BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW, and RESET.
-
- """
-
- # pylint: disable=exec-used,invalid-name
-
- colorama.init()
- for color, ansi in colorama.Fore.__dict__.items():
- exec("global {0}; {0} = '{1}'".format(color, ansi))
- yield
- for color in colorama.Fore.__dict__:
- exec("global {0}; {0} = ''".format(color))
- colorama.deinit()
-
-
def current_datetime():
"""Return the current datetime, complete with tzinfo.
@@ -1723,7 +1706,7 @@ def main():
description="Bring up post selector to select post for editing.")
parser_new_post.set_defaults(func=edit_existing_post)
- with init_colorama():
+ with utils.init_colorama():
args = parser.parse_args()
returncode = args.func(args)
exit(returncode)
diff --git a/utils/__init__.py b/utils/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/utils/__init__.py
diff --git a/utils/utils.py b/utils/utils.py
new file mode 100644
index 00000000..a76beb5d
--- /dev/null
+++ b/utils/utils.py
@@ -0,0 +1,23 @@
+#!/bin/python3
+
+from contextlib import contextmanager
+import colorama
+
+
+@contextmanager
+def init_colorama():
+ """Set global foreground modifying ANSI codes.
+
+ BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW, and RESET.
+
+ """
+
+ # pylint: disable=exec-used,invalid-name
+
+ colorama.init()
+ for color, ansi in colorama.Fore.__dict__.items():
+ exec("global {0}; {0} = '{1}'".format(color, ansi))
+ yield
+ for color in colorama.Fore.__dict__:
+ exec("global {0}; {0} = ''".format(color))
+ colorama.deinit()