import os import pprint import re import sys import yaml

from pathlib import Path

sys.path.append(

os.path.abspath("/home/x/programming/ruby/src/rbt/lib/rbt/python/")

)

from constants import * from e import *

# =========================================================================== # # This depends on the colored pip: # =========================================================================== # from colored import fg, bg, attr

# =========================================================================== # # Define all useful colours next: (colours tag) # =========================================================================== # tomato_on_black_background = bg(‘black’) + fg(‘red’) grey_on_black_background = bg(‘black’) + fg(‘grey_0’) orange_on_black_background = bg(‘black’) + fg(‘orange_4a’) slateblue1_on_black_background = bg(‘black’) + fg(‘slate_blue_3a’) light_magenta_on_black_background = bg(‘black’) + fg(‘light_magenta’)

sfancy = slateblue1_on_black_background # === sfancy() aquamarine1_on_black_background = bg(‘black’) + fg(‘aquamarine_1b’) lightskyblue1_on_black_background = bg(‘black’) + fg(‘light_sky_blue_3a’) rev1 = lightskyblue1_on_black_background lightskyblue2_on_black_background = bg(‘black’) + fg(‘light_sky_blue_3b’) rev = attr(‘reset’)

FIRST_ARGUMENT = sys.argv

# =========================================================================== # # === absolute_path # # The second argument denotes which suffix is in use. # =========================================================================== # def absolute_path(i, suffix = ‘.tar.xz’):

return os.path.abspath(os.path.basename(i)[:-len(suffix)])+"/"

# =========================================================================== # # === pretty_print # =========================================================================== # def pretty_print(i):

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(i)

# =========================================================================== # # === system # =========================================================================== # def system(i):

os.system(i)

# =========================================================================== # # === cd (cd tag) # =========================================================================== # def cd(i):

os.chdir(i)

# =========================================================================== # # === newline # =========================================================================== # def newline():

print("")

# =========================================================================== # # === do_show_the_blfs_entry() (blfs tag) # # Invocation example: # # compilepy htop –blfs # # =========================================================================== # def do_show_the_blfs_entry(first_argument = FIRST_ARGUMENT):

this_yaml_file = COOKBOOKS_DIRECTORY+first_argument+'.yml'

path = Path(this_yaml_file)

if path.is_file():

  with open(this_yaml_file) as this_file:
    dataset = yaml.load(this_file, Loader = yaml.FullLoader)

blfs_entry = dataset[':blfs']

if isinstance(blfs_entry, list):
  blfs_entry = blfs_entry[0]

newline()
e("  "+
  light_magenta_on_black_background+
  blfs_entry+
  rev
)
newline()

# =========================================================================== # # === menu (menu tag) # =========================================================================== # def menu(array):

for i in array:

  # ========================================================================= #
  # Build up a case/when "menu", python-style.
  # ========================================================================= #
  help_options = re.compile("^--help")
  blfs_entry   = re.compile("^--blfs")
  if (help_options.match(i)):
    show_the_available_help_options()
    exit()
  elif (blfs_entry.match(i)):
    do_show_the_blfs_entry();
    exit();
  else: # else do nothing.
    pass # print("NOPE")