diff options
author | Christos.K <freedomrfox@gmail.com> | 2017-10-09 17:55:26 +0000 |
---|---|---|
committer | Christos.K <freedomrfox@gmail.com> | 2017-10-09 17:55:26 +0000 |
commit | 429afbe3e3177d310ecdabd473cbdff67bd56393 (patch) | |
tree | 3f573b4d4accb2369fa6d7d33cb935123bb716a2 | |
parent | Relocated (diff) | |
download | GSE-429afbe3e3177d310ecdabd473cbdff67bd56393.tar.gz GSE-429afbe3e3177d310ecdabd473cbdff67bd56393.tar.bz2 GSE-429afbe3e3177d310ecdabd473cbdff67bd56393.zip |
New modules name
45 files changed, 2255 insertions, 0 deletions
diff --git a/scripts/gpyfunctions/__init__.py b/scripts/gpyfunctions/__init__.py new file mode 100644 index 0000000..125607d --- /dev/null +++ b/scripts/gpyfunctions/__init__.py @@ -0,0 +1,2 @@ +#__all__=[] +#__path__=["menu", "tools", "system", "controller"] diff --git a/scripts/gpyfunctions/__pycache__/__init__.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/__init__.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..958c54b --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/__init__.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/arg_opt.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/arg_opt.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..85860cf --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/arg_opt.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/arg_opt.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/arg_opt.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..0905bf8 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/arg_opt.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/gmen_opt.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/gmen_opt.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..ea223bc --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gmen_opt.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/gmen_opt.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/gmen_opt.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..96f83ca --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gmen_opt.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/gportal.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/gportal.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..26666c3 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gportal.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/gportal.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/gportal.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..d3ef3f4 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gportal.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/gseout.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/gseout.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..b0e4c94 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gseout.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/gseout.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/gseout.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..2fe6ce9 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gseout.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/gsetxf.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/gsetxf.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..d06c1b7 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gsetxf.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/gsetxmen.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/gsetxmen.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..b59423a --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gsetxmen.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/gsub_men.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/gsub_men.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..78ea39d --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gsub_men.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/gsub_men.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/gsub_men.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..40d731e --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/gsub_men.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/librarium.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/librarium.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..b08ce2a --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/librarium.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/preliminary.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/preliminary.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..d0c710c --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/preliminary.cpython-34.pyc diff --git a/scripts/gpyfunctions/__pycache__/preliminary.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/preliminary.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..a7261d8 --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/preliminary.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/sysctopt.cpython-36.pyc b/scripts/gpyfunctions/__pycache__/sysctopt.cpython-36.pyc Binary files differnew file mode 100644 index 0000000..8d016da --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/sysctopt.cpython-36.pyc diff --git a/scripts/gpyfunctions/__pycache__/warp.cpython-34.pyc b/scripts/gpyfunctions/__pycache__/warp.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..a42806c --- /dev/null +++ b/scripts/gpyfunctions/__pycache__/warp.cpython-34.pyc diff --git a/scripts/gpyfunctions/controller/__init__.py b/scripts/gpyfunctions/controller/__init__.py new file mode 100644 index 0000000..28180ed --- /dev/null +++ b/scripts/gpyfunctions/controller/__init__.py @@ -0,0 +1,2 @@ +#__all__=[] +#__path__=[] diff --git a/scripts/gpyfunctions/gseclass.py b/scripts/gpyfunctions/gseclass.py new file mode 100755 index 0000000..4a86d4a --- /dev/null +++ b/scripts/gpyfunctions/gseclass.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3.6 + +# Images +class image(object): + # Image products, with type + + # Attributes: + # name: A string with the image's name + # date: A string with the image's creation date + + def __init__(img, name): + # Return the image's name + img.name = name + + def set_date(img, date): + # Return the image's date of creation + img.date = date + diff --git a/scripts/gpyfunctions/menu/__init__.py b/scripts/gpyfunctions/menu/__init__.py new file mode 100644 index 0000000..7f01649 --- /dev/null +++ b/scripts/gpyfunctions/menu/__init__.py @@ -0,0 +1,3 @@ +#__all__=[] +#__path__=[] + diff --git a/scripts/gpyfunctions/menu/__pycache__/__init__.cpython-34.pyc b/scripts/gpyfunctions/menu/__pycache__/__init__.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..f5059ad --- /dev/null +++ b/scripts/gpyfunctions/menu/__pycache__/__init__.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/portal/__init__.py b/scripts/gpyfunctions/menu/portal/__init__.py new file mode 100644 index 0000000..2464e76 --- /dev/null +++ b/scripts/gpyfunctions/menu/portal/__init__.py @@ -0,0 +1,2 @@ +__all__=["gportal"] +#__path__=[] diff --git a/scripts/gpyfunctions/menu/portal/__pycache__/__init__.cpython-34.pyc b/scripts/gpyfunctions/menu/portal/__pycache__/__init__.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..a7dee46 --- /dev/null +++ b/scripts/gpyfunctions/menu/portal/__pycache__/__init__.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/portal/__pycache__/gportal.cpython-34.pyc b/scripts/gpyfunctions/menu/portal/__pycache__/gportal.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..9c84902 --- /dev/null +++ b/scripts/gpyfunctions/menu/portal/__pycache__/gportal.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/portal/gportal.py b/scripts/gpyfunctions/menu/portal/gportal.py new file mode 100755 index 0000000..dfa98cf --- /dev/null +++ b/scripts/gpyfunctions/menu/portal/gportal.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3.4 + +def _gmm(): + ''' + Definition of the project's GUI menu + ''' + + import tkinter + from tkinter import Tk, Toplevel, Button, Menu + + def donothing(): + filewin = Toplevel(portal) + button = Button(filewin, text="Do nothing button") + button.pack() + + # Define portal as Tk + portal = Tk() + + # Title + portal.title("Portal Menu") + # Window Geometry + portal.geometry("1200x1024") + + # Define portal menu as portmen + portmen = Menu(portal) + + def _portfile(): + ''' + Definition of "file tab" + ''' + + # Create file tab + portfile = Menu(portmen, tearoff=0) + # Label the tab as File + portmen.add_cascade(label="File", menu=portfile) + + # File's sub-menu + portfile.add_command(label="New", command=donothing) + portfile.add_command(label="Open", command=donothing) + portfile.add_command(label="Save", command=donothing) + portfile.add_command(label="Save as...", command=donothing) + portfile.add_command(label="Close", command=donothing) + portfile.add_separator() + portfile.add_command(label="Exit", command=portal.quit) + + return portfile + + + def _portedit(): + ''' + Definition of edit tab + ''' + + # Create edit tab + portedit = Menu(portmen, tearoff=0) + # Label the tab as edit + portmen.add_cascade(label="Edit", menu=portedit) + + portedit.add_command(label="Undo", command=donothing) + portedit.add_separator() + + portedit.add_command(label="Cut", command=donothing) + portedit.add_command(label="Copy", command=donothing) + portedit.add_command(label="Paste", command=donothing) + portedit.add_command(label="Delete", command=donothing) + portedit.add_command(label="Select All", command=donothing) + + return portedit + + + def _porthelp(): + ''' + Definition of help tab + ''' + + porthelp = Menu(portmen, tearoff=0) + portmen.add_cascade(label="Help", menu=porthelp) + + porthelp.add_command(label="Help Index", command=donothing) + porthelp.add_command(label="About...", command=donothing) + + return porthelp + + portfile = _portfile() + portedit = _portedit() + porthelp = _porthelp() + + portal.config(menu=portmen) + portal.mainloop() + + return 0 + + diff --git a/scripts/gpyfunctions/menu/txmen/__init__.py b/scripts/gpyfunctions/menu/txmen/__init__.py new file mode 100644 index 0000000..28180ed --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/__init__.py @@ -0,0 +1,2 @@ +#__all__=[] +#__path__=[] diff --git a/scripts/gpyfunctions/menu/txmen/__pycache__/__init__.cpython-34.pyc b/scripts/gpyfunctions/menu/txmen/__pycache__/__init__.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..db6668a --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/__pycache__/__init__.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/txmen/__pycache__/gsetxf.cpython-34.pyc b/scripts/gpyfunctions/menu/txmen/__pycache__/gsetxf.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..e3f6899 --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/__pycache__/gsetxf.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/txmen/__pycache__/gsetxmen.cpython-34.pyc b/scripts/gpyfunctions/menu/txmen/__pycache__/gsetxmen.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..b0b82dc --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/__pycache__/gsetxmen.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/txmen/__pycache__/gsub_men.cpython-34.pyc b/scripts/gpyfunctions/menu/txmen/__pycache__/gsub_men.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..d273a5f --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/__pycache__/gsub_men.cpython-34.pyc diff --git a/scripts/gpyfunctions/menu/txmen/gsetxf.py b/scripts/gpyfunctions/menu/txmen/gsetxf.py new file mode 100755 index 0000000..cbcd7b8 --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/gsetxf.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3.4 + +# Initiates the text main menu loop +def _call_menu(CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR): + ''' + Imports important porject's directories and initiates the text's menu loop + ''' + + from gpyfunctions.menu.txmen.gsub_men import _call_sub + from gpyfunctions.menu.txmen.gsetxmen import _men_opt + from gpyfunctions.preliminary import _clear + + # _init_sub initiated the requested sub_menu and its functions + def _init_sub(men, bpar, spar, ccal, *args): + ''' + _init_sub initiated the requested sub_menu and its functions + men: menu entry to be printed + bpar: which is the parent of men + spar: relates men with case (if conditions) about the current men + ccal: the function that will be executed after the menu has been printed + *args: additional arguments for the functions that are called. + ''' + + try: + del _sub_call + + c = [_PARENT, _CHILD, _STAY] + + for i in c[:]: + del i + + except NameError: + pass + + while True: + # Clear screen then print the related menu + _clear() + _men_opt(men) + + try: + # Call the related function + _sub_call = _call_sub(ccal, *args) + + except KeyboardInterrupt: + from gpyfunctions.tools.gseout import e_report + e_report("\n\nKeyboard interrupt detected.\n") + exit(1) + + except EOFError: + from gpyfunctions.tools.gseout import b_report + b_report("\n\nEOFError. Maybe CTRL-D?\nIf not, please report this bug!\n") + exit(1) + + # Check if the menu entry was a valid one + if _sub_call is "err": + pass + + else: + # For valid entry, set _PARENT, _CHILD OR _STAY + # _PARR requests the parent menu of the sub-menu + # _CHILD calls for a child = {NAME} sub-menu + # _STAY requests the same menu + for k, v in _sub_call.items(): + if k is "_PARENT" and v == 0: + BACKTO = bpar + + elif k is "_CHILD": + BACKTO = v + + elif k is "_STAY" and v == 0: + BACKTO = spar + + return BACKTO + + # Main menu loop function + def _main_loop(minit, CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR): + ''' + Main menu loop function + This function simply reads the BACKTO from the _init_sub function and executes + the return menu. + See _init_sub above for the given variables. + ''' + + BACKTO = minit + + while True: + # Main menu + if BACKTO is "MM": + BACKTO = _init_sub("1", "Q", "MM", "main_f", CWORKDIR) + + elif BACKTO is "DOC": + # Documentation menu + BACKTO = _init_sub("2", "MM", "DOC", "doc_f", CWORKDIR) + + elif BACKTO is "AB": + # About menu + BACKTO = _init_sub("3", "MM", "AB", "about_f", CWORKDIR) + + elif BACKTO is "PORT_M": + # Portage menu + BACKTO = _init_sub("7", "SM", "PORT_M", "portage_men_f", CCONFDIR) + + elif BACKTO is "CATA_M": + # Catalyst menu + BACKTO = _init_sub("10", "SM", "CATA_M", "catalyst_f", CCONFDIR) + + elif BACKTO is "SM": + # Builder menu + BACKTO = _init_sub("6", "BSM", "SM", "bs_f", CWORKDIR) + + elif BACKTO is "BSM": + # System menu + BACKTO = _init_sub("5", "MM", "BSM", "bs_menu_f", CWORKDIR) + + elif BACKTO is "CO_F": + # Controller menu + BACKTO = _init_sub("8", "BSM", "CO_F", "config_f", CCONFDIR) + + elif BACKTO is "SELDEF": + # Select defaults menu + BACKTO = _init_sub("9", "BSM", "SELDEF", "selectdef_f", CWORKDIR) + + elif BACKTO is "GSET": + # GSE tools menu + BACKTO = _init_sub("11", "MM", "GSET", "gse_t", CWORKDIR) + + elif BACKTO is "CONTR": + # Controller + BACKTO = _init_sub('', "MM", "CONTR", "controller_f", CWORKDIR) + + elif BACKTO is "Q": + break + else: + _parameter_error() + + + _main_loop("MM", CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR) + + return 0 + + + + diff --git a/scripts/gpyfunctions/menu/txmen/gsetxmen.py b/scripts/gpyfunctions/menu/txmen/gsetxmen.py new file mode 100755 index 0000000..bf42637 --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/gsetxmen.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3.4 + +def _men_opt(_men_call): + ''' + GSE text menu output. + For a given function that is called, this function prints the entries / options of that function. + ''' + + from gpyfunctions.tools.gseout import report_colors + + if _men_call is '1': + print("##################### " + report_colors.CYAN + "~~Main Menu~~" + report_colors.RESET + " ######################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " System Menu " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Build the controller image " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " GSE Tools " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Documentations " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " About the project " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.YELLOW + " I shouldn't be here, please let me leave! " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("############################################################") + + elif _men_call is "2": + print("################### " + report_colors.CYAN + "~~Documentations~~" + report_colors.RESET + " ####################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Introduction to GSE Directory " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " The Controller " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " The Config.d Directory " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " The script's Directory " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.GREEN + " Main Menu " + report_colors.RESET + "##") + print("## ##") + print("##############################################################") + + elif _men_call is "3": + print("####################### " + report_colors.CYAN + "~~About~~" + report_colors.RESET + " ########################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " About the project " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Linux, Gentoo and the birth of an Idea " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " Open Source To The End and Beyond " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.GREEN + " Main Menu " + report_colors.RESET + "##") + print("## ##") + print("#############################################################") + + elif _men_call is "5": + print("#################### " + report_colors.CYAN + "~~System Menu~~" + report_colors.RESET + " ###################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Built a System " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure built variables " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Select default system for distribution " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Create a stage4 tarball " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("###########################################################") + + elif _men_call is "6": + print("################### " + report_colors.CYAN + "~~Builder~~" + report_colors.RESET + " ##################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Portage " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Catalyst " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Precompiled " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("#####################################################") + + elif _men_call is "7": + print("###################### " + report_colors.CYAN + "~~Portage~~ " + report_colors.RESET + " #####################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Guided/Automatic make.conf " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Manually edit make.conf (Reset) " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Features & ccashe " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit distcc " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit packages.use " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("###########################################################") + + elif _men_call is "8": + print("################## " + report_colors.CYAN + "~~Configurations~~" + report_colors.RESET + " ##################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure fstab/drives " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Manually edit fstab " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III " + report_colors.RESET + "]" + report_colors.YELLOW + " Manually edit drive names " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Hostname " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit /etc/conf.d/net " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Locales " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VII " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Consolefont " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VIII " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit sshd " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IX " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit sshkey " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "X " + report_colors.RESET + "]" + report_colors.YELLOW + " Symlink, bind, overlay and tmpfs " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "XI " + report_colors.RESET + "]" + report_colors.YELLOW + " Add Scripts " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "XII " + report_colors.RESET + "]" + report_colors.YELLOW + " Install Packages " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "XIII " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit Default Grub " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "XIV " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit runlevels*** " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "XV " + report_colors.RESET + "]" + report_colors.YELLOW + " Inject files " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "XVI " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + " T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("###########################################################") + + elif _men_call is "9": + print("################## " + report_colors.CYAN + "~~Select Default~~" + report_colors.RESET + " ##################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " List systems " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Edit default " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("###########################################################") + + elif _men_call is "10": + print("################### " + report_colors.CYAN + "~~Catalyst~~" + report_colors.RESET + " #################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure catalyst.conf " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure catalystrc " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Configure stage1 " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure stage2 " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "V " + report_colors.RESET + "]" + report_colors.YELLOW + " Configure stage3 " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VI " + report_colors.RESET + "]" + report_colors.PURPLE + " Initiate Build " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "VII" + report_colors.RESET + "]" + report_colors.YELLOW + " Return " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("#####################################################") + + elif _men_call is "11": + print("#################### " + report_colors.CYAN + "~~GSE Tools~~" + report_colors.RESET + " #####################") + print("## ##") + print("## [ " + report_colors.GREEN + "I " + report_colors.RESET + "]" + report_colors.YELLOW + " Renew ALL " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "II " + report_colors.RESET + "]" + report_colors.YELLOW + " Renew Scripts " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "III" + report_colors.RESET + "]" + report_colors.YELLOW + " Version Check " + report_colors.RESET + "##") + print("## [ " + report_colors.GREEN + "IV " + report_colors.RESET + "]" + report_colors.YELLOW + " Return back " + report_colors.RESET + "##") + print("## ##") + print("## [ " + report_colors.GREEN + "T " + report_colors.RESET + "]" + report_colors.GREEN + " Terminal " + report_colors.RESET + "##") + print("## ##") + print("###########################################################") + + + del _men_call, report_colors + + + + diff --git a/scripts/gpyfunctions/menu/txmen/gsub_men.py b/scripts/gpyfunctions/menu/txmen/gsub_men.py new file mode 100755 index 0000000..31583f5 --- /dev/null +++ b/scripts/gpyfunctions/menu/txmen/gsub_men.py @@ -0,0 +1,574 @@ +#!/usr/bin/env python3.4 + +# Define all menu functions +def _call_sub(ccal, *args): + ''' + Here are defined all the function that consist the project's text menu + For example: + main_f() is the top layer function from the text menu + gse_t() appears as an entry on main_f options and calls a new sub-menu + ''' + + from gpyfunctions.tools.gseout import report_colors, e_report, b_report + from sys import exit + from gpyfunctions.preliminary import portalin + + def main_f(*args): + ''' + Main menu function + ''' + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + # Call builder submenu + _sub_call = {"_CHILD": "BSM"} + + elif SELCT in ['II', 'ii', '2']: + # Call controller submenu + _sub_call = {"_CHILD": "CONTR"} + + elif SELCT in ['III', 'iii', '3']: + # GSE renew submenu + _sub_call = {"_CHILD": "GSET"} + + elif SELCT in ['IV', 'iv', '4']: + # Call documentation submenu + _sub_call = {"_CHILD": "DOC"} + + elif SELCT in ['V', 'v', '5']: + # Call about submenu + _sub_call = {"_CHILD": "AB"} + + elif SELCT in ['VI', 'vi', '6', 'q', 'Q']: + # Go to parrent + e_report("Exiting...") + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT + + return _sub_call + + + def gse_t(*args): + ''' + GSE tools menu function + ''' + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + pass + exit(0) + + elif SELCT in ['II', 'ii', '2']: + pass + exit(0) + + elif SELCT in ['III', 'iii', '3']: + # Version check + # import version check function here + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT + + return _sub_call + + def bs_menu_f(*args): + ''' + Systen's menu function + ''' + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + # Call build system submenu + _sub_call = {"_CHILD": "SM"} + + elif SELCT in ['II', 'ii', '2']: + # Call configuration submenu + _sub_call = {"_CHILD": "CO_F"} + + elif SELCT in ['III', 'iii', '3']: + # CALL SELECT DEFAULT SYSTEM SUBMENU + _sub_call = {"_CHILD": "SELDEF"} + + elif SELCT in ['IV', 'iv', '4']: + # TBU: WILL INCLUDE A STAGE4 TARBALL CREATION + _sub_call = {"_STAY": 0} + + elif SELCT in ['V', 'v', '5']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT + + return _sub_call + + + def bs_f(*args): + ''' + Builders's menu function + ''' + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + # CALL PORTAGE SUBMENU) + _sub_call = {"_CHILD": "PORT_M"} + + elif SELCT in ['II', 'ii', '2']: + # CALL CATALYST SUBMENU + _sub_call = {"_CHILD": "CATA_M"} + + elif SELCT in ['III', 'iii', '3']: + # START PRE PRECOMPILED + # import warp "--base=precomp" "args" here + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT + + return _sub_call + + + def portage_men_f(CCONFDIR, *args): + ''' + Portage's menu function + ''' + + from subprocess import call + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + exit(0) + # Make make.conf: Automatic or guided configuration + _ex_stat = makeconf_ed + + if _ex_stat == 0: + print(report_colors.YELLOW + "[ * ]" + report_colors.RESET + "Configuration was successful") + else: + print(report_colors.SRED + "[ * ]" + report_colors.RESET + "Something went wrong") + + del _ex_stat + + _sub_call = {"_STAY": 0} + + elif SELCT in ['II', 'ii', '2']: + # Edit of make.conf + call(["vim", CCONFDIR + "/system/portage/make.conf"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['III', 'iii', '3']: + # Edit features + call(["vim", CCONFDIR + "/system/coptions"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + # Edit distcc's hosts + call(["vim", CCONFDIR + "/system/hosts"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['V', 'v', '5']: + # Edit USEFLAGS + call(["vim", CCONFDIR + "/system/portage/package.use/sysbuild"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['VI', 'vi', '6']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT, call + + return _sub_call + + + def catalyst_f(CCONFDIR, args): + ''' + Catalyst's menu function + ''' + + from subprocess import call + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + # Edit catalyst.conf + call(["vim", CCONFDIR + "/system/catalyst/catalyst.conf"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['II', 'ii', '2']: + # Edit catalystrc + call(["vim", CCONFDIR + "/system/catalyst/catalystrc"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['III', 'iii', '3']: + # Edit stage1.spec + call(["vim", CCONFDIR + "/system/catalyst/stage1.spec"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + # Edit stage2.spec + call(["vim", CCONFDIR + "/system/catalyst/stage2.spec"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['V', 'v', '5']: + # Edit stage3.spec + call(["vim", CCONFDIR + "/system/catalyst/stage3.spec"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['VI', 'vi', '6']: + # Initiate system build + #warp "--base=catalyst" "${lppar[@]}" + _sub_call = {"_STAY": 0} + + elif SELCT in ['VII', 'vii', '7']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT, call + + return _sub_call + + + def config_f(CCONFDIR, *args): + ''' + Configuration's menu function + ''' + + from subprocess import call + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + # Marked for removal + #drv_interface + + _sub_call = {"_STAY": 0} + + elif SELCT in ['II', 'ii', '2']: + # Edit fstab + call(["vim", CCONFDIR + "/system/fstab"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['III', 'iii', '3']: + # Edit devname.info + call(["vim", CCONFDIR + "/system/devname.info"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + # Edit hostname + call(["vim", CCONFDIR + "/system/hostname"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['V', 'v', '5']: + # Edit conf.d/net + call(["vim", CCONFDIR + "/system/net"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['VI', 'vi', '6']: + # Edit locale + call(["vim", CCONFDIR + "/system/locale.gen"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['VII', 'vii', '7']: + # Edit consolefont + call(["vim", CCONFDIR + "/system/consolefont"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['VIII', 'viii', '8']: + # Edit sshd_config + call(["vim", CCONFDIR + "/system/sshd"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['IX', 'ix', '9']: + # Edit id_rsa.pub + call(["vim", CCONFDIR + "/system/ssh.pub"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['X', 'x', "10"]: + # Edit system links + call(["vim", CCONFDIR + "/system/system_links"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['XI', 'xi', '11']: + # Edit custom scripts + call(["vim", CCONFDIR + "/system/custom_scripts"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['XII', 'xii', '12']: + # Edit custom package list + call(["vim", CCONFDIR + "/system/custom_pacl"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['XIII', 'xiii', '13']: + # Edit /etc/default/grub + call(["vim", CCONFDIR + "/system/grub"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['XIV', 'xiv', '14']: + # Edit runlevels + call(["vim", CCONFDIR + "/system/runlevels"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['XV', 'xv', '15']: + # Edit files + call(["vim", CCONFDIR + "/system/inject_files"], stdout=None, stderr=None) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['XVI', 'xvi', '16']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from pgpyfunctions.reliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT, call + + return _sub_call + + + def selectdef_f(*args): + ''' + Select default menu function + ''' + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + _sub_call = {"_STAY": 0} + + elif SELCT in ['II', 'ii', '2']: + _sub_call = {"_STAY": 0} + + elif SELCT in ['III', 'iii', '3']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + elif SELCT in ['t', 'T']: + # Call shell function + from gpyfunctions.preliminary import _shell + _shell() + + _sub_call = {"_STAY": 0} + + del _shell + + else: + _sub_call="err" + + del SELCT + + return _sub_call + + + def doc_f(CWORKDIR, *args): + ''' + Documentetion's menu function + ''' + + from subprocess import call + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + call(["man", CWORKDIR + "/docs/documentations/overview_gse.5"]) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['II', 'ii', '2']: + call(["man", CWORKDIR + "/docs/documentations/overview_controller.5"]) + _sub_call = {"_STAY": 0} + + elif SELCT in ['III', 'iii', '3']: + call(["man", CWORKDIR + "/docs/documentations/overview_config.d.5"]) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + call(["man", CWORKDIR + "/docs/documentations/overview_scripts.5"]) + + _sub_call = {"_STAY": 0} + + elif SELCT in ['V', 'v', '5']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + else: + _sub_call="err" + + del SELCT, call + + return _sub_call + + def about_f(CWORKDIR, *args): + ''' + About menu function + ''' + + SELCT = portalin("_input") + + if SELCT in ['I', 'i', '1']: + e_report("About submenu option a)") + portalin("_key") + + _sub_call = {"_STAY": 0} + + elif SELCT in ['II', 'ii', '2']: + e_report("About submenu option b)") + portalin("_key") + + _sub_call = {"_STAY": 0} + + elif SELCT in ['III', 'iii', '3']: + e_report("About submenu option c)") + portalin("_key") + + _sub_call = {"_STAY": 0} + + elif SELCT in ['IV', 'iv', '4']: + # Go to parrent + _sub_call = {"_PARENT": 0} + + else: + _sub_call="err" + + del SELCT + + return _sub_call + + + def controller_f(*args): + ''' + Controller's menu function + ''' + + e_report("Initiating controller build") + + _sub_call = {"_PARENT": 0} + + return _sub_call + + + # Get the return value from the evaluated function + _sub_call = eval(ccal+'(args[0], args[1:])') + + # Clear return + del portalin, report_colors, e_report, b_report, exit + + return _sub_call + + + diff --git a/scripts/gpyfunctions/preliminary.py b/scripts/gpyfunctions/preliminary.py new file mode 100755 index 0000000..6f40533 --- /dev/null +++ b/scripts/gpyfunctions/preliminary.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python3.4 + +# Gentoo check function +def _is_gentoo(): + ''' + Check if the project has been initiated from a Gentoo system + ''' + + from subprocess import call + + # Grep Gentoo from the releases file. + _dist_check = call("grep ^NAME= /etc/*release | awk -F '=' '{print $2}' | grep -q Gentoo", stdout=None, stderr=None, shell=True) + + del call + + # Return 0 in case grep was successful, or 1 otherwise. + if _dist_check == 0: + del _dist_check + return 0 + else: + return 1 + +# Check for superuser privileges +def _is_su(): + ''' + Check if the project has been initiated with super user permissions + ''' + + from subprocess import call + + # The check is very simple. It checks if the $UID is equal to 0. In case it is not, it returns a value of 1 + _super_u = call("if [[ $(echo $UID) == 0 ]]; then exit 0; else exit 1; fi", stdout=None, stderr=None, shell=True) + + del call + + # Test the return value and return either 0 or 1 + if _super_u == 0: + del _super_u + return 0 + else: + return 1 + +# Simple input call +def portalin(_input): + ''' + Calls for a user input. + There are two calls for input + I ) The first one requests an input and returns it to the function that requested it + II ) The second asks for a user input and does nothing. This one is for visual purpose like (press any key) + ''' + + from gpyfunctions.tools.gseout import report_colors + + # Ask for user input + if _input is "_input": + portin = input(report_colors.YELLOW + "Input :: <= " + report_colors.RESET) + return portin + + # Asks for an input to continue the process. + # The main difference of this one from the above, apart from the stdout text is that it does not return anything. + elif _input is "_key": + portin = input(report_colors.BLUE + "Press any key to continue" + report_colors.RESET) + + del report_colors + + +# Simple shell call +def _shell(): + ''' + Shell function that: + Exports the current $SHELL of the system + Initiates a call subprocess on the given $SHELL + Resumes the process when the call shell subprocess finishes + ''' + + from gpyfunctions.tools.gseout import e_report + from os import environ + + # Export $SHELL + active_shell = environ['SHELL'] + + e_report("Calling " + active_shell + ", please exit to resume script") + + # Import time and wait 3 seconds before initiating a shell + import time + time.sleep(1.5) + + from subprocess import call + + # Open shell terminal with as $SHELL + call([active_shell], stdout=None, stderr=None, shell=True) + e_report("Proceeding") + + # Clear and exit + del e_report, time, call, active_shell, environ + +# Simple clear screen function +def _clear(): + ''' + Very simply screen clear function. + When called, it executes system("clear") for os module + This function exists only to aid the text menu functions. + ''' + + from os import system + system("clear") + +# Parameter error function +def _parameter_error(): + ''' + Parameter miss match error + This error will be printed before key point actions. + Example: All actions that request write access in the system. + ''' + + from gpyfunctions.tools.gseout import die + from os import system + die(""" + [ FATAL ] + + If this message is printed while using the Maim Menu + That means essential files are altered or something bad is happening. + + Please run a health-check from the ~Main Menu~ and a Version check first. + If you see this again after the health/version check, please submit a bug report + and stop using the program, or data loss may occur. + + Exiting... + """) + + +# Export important project's sub-directories +def _gse_path(_gpyfunc_): + ''' + The purpose of this function is to read the given _gpygunc_ variable and export + the all important project's sub-directories + The subdirectories are: + CCGSE + CCONFDIR + CDISTDIR + CLOCALLG + CLOGLG + CSYSROOT + CLOCALLIB + CFUNCTIONS + ''' + + from os import getcwd, path + from sys import exit + + # Export current working category + CWORKDIR = getcwd() + + if _gpyfunc_ == 'sys': + CWORKDIR = '/usr/lib64/gse' + CGSE = CWORKDIR + '/gse.py' + CCONFDIR = CWORKDIR + '/config.d' + CDISTDIR = '/var/tmp/gse/dist.d' + CLOCALLG = CWORKDIR + '/local' + CLOGLG = '/var/log/gse' + CSYSROOT = '/home/gse' + CLOCALLIB = '/var/lib/gse' + CFUNCTIONS = CWORKDIR + 'scripts/pyfunctions' + + elif _gpyfunc_ == '.git': + # If the project has been git cloned or simply copied to a location + CWORKDIR = path.dirname(CWORKDIR) + CFUNCTIONS = CWORKDIR+'/scripts/pyfunctions' + CGSE = CWORKDIR + '/gse.py' + CCONFDIR = CWORKDIR+'/config.d' + CDISTDIR = CWORKDIR+'/dist.d' + CLOCALLG = CWORKDIR+'/local' + CLOGLG = CWORKDIR+'/var/log' + CSYSROOT = CWORKDIR+'/sysroot' + CLOCALLIB = CWORKDIR+'/var/lib' + + else: + print("\033[0;31m Could not find project's directory \033[0;0m") + exit(1) + + del getcwd, path, exit + + return CWORKDIR, CGSE, CFUNCTIONS, CCONFDIR, CDISTDIR, CLOCALLG, CLOGLG, CSYSROOT, CLOCALLIB + + + + diff --git a/scripts/gpyfunctions/system/__init__.py b/scripts/gpyfunctions/system/__init__.py new file mode 100644 index 0000000..2a1545b --- /dev/null +++ b/scripts/gpyfunctions/system/__init__.py @@ -0,0 +1,2 @@ +#__all__=[] +#__path__=[ diff --git a/scripts/gpyfunctions/tools/__init__.py b/scripts/gpyfunctions/tools/__init__.py new file mode 100644 index 0000000..95843cb --- /dev/null +++ b/scripts/gpyfunctions/tools/__init__.py @@ -0,0 +1,2 @@ +__all__=["gseout"] +#__path__=[] diff --git a/scripts/gpyfunctions/tools/__pycache__/__init__.cpython-34.pyc b/scripts/gpyfunctions/tools/__pycache__/__init__.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..42a9c93 --- /dev/null +++ b/scripts/gpyfunctions/tools/__pycache__/__init__.cpython-34.pyc diff --git a/scripts/gpyfunctions/tools/__pycache__/gseout.cpython-34.pyc b/scripts/gpyfunctions/tools/__pycache__/gseout.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..cdae1cb --- /dev/null +++ b/scripts/gpyfunctions/tools/__pycache__/gseout.cpython-34.pyc diff --git a/scripts/gpyfunctions/tools/__pycache__/librarium.cpython-34.pyc b/scripts/gpyfunctions/tools/__pycache__/librarium.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..d4bc6da --- /dev/null +++ b/scripts/gpyfunctions/tools/__pycache__/librarium.cpython-34.pyc diff --git a/scripts/gpyfunctions/tools/__pycache__/warp.cpython-34.pyc b/scripts/gpyfunctions/tools/__pycache__/warp.cpython-34.pyc Binary files differnew file mode 100644 index 0000000..0391e41 --- /dev/null +++ b/scripts/gpyfunctions/tools/__pycache__/warp.cpython-34.pyc diff --git a/scripts/gpyfunctions/tools/gseout.py b/scripts/gpyfunctions/tools/gseout.py new file mode 100755 index 0000000..a8b7bcd --- /dev/null +++ b/scripts/gpyfunctions/tools/gseout.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3.4 + +from sys import exit + +# Output colors +class report_colors: + ''' + Class that defines and saves various color formats + ''' + + SRED = "\033[0;31m" + LRED = "\033[1;31m" + BLUE = "\033[0;34m" + YELLOW = "\033[0;33m" + CYAN = "\033[1;36m" + GREEN = "\033[0;32m" + PURPLE = "\033[2;35m" + RESET = "\033[0;0m" + +# Die function +def die(error): + ''' + Print red error and kill the process + ''' + + print(report_colors.SRED + error + report_colors.RESET) + exit(1) + +# Red report function +def lr_report(report): + ''' + Print a light red warning + ''' + + print(report_colors.LRED + report + report_colors.RESET) + +# Yellow report function +def e_report(report): + ''' + Print a yellow warning + ''' + + print(report_colors.YELLOW + report + report_colors.RESET) + +# Blue report function +def b_report(report): + ''' + Print a blue warning + ''' + + print(report_colors.BLUE + report + report_colors.RESET) + +# Green report function +def g_report(report): + ''' + Print a green warning + ''' + + print(report_colors.GREEN + report + report_colors.RESET) + +# Purpule report function +def p_report(report): + ''' + Print a purple warning + ''' + + print(report_colors.PURPLE + report + report_colors.RESET) + + + + + + + + diff --git a/scripts/gpyfunctions/tools/librarium.py b/scripts/gpyfunctions/tools/librarium.py new file mode 100755 index 0000000..dd491b1 --- /dev/null +++ b/scripts/gpyfunctions/tools/librarium.py @@ -0,0 +1,503 @@ +#!/usr/bin/env python3.4 + +gse_des = '''\ + ----------------------------------------------------------------- + + GSE: This project was built under GSoC 2017 for Gentoo Fundation. + For more informations see man gse.5 or the project's wiki at: + https://wiki.gentoo.org/wiki/User:Ulfox/GSoC-GSE + + ----------------------------------------------------------------- + + System: For system menu, run: gse system -h + Controller: For controller menu, run: gse controller -h + ''' +gse_usage="%(prog)s system --base=[precomp/catalyst] [options] / controller [options] / [-h/--help]" + +gse_ver = '%(prog)s Experimental' + +# System arguments +def _export_args(sequence): + ''' + Here all project's arguments and options are defined. + + The definition has 4 phases. + On phase 1 the general project's arguments and options are defined. + On phase 2 the special arguments and options are defined, based on the sequence that is given. + On phase 3 special sub-options are defined. Those options are enabled only from some special options. + Last, on phase 4, everything is evaluated and returned back the the parent function. + ''' + + # Library for arguments and options parse + import argparse + from sys import argv + + # Definition of name, usage and description for the options menu + parser = argparse.ArgumentParser(prog="gse", + formatter_class=argparse.RawDescriptionHelpFormatter, + description=gse_des, + usage=gse_usage, + epilog="For more information about each option, please see man gse.1 " + + "This program is distributed under GPL-2 license", + add_help=True) + + # Dev opt + parser.add_argument('--dev', + help="Marked for removal. Removes all kind of checks. Never run this with super user privileges. It exists only for the experimental developing phase.", + action="store_true", + default=False) + + parser.add_argument("target", + help="Initiate either system or controller scripts. [system/controller] ", + action="store", + default=None) + + parser.add_argument("--gmm", + help="GUI Menu", + action="store_true", + default=False) + + parser.add_argument("--mm", + help="Text Menu", + action="store_true", + default=False) + + # Time-warp option + parser.add_argument('--timewarp', '--time-warp', + help="Load and execute a saved state. A state is the set of configuration files and arguments that were saved at a given time.", + action="store", + type=int) + + # Time-state option + parser.add_argument('--timestate', '--time-state', + help="Create, list, set, save and delete configuration states. \ + Syntax: --time-state [save/list/set/delete] [name/-/N/N]", + action="store", + default='no', + nargs='+', + type=str) + + # No check option + parser.add_argument('--nochecks', '--no-checks', + help="Disable all \"simple\" checks. The process will be enabled without requesting a return 0 from the system check function.", + action="store_true", + default=False) + + # Keep optional argument. + parser.add_argument('-k', '--keep', + help='''Save to backup old work, instead of purging / reconfiguring an old entry. This option does not work with force.''', + action="store_true", + default=False) + + # Health check argument + parser.add_argument('-hc', '--healthcheck', '--health-check', + help='''Run integrity check for the project's scripts and essential configuration files''', + action="store_true", + default=False) + + # Replace new argument + parser.add_argument('-rpn', '--replacenew', '--replace-new', + help='''Refresh all the project's scripts and configuration files. + Warning: All user configuration files will be lost''', + action="store_true") + + # Minimal build + parser.add_argument('-bm', '--minimal', '--build-minimal', + help="""Enable minimal build. This option removes and disables many features. All images under this flag are configured for size.""", + action="store_true", + default=False) + + # Verbose option + parser.add_argument('-v', '--verbose', + help="Enable verbose output for all actions.", + action='count') + + # Quiet option + parser.add_argument('-q', '--quiet', + help="Enable quiet global flag. This flag suppresses all output with a simple text entry regarding the action.", + action="store_true", + default=False) + + # Version + parser.add_argument('-V', '--version', + help="Show project's version and exit.", + action='version', + version=gse_ver) + + if sequence == 'system': + # Base definition. While base appears to be optional, it is not, since it's always required to initiate the building sequence + parser.add_argument('-b', '--base', + help='''Set the system's fundation. See man gse.1 for more.''', + action="store", + type=str, + default='catalyst') + + # Force new optional argument + parser.add_argument('-fcn', '--forcenew', '--force-new', + help='''Enable force to all project's actions. This option purges all previous work done. Not recommended!''', + action="store_true", + default=False) + + # Fetch new optional argument + parser.add_argument('-fn', '--fetchnew', '--fetch-new', + help="Enable fetch option. Will always download requested files, even if they exist and are up to date.", + action="store_true", + default=False) + + # Script's check argument + parser.add_argument("--sdir", + help="Give the directory that hosts the scripts. See man gse.1 for more informations.", + action="store", + default=None, + type=str) + + for _tmp1 in argv[:]: + if '--sdir' in str(_tmp1): + parser.add_argument("--do", + help="Scripts to be sourced. For the same hook the given order applies to priority.", + action="store", + default=None, + type=str) + + parser.add_argument("--ghook", + help="Hooks with priority for given scripts.", + action="store", + default=None, + type=str) + + # Disable kernel build optional argument + parser.add_argument('-ke', '--kernel', + help='''Enable kernel build action inside the chroot phase''', + action="store_true", + default=False) + + # Disable initramfs build optional argument + parser.add_argument('-i', '--initrd', + help='''Enable initramfs build action inside the chroot phase''', + action="store_true", + default=False) + + # Enable automatic mode. + parser.add_argument('--auto', + help="Enable automatic mode. All prompt actions will turn to yes/continue.", + action="store_true", + default=False) + + # Enforce arguments + parser.add_argument('--enforce', + help="Enforce (force) a specific Part of the process. More about stages and parts at man gse.5", + action="store", + default=None, + type=str) + + # Lawful-good arguments + parser.add_argument('--lawfulgood', '--lawful-good', + help="Lawful good (pass) a specific Part of the process. More about stages and parts at man gse.5", + action="store", + default=None, + type=str) + + # Distcc + parser.add_argument('--distcc', + help="Enable distcc mode for the system build process. For pump, give --distcc=pump. See man 5 gse for more informations.", + action="store", + default=None, + type=str) + + # Ccache + parser.add_argument('--ccache', + help="Enable ccache for the system build process.", + action="store_true", + default=False) + + # Edit configs option + parser.add_argument('-e', '--edit', + help='''Edit X:Y config. Where X is the category and Y is the file. See man gse.1 for more informations''', + action="store", + type=str) + + elif sequence == 'controller': + # Build the controller option + parser.add_argument('-bc', '--controller', '--build-controller', + help='''Request the initramfs-controller image. Not to confuse with the --initrd. See man gse.1 for more informations.''', + action="store_true", + default=False) + + # Force option + parser.add_argument('--force', + help="Enable Dracut's force flag. The option is for simplicity over --dracut_opt=-f", + action="store_true", + default=False) + + # Hook script option + parser.add_argument('--hook', + help="Add custom scripts to Dracut hook points. Use this for simple scripts instead of creating new modules.", + action="store", + default=None, + type=str) + + # Net script option + parser.add_argument('--net', + help="Import a custom net script to be sourced before initiating the controller scripts. That is after udev has finished.", + action="store", + default=None, + type=str) + + # Module config + parser.add_argument('--modules', + help="Import a custom module config file under /etc/modprobe.d with name umod.conf.", + action="store", + default=None, + type=str) + + # Dracut's option cmdline + parser.add_argument('--dracut_opt', + help="Include extra options for dracut. For more info see man dracut", + action="store", + default=None, + type=str) + + args = parser.parse_args() + + del parser + del argparse + + return args + + +# Check system's arguments +def _check_args(args): + ''' + This function is directly related to the _export_args function. + The purpose of this function is to check given options and arguments and either give a pass or kill the process. + The pass/kill is defined from conditions that are not allowed to be executed simultaneously or they are either + missing or holding an invalid entry. + + Example 1: for --enforce gccat. This will kill the process, since gccat is not defined as one of the building hooks. + Example 2: for --sdir ~/my_scripts --do sc1:sc2:sc3 --ghook -gseed:+gportage:. Here the scripts are more than the hooks. + ''' + + # Libraries for + import os + from sys import argv + from gpyfunctions.tools.gseout import die, e_report, b_report + + # Opt conditions + def _opt_cond(args): + ''' + Check if there are enabled options that "collide" with each other. + If yes, issue a warning or die if the "collision" is significant. + ''' + + if args.quiet and not args.verbose == None: + die("Error: Quiet and Verbose can not be used at the same time") + + if args.forcenew and args.keep: + die("Error: Force new can not be used with keep") + + if args.edit and not len(argv[1:]) == 2: + die("Invalid options for --edit. Edit can only be used alone as option. Please give only the related XY number.") + + if args.forcenew and not args.lawfulgood == None: + die("Warning: --force-new suppresses --lawful-good") + + if not args.lawfulgood == None and not args.enforce == None: + e_report("Warning: --lawful-good suppresses --enforce") + + if args.healthcheck and not len(argv[1:]) == 1: + die("Warning: --health-check unknown parameters") + + if args.replacenew and not len(argv[1:]) == 1: + die("Warning: --replace-new unknown parameters") + + # Issue warning if minimal and enforce with ginst or gkernel or gintrid are enabled simultaneously + if args.minimal: + _minimal_exclude = [ "ginst", "gkernel", "gintrid"] + + for i in _minimal_exclude[:]: + if i in args.enforce[:] and args.minimal: + e_report("Warning: --build-minimal suppresses " + i) + + del _minimal_exclude + + # Call opt conditions + _opt_cond(args) + + del _opt_cond + + def _hook_set(): + ''' + Here are defined the hooks of the system build process. + ''' + + # Create set with valid hook entries + __set = {"gfund", "gseed", "gcat", "gextr", "gprec", "gparta", "gupdate", "gportage", "grebuild", "gsnap"} + __set.add("gconfigure") + __set.add("ginst") + __set.add("grun") + __set.add("gkernel") + __set.add("ginitrd") + __set.add("gdes") + __set.add("gpartb") + __set.add("gclean") + + return __set + + # Check if --base=[catalyst/precomp] + if args.base == 'catalyst' or args.base == 'precomp': + e_report("System base set to: " + args.base) + else: + die("Wrong base entry. Please give either 'catalyst' or 'precomp'") + + # Export enforce hook point entries + if not args.enforce == None: + en_args = args.enforce + + args.enforce = [] + args.enforce = [x.strip() for x in en_args.split(':')] + + del en_args + + # Export default hook entries + _args_set = _hook_set() + + for _tmp1 in args.enforce[:]: + if not _tmp1 in _args_set: + die("Enforce: " + _tmp1 + " is not a valid hook point") + + del _args_set, _tmp1 + + # Print enforce hooks + e_report("Enforce enabled") + print("\033[0;34m Hooks:", "\033[0;33m", end='') + print(*args.enforce) + print("\033[0;0m") + + + # Export lawful-good hook point entries + if not args.lawfulgood == None: + lg_args = args.lawfulgood + + args.lawfulgood = [] + args.lawfulgood = [x.strip() for x in lg_args.split(':')] + + del lg_args + + # Export default hook entries + _args_set = _hook_set() + + for _tmp1 in args.lawfulgood[:]: + if not _tmp1 in _args_set: + die("Lawful-good: " + _tmp1 + " is not a valid hook point") + + del _args_set, _tmp1 + + # Print lawful-good hooks + e_report("Lawful enabled") + print("\033[0;34m Hooks:", "\033[0;33m", end='') + print(*args.lawfulgood) + print("\033[0;0m") + + # Script's --sdir checks + if not args.sdir == None: + if not os.path.isdir(args.sdir): + die("Sdir's location is not a directory") + + # Check if --do option has been given. + if not args.do == None: + do_args = args.do + + args.do = [] + args.do = [x.strip() for x in do_args.split(':')] + + del do_args + + # Check if given scripts exist + for i in args.do: + __sdir= (args.sdir + '/') + __is_file = (__sdir + i) + + if not os.path.isfile(__is_file): + die("The file " + i + " does not exist. " + "Please be sure that " + args.sdir + " is the correct directory that hosts the scripts.") + + del __is_file, __sdir + + # Count the number of scripts to compare them with the number of hook points later + do_nargs = len(args.do[:]) + + else: + # Issue error for missing --do + die("Scripts: --do script1:script2:...:scriptN are missing") + + # Check if --ghook option has been given + if not args.ghook == None: + ghook_args = args.ghook + + args.ghook = [] + args.ghook = [x.strip() for x in ghook_args.split(':')] + + del ghook_args + + # Check if given hook entries have a priority mark, issue warning and die otherwise + for _tmp1 in args.ghook[:]: + if _tmp1[0] != '-' and _tmp1[0] != '+': + die("Please give - or + at the beginning of each hook. See gse.1 and gse.5 for more informations and examples.") + + del _tmp1 + + # Export default hook entries + _args_set = _hook_set() + + # Check if the given entries are valid entries + for _tmp1 in args.ghook[:]: + if not _tmp1[1:] in _args_set: + die("Enforce: " + _tmp1 + " is not a valid hook point") + + del _tmp1, _args_set + + # Count ghook entries + ghook_nargs = len(args.ghook[:]) + + # Compare if scripts have equal hook points + if do_nargs == ghook_nargs: + del ghook_nargs, do_nargs + + else: + # Die if scripts are not equal to hook points and vice versa + die("Number of hook point entries does not match the number of given scripts") + + else: + # Die for missing + die("Hook points are missing: --ghook [+-]hook1:[+-]hook2:...:[+-]hookN:") + + + # Print the args.sdir, *args.do and *args.ghook + e_report("Scripts enabled") + print("\033[0;34m Directory: ", "\033[0;33m", end='') + print(args.sdir) + print("\033[0;34m Scripts: ", "\033[0;33m", end='') + print(*args.do) + print("\033[0;34m Hooks: ", "\033[0;33m", end='') + print(*args.ghook) + print("\033[0;0m") + + del die, argv, e_report, b_report + + +# Check controller's arguments +def _ct_check_args(args): + ''' + This function checks the controller arguments. + + Compared to the _export_args, while similar, this is more simple, since + Most of the controller flags are true/false entries and those that are not, are simple + input file entries. + ''' + + pass + + + + + + diff --git a/scripts/gpyfunctions/tools/warp.py b/scripts/gpyfunctions/tools/warp.py new file mode 100755 index 0000000..44589c7 --- /dev/null +++ b/scripts/gpyfunctions/tools/warp.py @@ -0,0 +1,496 @@ +#!/usr/bin/env python3.4 + +# Time state function +def time_state(args, CWORKDIR, CCONFDIR, CLOCALLG): + ''' + Time sate function. + Saves a state of configuration files + options + arguments for later use + Lists the saved states + Sets a state as a default state. The state must exist before this option is used + Deletes a saved state from the list + ''' + + import os + import datetime + from gpyfunctions.tools.gseout import die, e_report, b_report, lr_report + + # Create state directory, for hosting the state entries + if not os.path.exists(CLOCALLG + "/states"): + os.makedirs(CLOCALLG + "/states") + + # Save a state + if args.timestate[0] == "save": + + # Check if state name has been given, die if not + try: + if args.timestate[1]: + pass + + # Counter for the states mark + k = 1 + # Export directory's contents to a state list + _tmp_state_list =os.listdir(CLOCALLG + "/states/") + + # Define state's mark (k) value + for _tmp1 in _tmp_state_list[:]: + try: + if k < 10: + if str(k) == _tmp1[0:1]: + k += 1 + + elif k >= 10: + if str(k) == _tmp1[0:2]: + k += 1 + + except IndexError: + break + + del _tmp_state_list + + try: + del _tmp1 + + except NameError: + pass + + # Date and time + _state_date = str(datetime.datetime.today().strftime("date-%Y-%m-%d-time-%H-%M")) + + del datetime + + # Check if the state directory is indeed missing then create it. Issue warning and die otherwise + if not os.path.exists(CLOCALLG + "/states/" + str(k) + "_" + args.timestate[1] + "-" + _state_date): + os.makedirs(CLOCALLG + "/states/" + str(k) + "_" + args.timestate[1] + "-" + _state_date) + # Text report + print("\033[0;33mCreated state entry:", "\033[0;33m", end='') + print("\033[0;34m" + str(k) + "_" + args.timestate[1] + "-" + _state_date) + + else: + die("Can not create state: " + args.timestate[1] + ", because the state already exists") + + except IndexError: + # Name has not been given, since 1 gives an index error + die("Missing name for --time-state save") + + + # Full path and state name + _abs_state_name = (CLOCALLG + "/states/" + str(k) + "_" + args.timestate[1] + "-" + _state_date) + _state_name = (str(k) + "_" + args.timestate[1] + "-" + _state_date) + + # Function for copying config.d/system directory + def _copy_config_target(CCONFDIR, target, _abs_state_name): + ''' + Copy either .../config.d/system or .../config.d/controller to the newly created state. + The decision is based on the nature of the saved state. If it was called under the sequence=system variable, + then system is copied and if it was called under the sequence=controller variable, then controller is copied. + ''' + + # Import shutil for enabling copy functionality + import shutil + + try: + # Copy the system directory + shutil.copytree(CCONFDIR + '/' + target, _abs_state_name + '/' + target) + + # Text report + print("\033[0;33m Saving:", "\033[0;33m", end='') + b_report("config.d/" + target + " to state") + + except FileNotFoundError: + die(" File not found error. If config.d/system exists, please report this bug.") + + except FileExistsError: + die(" File exists error. Please report the bug!") + + del shutil + + # System case + if args.target == 'system': + # Create main_flags file under state directory and make it writable + with open(_abs_state_name + '/main_flags', 'w') as _s_entry: + _system_entries = {} + _system_entries["State name: "] = _state_name + _system_entries["State target : "] = args.target + _system_entries["System target: "] = args.base + _system_entries["Auto: "] = args.auto + _system_entries["Ccache: "] = args.ccache + _system_entries["Dev: "] = args.dev + _system_entries["Distcc: "] = args.distcc + + if args.enforce == None: + _system_entries["Enforce: "] = args.enforce + else: + _system_entries["Enforce: "] = "Enabled" + + if args.lawfulgood == None: + _system_entries["Lawful-good: "] = args.lawfulgood + else: + _system_entries["Lawful-good: "] = "Enabled" + + if args.sdir == None: + _system_entries["Sdir :"] = args.sdir + _system_entries["Do scripts :"] = "None" + _system_entries["GHooks :"] = "None" + else: + _system_entries["Sdir : "] = "Enabled" + _system_entries["Do scripts :"] = "Enabled" + _system_entries["GHooks :"] = "Enabled" + + _system_entries["Fetch new: "] = args.fetchnew + _system_entries["Force new: "] = args.forcenew + _system_entries["Initrd: "] = args.initrd + _system_entries["Keep: "] = args.keep + _system_entries["Kernel: "] = args.kernel + _system_entries["Minimal build: "] = args.minimal + _system_entries["No checks: "] = args.nochecks + _system_entries["Quiet :"] = args.quiet + _system_entries["Verbose : "] = args.verbose + + # Write system enabled/disabled options + for key, value in _system_entries.items(): + _s_entry.write(str(key) + str(value) + '\n') + + # Text report + print("\033[0;33m Saving:", "\033[0;33m", end='') + b_report("Main options") + + if _s_entry.closed: + del _s_entry + else: + _s_entry.close() + del _s_entry + + # Write enforce entries + if args.enforce != None: + with open(_abs_state_name + '/enforce_hooks', 'w') as _e_entry: + for i in range(len(args.enforce[:])): + _e_entry.write("Hook " + str(i) + " : " + args.enforce[i] + '\n') + + if _e_entry.closed: + del _e_entry + else: + _e_entry.close() + del _e_entry + + del i + + # Text report + print("\033[0;33m Saving:", "\033[0;33m", end='') + b_report("Enforce arguments") + + # Write lawful-good entries + if args.lawfulgood != None: + with open(_abs_state_name + '/lawfulgood_hooks', 'w') as _l_entry: + for i in range(len(args.lawfulgood[:])): + _l_entry.write("Hook " + str(i) + " : " + args.lawfulgood[i] + '\n') + + + if _l_entry.closed: + del _l_entry + else: + _l_entry.close() + del _l_entry + + del i + + # Text report + print("\033[0;33m Saving:", "\033[0;33m", end='') + b_report("Lawful-good arguments") + + # Write do scripts + if args.sdir != None: + # Import shutil for enabling copy functionality + import shutil + + # Create doscripts file with write permissions + with open(_abs_state_name + '/doscripts', 'w') as _do_entry: + # Text report + print("\033[0;33m Configuring:", "\033[0;33m", end='') + b_report("Do scripts") + + # Write the directory path + _do_entry.write("Do scripts : Enabled" + '\n') + _do_entry.write("Path : " + args.sdir +'\n') + + # Write the total number of scripts + _do_entry.write('\n') + _do_entry.write("Script's Num : " + str(len(args.do)) + '\n') + + # Create do_scripts directory to host the requested do scripts + os.makedirs(_abs_state_name + '/do_scripts') + + # Write the requested scripts entries and copy the script files at do_scripts + for i in range(len(args.do[:])): + _do_entry.write("Requested Script " + str(i) + " : " + args.do[i] + '\n') + + try: + shutil.copy2(args.sdir + '/' + args.do[i], _abs_state_name + '/do_scripts', follow_symlinks=True) + + except FileNotFoundError: + die("File not found error. If the scripts exist, please report this bug.") + + except FileExistsError: + die("File exists error. Please report the bug!") + + # Text report + print("\033[0;33m Saving:", "\033[0;33m", end='') + b_report("Scripts to state") + + # Write the total hook's number. Must be equal to total script's number + _do_entry.write('\n') + _do_entry.write("Hook's Num : " + str(len(args.ghook)) + '\n') + + # Write the requested scripts entries and copy the script files at do_scripts + for j in range(len(args.ghook[:])): + _do_entry.write("Requested Hook-Point " + str(i) + " : " + args.ghook[j] + '\n') + + # Text report + print("\033[0;33m Saving:", "\033[0;33m", end='') + b_report("Hooks to state") + + del i, j, shutil + + if _do_entry.closed: + del _do_entry + else: + _do_entry.close() + del _do_entry + + # Call system copy function + _copy_config_target(CCONFDIR, "system", _abs_state_name) + + del _copy_config_target + + elif args.target == 'controller': + # Create main_flags file under state directory and make it writable + with open(_abs_state_name + '/main_flags', 'w') as _s_entry: + _controller_entries = {} + _controller_entries["State name: "] = _state_name + _controller_entries["State target : "] = args.target + _controller_entries["System target: "] = "None" + _controller_entries["Build Controller: "] = args.controller + _controller_entries["Force: "] = args.force + _controller_entries["Dev: "] = args.dev + _controller_entries["Keep: "] = args.keep + _controller_entries["Minimal build: "] = args.minimal + _controller_entries["No checks: "] = args.nochecks + _controller_entries["Quiet :"] = args.quiet + _controller_entries["Verbose : "] = args.verbose + + if args.hook == None: + _controller_entries["Hook scripts: "] = "None" + else: + _controller_entries["Hook scripts: "] = "Enabled" + + if args.net == None: + _controller_entries["Net script: "] = "None" + else: + _controller_entries["Net script: "] = "Enabled" + + if args.modules == None: + _controller_entries["Custom modules config: "] = "None" + else: + _controller_entries["Custom modules config: "] = "Enabled" + + if args.dracut_opt == None: + _controller_entries["Dracut options: "] = "None" + else: + _controller_entries["Dracut options: "] = "Enabled" + + # Write system enabled/disabled options + for key, value in _controller_entries.items(): + _s_entry.write(str(key) + str(value) + '\n') + + del _controller_entries, key, value + + if _s_entry.closed: + del _s_entry + else: + _s_entry.close() + del _s_entry + + # Call system copy function + _copy_config_target(CCONFDIR, "controller", _abs_state_name) + + e_report("===========================================================================================") + e_report("State has been saved. To refer at this state in the future, use --time-warp=[state's mark]") + e_report("===========================================================================================") + + # List states + elif args.timestate[0] == "list": + try: + if args.timestate[1]: + print("\033[0;33mTime state:", "\033[0;33m") + die(" Unknown " + args.timestate[1] + " option.") + + except IndexError: + if os.path.isdir(CLOCALLG + "/states"): + _list_states = os.listdir(CLOCALLG + "/states/") + + print("\033[0;33mStates list:", "\033[0;33m") + for i in _list_states[:]: + b_report(" " + i) + + del _list_states, i + + else: + print("\033[0;33mTime state:", "\033[0;33m") + b_report(" Nothing to show. No state has been saved!") + + elif args.timestate[0] == 'set': + try: + if args.timestate[1]: + pass + + if args.timestate[1] != '-': + if os.path.isdir(CLOCALLG + "/states"): + _list_states = os.listdir(CLOCALLG + "/states/") + + _list_marks = [] + for i in _list_states[:]: + _list_marks.append(i[0]) + + del _list_states, i + + for j in _list_marks[:]: + if args.timestate[1] == j: + _set_state = str(j) + break + else: + _set_state = None + + del _list_marks, j + + if _set_state == None: + print("\033[0;33mTime state:", "\033[0;33m") + die(" No such a state mark.") + else: + try: + os.remove(CLOCALLG + "/states/default") + except FileNotFoundError: + pass + + with open(CLOCALLG + "/states/default", 'w') as _set_default: + _set_default.write("Default : " + _set_state + '\n') + + if _set_default.closed: + del _set_default + else: + _set_default.close() + del _set_default + + print("\033[0;33mTime state:", "\033[0;33m") + b_report(" Default state has been set to: " + _set_state) + del _set_state + else: + print("\033[0;33mTime state:", "\033[0;33m") + die(" No state has been configured, hence none can be set.") + + elif args.timestate[1] == '-': + if os.path.isfile(CLOCALLG + "/states/default"): + os.remove(CLOCALLG + "/states/default") + + with open(CLOCALLG + "/states/default", 'w') as _set_default: + _set_default.write("Default : None" + '\n') + + print("\033[0;33mTime state:", "\033[0;33m") + b_report(" Default state has been unset") + + if _set_default.closed: + del _set_default + else: + _set_default.close() + del _set_default + + except IndexError: + print("\033[0;33mTime state:", "\033[0;33m") + die(" Error: missing mark [M]. To unset a default entry give \'-\' instead of mark. See man 1 gse.") + + elif args.timestate[0] == 'del': + try: + if args.timestate[1]: + pass + + if os.path.isdir(CLOCALLG + "/states"): + _list_states = os.listdir(CLOCALLG + "/states/") + + for i in _list_states[:]: + if args.timestate[1] == i[0]: + _del_state = str(i) + break + else: + _del_state = None + + del _list_states, i + + if _del_state == None: + print("\033[0;33mTime state:", "\033[0;33m") + die(" State does not exist.") + else: + import shutil + try: + shutil.rmtree(CLOCALLG + "/states/" + _del_state, ignore_errors=False, onerror=None) + print("\033[0;33mTime state:", "\033[0;33m") + b_report(" State: " + _del_state + " has been deleted") + del shutil + + except FileNotFoundError: + print("\033[0;33mTime state:", "\033[0;33m") + die(" Error file not found. If the state exists, please report this bug.") + + del _del_state + + else: + print("\033[0;33mTime state:", "\033[0;33m") + die(" No state has been configured, hence none can be deleted.") + + except IndexError: + die("Time-state: Error no state mark [M] was given") + + else: + print("\033[0;33mTime state:", "\033[0;33m") + die(" No valid option. Please give --time-state [save/list/set/del] [sstate_name/-/M/M]") + + +def warp(target, args, CWORKDIR, CCONFDIR, CLOCALLG): + ''' + Warp function. + This is function is the function that controls all actions that are made after a sequence has been set and enabled. + Simply put, the _call_main function, which is the one initiated under the __init__ == __main__ condition, is only + checking / exporting environmental variables before calling this warp. + ''' + + # Check the arguments + if target is "system": + # system arguments + from gpyfunctions.tools.librarium import _check_args + _check_args(args) + + del _check_args + + elif target is "controller": + # controller arguments + from gpyfunctions.tools.librarium import _ct_check_args + _ct_check_args(args) + + del _ct_check_args + + # Call time state + if args.timestate is not 'no': + time_state(args, CWORKDIR, CCONFDIR, CLOCALLG) + + exit(1) + return 0 + +# _auto_def_silence_def "$@" + +# _flags_stagea+=("${_flag_base}") + +# if [[ -n "${_flag_base}" ]]; then +# source "${CWORKDIR}/scripts/sinit" "${_flags_stagea[@]}" +# elif [[ -z "${_flag_base}" && -n "${_flag_fetch}" ]]; then +# _call_fetch_new "$@" +# fi + +# # STAGE C +# }
\ No newline at end of file |