start on installer script

This commit is contained in:
Mike Young
2019-12-23 17:06:51 -05:00
parent 083f82fde1
commit 5b81252f4f
6 changed files with 99 additions and 14 deletions

View File

@@ -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/")

28
install vendored Executable file
View File

@@ -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

View File

@@ -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)

2
pyproject.toml vendored
View File

@@ -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"]

View File

@@ -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

View File

@@ -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)