install

installer
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/install

commit 5a62573815dcf6ab0359a2591240ee5cb90a941a
parent 3fb38e7fe99a0a4fab425fd8c601911afdf14e16
Author: louis.solofrizzo <louis.solofrizzo@stormshield.eu>
Date:   Fri, 21 Oct 2016 16:15:06 +0200

Add(Base): First code, base done.

Diffstat:
A.gitignore | 1+
Amain.py | 31+++++++++++++++++++++++++++++++
Ascreen.py | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascreens/__init__.py | 0
Ascreens/main/__init__.py | 0
Ascreens/main/main.py | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 242 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/main.py b/main.py @@ -0,0 +1,31 @@ +################################### LICENSE #################################### +# Copyright 2016 Louis Solofrizzo # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +## +# main.py +# Created: 21/10/2016 +# By: Louis Solofrizzo <louis@morphux.org> +## + +# Imports + +from screen import Screen + +def main(): + cur = Screen() + cur.loop() + +main() diff --git a/screen.py b/screen.py @@ -0,0 +1,99 @@ +################################### LICENSE #################################### +# Copyright 2016 Louis Solofrizzo # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +## +# curses.py +# Created: 21/10/2016 +# By: Louis Solofrizzo <louis@morphux.org> +## + +# Imports + +import curses +import os + +class Screen: + + # Variables + stdscr = {} + modules = {} + screens = {} + curr_screen = {} + + # Construct function + def __init__(self): + self.stdscr = curses.initscr() + curses.noecho() + curses.cbreak() + self.stdscr.keypad(1) + curses.start_color() + curses.curs_set(0) + self.load_screens() + self.init_colors() + + # Destructor function + def __del__(self): + curses.nocbreak() + self.stdscr.keypad(0) + curses.echo() + curses.curs_set(1) + os.system('stty sane') + os.system('clear') + + # Load differents modules in the path screens/ + def load_screens(self, path = "screens"): + res = {} + lst = os.listdir(path) + dir = [] + for d in lst: + s = os.path.abspath(path) + os.sep + d + if os.path.isdir(s) and os.path.exists(s + os.sep + "__init__.py"): + dir.append(d) + for d in dir: + res[d] = __import__(path + "." + d + "." + d, fromlist = ["*"]) + res[d] = getattr(res[d], d.title()) + self.modules = res + self.get_screens_infos() + + # Get infos on screens + def get_screens_infos(self): + config = {} + for name, klass in self.modules.items(): + print("Reading"+ name +"module...") + klass = klass() + config = klass.init() + self.screens[name] = klass + if config["title"] == "Main": + self.curr_screen = klass + print("Done !") + + def init_colors(self): + curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK) + + # Main Loop + def loop(self): + quit = 0 + key = 0 + self.curr_screen.refresh(self.stdscr) + self.stdscr.refresh() + while quit != -1: + if self.curr_screen.config["type"] == "menu": + key = self.stdscr.getch() + self.curr_screen.input(key) + self.stdscr.clear() + quit = self.curr_screen.refresh(self.stdscr) + self.stdscr.refresh() diff --git a/screens/__init__.py b/screens/__init__.py diff --git a/screens/main/__init__.py b/screens/main/__init__.py diff --git a/screens/main/main.py b/screens/main/main.py @@ -0,0 +1,111 @@ +################################### LICENSE #################################### +# Copyright 2016 Louis Solofrizzo # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +## +# main.py +# Created: 21/10/2016 +# By: Louis Solofrizzo <louis@morphux.org> +## + +import curses + +class Main: + + key = 0 + menu_s = ["INSTALL", "INSTALL 64BITS", "OPTIONS", "HELP", "QUIT"] + menu_choice = 0 + quit = 0 + title = " __ __ _ \n\ + | \\/ | | | \n\ + | \\ / | ___ _ __ _ __ | |__ _ ___ __\n\ + | |\\/| |/ _ \\| '__| '_ \\| '_ \\| | | \ \\/ /\n\ + | | | | (_) | | | |_) | | | | |_| |> < \n\ + |_| |_|\\___/|_| | .__/|_| |_|\\__,_/_/\\_\\\n\ + | | \n\ + |_| \n\ +" + + def init(self): + self.config = { + "id": 0, + "title": "Main", + "type": "menu" + } + return self.config + + def input(self, key): + self.key = key + if (key == curses.KEY_DOWN and self.menu_choice < len(self.menu_s) - 1): + self.menu_choice += 1 + elif (key == curses.KEY_UP and self.menu_choice > 0): + self.menu_choice -= 1 + elif (key == curses.KEY_ENTER or key == 10 or key == 13): + if (self.menu_s[self.menu_choice] == "QUIT"): + self.quit = -1 + else: + self.quit = self.menu_choice + + def print_title(self, win): + size = win.getmaxyx() + y = size[0] / 4; + x = (size[1] / 2) - (44 / 2) + for c in self.title: + win.addstr(y, x, c, curses.color_pair(2) | curses.A_BOLD) + x = x + 1 + if c == '\n': + y = y + 1 + x = (size[1] / 2) - (44 / 2) + return y + + def menu(self, y, win): + size = win.getmaxyx() + i = 0 + for string in self.menu_s: + if i == self.menu_choice: + win.addstr(y, (size[1] / 2) - (len(string) / 2), string, curses.color_pair(1) | curses.A_BOLD) + else: + win.addstr(y, (size[1] / 2) - (len(string) / 2), string) + y += 1 + i += 1 + + def print_borders(self, win, y, height): + size = win.getmaxyx() + c = "#" + i = 0 + while i < height: + win.addstr(y + i, (size[1] / 2) - (80 / 2), c) + i += 1 + i = 0 + while i < height + 1: + win.addstr(y + i, (size[1] / 2) + (80 / 2), c) + i += 1 + i = 0 + while i < 80: + win.addstr(y, (size[1] / 2) - (80 / 2) + i, c) + i += 1 + i = 0 + y += height + while i < 80: + win.addstr(y, (size[1] / 2) - (80 / 2) + i, c) + i += 1 + + def refresh(self, win): + size = win.getmaxyx() + y = self.print_title(win) + 1 + win.addstr(y, (size[1] / 2) - 8, "__Installer v1__", curses.A_REVERSE) + self.print_borders(win, y + 3, len(self.menu_s) + 5) + self.menu(y + 6, win); + return self.quit