mirror of
https://git.ari.lt/ari.lt/blog.ari.lt.git
synced 2025-02-04 09:39:25 +01:00
update @ Wed 17 Aug 01:51:03 EEST 2022
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
parent
27c4d86aa6
commit
8454f452ce
1 changed files with 22 additions and 19 deletions
41
scripts/blog
41
scripts/blog
|
@ -5,10 +5,8 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import readline
|
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
from atexit import register as fn_register
|
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from glob import iglob
|
from glob import iglob
|
||||||
|
@ -25,6 +23,12 @@ from markdown import markdown # type: ignore
|
||||||
from plumbum.commands.processes import ProcessExecutionError # type: ignore
|
from plumbum.commands.processes import ProcessExecutionError # type: ignore
|
||||||
from pyfzf import FzfPrompt # type: ignore
|
from pyfzf import FzfPrompt # type: ignore
|
||||||
|
|
||||||
|
NOT_CI_BUILD: bool = not os.getenv("CI")
|
||||||
|
|
||||||
|
if NOT_CI_BUILD:
|
||||||
|
import readline
|
||||||
|
from atexit import register as fn_register
|
||||||
|
|
||||||
EXIT_OK: int = 0
|
EXIT_OK: int = 0
|
||||||
EXIT_ERR: int = 1
|
EXIT_ERR: int = 1
|
||||||
|
|
||||||
|
@ -695,21 +699,23 @@ def usage(code: int = EXIT_ERR, config: Dict = None) -> int:
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
"""Entry/main function"""
|
"""Entry/main function"""
|
||||||
|
|
||||||
if not os.path.isfile(HISTORY_FILE):
|
if NOT_CI_BUILD:
|
||||||
open(HISTORY_FILE, "w").close()
|
if not os.path.isfile(HISTORY_FILE):
|
||||||
|
open(HISTORY_FILE, "w").close()
|
||||||
|
|
||||||
readline.parse_and_bind("tab: complete")
|
readline.parse_and_bind("tab: complete")
|
||||||
|
|
||||||
fn_register(readline.write_history_file, HISTORY_FILE)
|
fn_register(readline.write_history_file, HISTORY_FILE)
|
||||||
fn_register(readline.read_history_file, HISTORY_FILE)
|
fn_register(readline.read_history_file, HISTORY_FILE)
|
||||||
|
|
||||||
readline.read_history_file(HISTORY_FILE)
|
readline.read_history_file(HISTORY_FILE)
|
||||||
readline.set_history_length(5000)
|
readline.set_history_length(5000)
|
||||||
|
|
||||||
readline.set_auto_history(False)
|
readline.set_auto_history(False)
|
||||||
|
|
||||||
if not os.path.isfile(DEFAULT_CONFIG_FILE):
|
if not os.path.isfile(DEFAULT_CONFIG_FILE):
|
||||||
new_config()
|
new_config()
|
||||||
|
log(f"PLease configure {DEFAULT_CONFIG_FILE!r}")
|
||||||
return EXIT_ERR
|
return EXIT_ERR
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
|
@ -729,9 +735,7 @@ def main() -> int:
|
||||||
"TIME",
|
"TIME",
|
||||||
)
|
)
|
||||||
|
|
||||||
not_ci_build = not os.getenv("CI")
|
if config["blogs"] and NOT_CI_BUILD:
|
||||||
|
|
||||||
if config["blogs"] and not_ci_build:
|
|
||||||
log("Sorting blogs by creation time...", "CLEANUP")
|
log("Sorting blogs by creation time...", "CLEANUP")
|
||||||
|
|
||||||
sort_timer = code_timer()
|
sort_timer = code_timer()
|
||||||
|
@ -745,15 +749,14 @@ def main() -> int:
|
||||||
|
|
||||||
log(f"Sorted in {code_timer() - sort_timer} seconds", "TIME")
|
log(f"Sorted in {code_timer() - sort_timer} seconds", "TIME")
|
||||||
|
|
||||||
if not_ci_build:
|
log("Redumping config", "CONFIG")
|
||||||
log("Redumping config", "CONFIG")
|
|
||||||
|
|
||||||
dump_timer = code_timer()
|
dump_timer = code_timer()
|
||||||
|
|
||||||
with open(DEFAULT_CONFIG_FILE, "w") as dcfg:
|
with open(DEFAULT_CONFIG_FILE, "w") as dcfg:
|
||||||
json.dump(config, dcfg, indent=4)
|
json.dump(config, dcfg, indent=(4 if NOT_CI_BUILD else 0))
|
||||||
|
|
||||||
log(f"Dumped config in {code_timer() - dump_timer} seconds", "TIME")
|
log(f"Dumped config in {code_timer() - dump_timer} seconds", "TIME")
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue