diff --git a/__init__.py b/__init__.py index 9171045..21575c2 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,4 @@ import sys -sys.path.insert(1, "app/") -sys.path.insert(2, "frontend/") +# sys.path.insert(1, "app/") +# sys.path.insert(2, "frontend/") diff --git a/install b/install new file mode 100755 index 0000000..f469338 --- /dev/null +++ b/install @@ -0,0 +1,28 @@ +#!/usr/bin/python +import json +import pathlib + +from src.backend.lib.config import Config +from src.backend.lib.display import TerminalDisplay + +PRG_PATH = pathlib.Path.cwd() +LIB_PATH = pathlib.Path.joinpath(PRG_PATH, "src", "backend", "lib") +# sys.path.insert(0, PRG_PATH) + +TerminalDisplay().installer() + + +class Configuration: + def __init__(self): + _cp = pathlib.Path("config.json") + _data = self.open_file() + + def open_file(self): + with open(str(self._cp), "r") as read_file: + data = json.load(read_file) + return data + + def write_file(self, data): + with open(str(self._cp), "rw") as write_file: + json.dumps(write_file) + return True diff --git a/install.py b/install.py deleted file mode 100644 index 04bdeb3..0000000 --- a/install.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/python - -import pathlib -import sys - -PRG_PATH = pathlib.Path.cwd() -LIB_PATH = pathlib.Path.joinpath(PRG_PATH, "src", "backend", "lib") -sys.path.insert(0, PRG_PATH) diff --git a/pyproject.toml b/pyproject.toml index 2db2a64..ad507ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,4 +7,4 @@ use_parentheses = true # NOTE: the known_third_party setting is managed by # seed-isort-config and should not be modified directly. # Any changes made to this setting will be overwritten. -known_third_party = ["backend", "bs4", "django", "interface", "psycopg2", "requests"] +known_third_party = ["backend", "bs4", "django", "interface", "prompt_toolkit", "psycopg2", "requests"] diff --git a/src/backend/lib/config.py b/src/backend/lib/config.py index a78054d..c36c0c3 100755 --- a/src/backend/lib/config.py +++ b/src/backend/lib/config.py @@ -22,8 +22,6 @@ class Config: self.VERSION = _data["VERSION"] self.TITLE = self.TITLE + " ver " + self.VERSION self.book_shelf = _data["BOOKSHELF"] - # self.catalogue_db = "data/catalogue.db" - # self.catalogue_db = str(root) + "/" + _data["DATABASE"] self.catalogue_db = _data["DATABASE"] self.user = _data["USER"] self.password = _data["PASSWORD"] @@ -31,7 +29,6 @@ class Config: self.db_port = _data["DB_PORT"] self.file_array = [ self.book_shelf, - # self.catalogue_db, ] self.root = root self.auto_scan = True diff --git a/src/backend/lib/display.py b/src/backend/lib/display.py new file mode 100644 index 0000000..70d6381 --- /dev/null +++ b/src/backend/lib/display.py @@ -0,0 +1,68 @@ +from __future__ import unicode_literals + +import os +import sys +from pprint import pprint + +from prompt_toolkit import prompt as prm + + +class TerminalDisplay: + def __init__(self): + self.term = True + self.w, self.y = os.get_terminal_size()[0], os.get_terminal_size()[1] + + def screen(self): + return self.term + + def installer(self): + questions = [ + { + "message": "Input the absolute path to your ebooks\nEg. /home/{user}/Books > ", + "options": "", + "name": "BOOKPATH", + "answer": "", + }, + { + "message": "Input your PostgreSQL server ip\nEg. localhost > ", + "options": "localhost", + "name": "DB_HOST", + "answer": "", + }, + { + "message": "Input your PostgreSQL server port\nEg. 5432 > ", + "options": "5432", + "name": "DB_PORT", + "answer": "", + }, + { + "message": "Input your PostgreSQL user name\nEg. pyshelf > ", + "options": "pyshelf", + "name": "USER", + "answer": "", + }, + { + "message": "Input your PostgreSQL password\neg. pyshelf > ", + "options": "pyshelf", + "name": "PASSWORD", + "answer": "", + }, + ] + answers = self.prompt(questions) + pprint(answers) + + @staticmethod + def clear(): + os.system("cls" if os.name == "nt" else "clear") + + def prompt(self, questions): + self.clear() + answers = questions + for answer in answers: + self.h_rule() + answer["answer"] = prm(answer["message"]) + self.clear() + return answers + + def h_rule(self): + print("\u2501" * self.w)