mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
start on installer script
This commit is contained in:
@@ -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
28
install
vendored
Executable 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
|
||||
@@ -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
2
pyproject.toml
vendored
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
68
src/backend/lib/display.py
Normal file
68
src/backend/lib/display.py
Normal 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)
|
||||
Reference in New Issue
Block a user