aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos.K <freedomrfox@gmail.com>2017-10-09 17:53:21 +0000
committerChristos.K <freedomrfox@gmail.com>2017-10-09 17:53:21 +0000
commit91f08d077fca6b76e9ce18c6731ec53329e168f8 (patch)
tree2236ded34a1bb23e0b932b606fd703c10ac372ff
parentgportal: gse gui menu (diff)
downloadGSE-91f08d077fca6b76e9ce18c6731ec53329e168f8.tar.gz
GSE-91f08d077fca6b76e9ce18c6731ec53329e168f8.tar.bz2
GSE-91f08d077fca6b76e9ce18c6731ec53329e168f8.zip
Minor flow changes
-rwxr-xr-xbin/gse.py271
1 files changed, 177 insertions, 94 deletions
diff --git a/bin/gse.py b/bin/gse.py
index fcc02c0..65fd4be 100755
--- a/bin/gse.py
+++ b/bin/gse.py
@@ -1,104 +1,76 @@
-#!/usr/bin/env python3.6
-
-def _call_main():
- # Essential libraries
- import os, sys
- from os import system, getcwd
- from sys import argv, exit
-
- # Export current working category
- CWORKDIR = getcwd()
-
- if CWORKDIR in '/usr/bin' and os.path.isfile('/usr/lib64/gse/gse'):
- # If the project has been installed to root
- #prnt("system") # Exists only: for testing
- 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 os.path.isdir(os.path.dirname(CWORKDIR)+'/.git'):
- # If the project has been git cloned or simply copied to a location
- CWORKDIR = os.path.dirname(CWORKDIR)
- #print(CWORKDIR) # Exists only: for testing
- CFUNCTIONS = CWORKDIR+'/scripts/pyfunctions'
- CCONFDIR = CWORKDIR+'/config.d'
- CDISTDIR = CWORKDIR+'/dist.d'
- CLOCALLG = CWORKDIR+'/local'
- CLOGLG = CWORKDIR+'/var/log'
- CSYSROOT = CWORKDIR+'/sysroot'
- CLOCALLIB = CWORKDIR+'/var/lib'
-
-
- # Append new python path at CWORKDIR + /scripts/pyfunctions
- sys.path.append(CFUNCTIONS)
-
-
- # Simplle die function
- from gseout import die
-
- # Import yellow, green, blue and purple color reports
- from gseout import e_report, g_report, b_report, p_report
-
- # Cmdline argument's function
+#!/usr/bin/env python3.4
+
+def _call_main(_gpyfunc_):
+ '''
+ Main function
+ This function:
+ Detects the project's directory and exports it with it's sub-dirs
+ Exports the given arguments and options
+ Exports the build sequence
+ Brings up the text/gui menu if given from the arguments
+ Last, enables the exported sequence (build process)
+ '''
+
+ # Simple die function and yellow, green, blue and purple color reports
+ from gpyfunctions.tools.gseout import die, e_report, g_report, b_report, p_report
+
+ # Check target and export args
def gse_args():
- if 'system' in argv[1:2]:
+ '''
+ Exports the sequence variable
+ Calls _export_args which defines and exports the final arguments based on the sequence
+ '''
+
+ if any('system' in _tmp1 for _tmp1 in argv[1:]):
sequence = "system"
- elif 'controller' in argv[1:2]:
+ elif any('controller' in _tmp1 for _tmp1 in argv[1:]):
sequence = "controller"
- elif '-h' in argv[1:2] or '--help' in argv[1:2]:
- sequence = "target"
+ elif any('-h' in _tmp1 for _tmp1 in argv[1:]) or any('--help' in _tmp2 for _tmp2 in argv[1:]):
+ # For missing target arguments and given help option. Call general args.
+ sequence = "help"
+ elif any('-V' in _tmp1 for _tmp1 in argv[1:]) or any('--version' in _tmp2 for _tmp2 in argv[1:]):
+ # For missing target arguments and given version option. Print version.
+ sequence = "version"
else:
- sequence = "err"
+ # Die for missing target and help opt
+ e_report("You must specify exactly one of: 'system' or 'controller' targets")
+ e_report("See gse -h or gse 5 for more info and gse 1 for options manpage")
+ die('')
- # Check if base and controller are issues at the same time. If yes, exit with error
- if sequence in 'system' or sequence in 'controller':
- if any('system' in item1 for item1 in argv[1:]) and any ("controller" in item2 for item2 in argv[1:]):
- die("Error: System and Controller arguments can not be issued at the same time. " +
- "Only one operating at a given time can be supported.")
+ # # Check if base and controller are issues at the same time. If yes, exit with error
+ # if sequence in 'system' or sequence in 'controller':
+ # if any('system' in item1 for item1 in argv[1:]) and ("controller" in item2 for item2 in argv[1:]):
+ # die("Error: System and Controller arguments can not be issued at the same time. " +
+ # "Only one operating at a given time can be supported.")
if sequence == "system":
# Export arguments for system sequence
- from arg_opt import _export_args
+ from gpyfunctions.tools.librarium import _export_args
- b_report("System sequence enabled")
+ # Evaluate the arguments
+ p_report("System sequence enabled")
args = _export_args(sequence)
del _export_args
- from arg_opt import _check_args
- _check_args(args)
-
- del _check_args
-
-
elif sequence == 'controller':
# Export arguments for controller sequence
- from arg_opt import _export_args
+ from gpyfunctions.tools.librarium import _export_args
- b_report("Controller sequence enabled")
+ # Evaluate the arguments
+ p_report("Controller sequence enabled")
args = _export_args(sequence)
del _export_args
- from arg_opt import _ct_check_args
- _ct_check_args(args)
-
- del _ct_check_args
-
- elif sequence == 'target':
- from arg_opt import _export_args
-
+ elif sequence == 'help':
+ # Print --help
+ from gpyfunctions.tools.librarium import _export_args
+ args = _export_args(sequence)
+ elif sequence == 'version':
+ # Print --version
+ from gpyfunctions.tools.librarium import _export_args
args = _export_args(sequence)
- elif sequence == "err":
- e_report("You must specify exactly one of: 'system' or 'controller' targets as the first argument")
- e_report("See gse -h or gse 5 for more info and gse 1 for options manpage")
- die('')
return args, sequence
@@ -110,7 +82,7 @@ def _call_main():
del gse_args
# Import dist check function
- from preliminary import _is_gentoo
+ from gpyfunctions.preliminary import _is_gentoo
# Check the output. In case of a fail, issue warning and abort
if _is_gentoo() == 0:
@@ -128,7 +100,7 @@ def _call_main():
del _is_gentoo
# Import super user check function
- from preliminary import _is_su
+ from gpyfunctions.preliminary import _is_su
# Pass if super user, issue warning if not and abort
if _is_su() == 0:
@@ -142,31 +114,142 @@ def _call_main():
del _is_su
- # If args.mm, initiate text menu
- if args.mm:
- from preliminary import _call_menu
- _ex_stat = _call_menu(CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR)
+ if (args.mm or args.gmm):
+ # Check for mm && gmm conflict
+ if args.mm and args.gmm:
+ die("Error: Use one of [--mm/--gmm]")
+
+ # If args.mm, initiate text menu
+ if args.mm:
+ from gpyfunctions.menu.txmen.gsetxf import _call_menu
+ _ex_stat = _call_menu(CWORKDIR, CFUNCTIONS, CCONFDIR, CDISTDIR)
+
+ del _call_menu
+
+ # if args.gmm, initiate GUI menu
+ if args.gmm:
+ from gpyfunctions.menu.portal.gportal import _gmm
+ _ex_stat = _gmm()
+
+ del _gmm
+
+ return _ex_stat
+
+ elif sequence is "system" or sequence is "controller":
+ from gpyfunctions.tools.warp import warp
+ _ex_stat = warp(sequence, args, CWORKDIR, CCONFDIR, CLOCALLG)
+
+ del warp
+
+ return _ex_stat
+ else:
+ return 9
+
+# EO_call_main
+
+
+# Essential libraries
+from sys import argv, exit
+from os import path as ospath
+from sys import path as syspath
+
+# Append gpyfunctions from /usr/lib64/gse/scripts/
+if ospath.isdir('/usr/lib64/gse/scripts/gpyfunctions'):
+ if ospath.isfile('/usr/lib64/gse/scripts/gpyfunctions/__init__.py'):
+ syspath.append('/usr/lib64/gse/scripts')
+ _gpyfunc_ = "sys"
+
+# Append gpyfunctions from git chase
+elif ospath.isdir('../scripts/gpyfunctions'):
+ if ospath.isfile('../scripts/gpyfunctions/__init__.py'):
+ syspath.append("../scripts")
+ _gpyfunc_ = ".git"
+else:
+ print("Could not locate gpy modules path")
+ exit(1)
+
+def __gse_mod_check():
+ from sys import exit
+
+ try:
+ import gpyfunctions
+ del gpyfunctions
+
+ from gpyfunctions import preliminary
+ del preliminary
+
+ from gpyfunctions.tools import gseout
+ del gseout
+
+ from gpyfunctions.tools import librarium
+ del librarium
+
+ from gpyfunctions.tools import warp
+ del warp
+
+ from gpyfunctions.menu.txmen import gsub_men
+ del gsub_men
+
+ from gpyfunctions.menu.txmen import gsetxmen
+ del gsetxmen
+
+ from gpyfunctions.menu.txmen import gsetxf
+ del gsetxf
+
+ from gpyfunctions.menu.portal import gportal
+ del gportal
- del _call_menu
+ except ImportError:
+ raise
+ exit(1)
+
+ print("\033[1;35mAll gse modules are healthy\033[0;0m\n")
+
- # if args.gmm, initiate gui menu
- if args.gmm:
- from gportal import _gmm
- _ex_stat = _gmm()
+# Check gpy modules. This function exists only in the experimental phase.
+__gse_mod_check()
- del _gmm
+del __gse_mod_check, ospath, syspath
- return _ex_stat
+# Import function for exporting CWORDKIR, ... PATHS
+from gpyfunctions.preliminary import _gse_path
+
+# Export the paths from _gse_path()
+CWORKDIR, CGSE, CFUNCTIONS, CCONFDIR, \
+CDISTDIR, CLOCALLG, CLOGLG, CSYSROOT, \
+CLOCALLIB = _gse_path(_gpyfunc_)
+
+del _gse_path
# Main function
if __name__ == "__main__":
- _ex_stat = _call_main()
+ try:
+ _ex_stat = _call_main(_gpyfunc_)
+
+ 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)
if _ex_stat == 0:
print("Success")
exit(0)
+
+ elif _ex_stat == 9:
+ print("No valid sequence")
+ exit(9)
+
else:
print("Fail")
exit(1)
+else:
+ print("Not Main")
+ exit(1)
+