GRAPHIC: New Entity Operations™ Alpha Logo

EntityScript



core_view




# -*- coding: utf-8 -*-
"""
COPYRIGHT (C) 2020-2023 NEW ENTITY OPERATIONS INC. ALL RIGHTS RESERVED
INSTANCE: core_view
MODIFIED: 2023/05/31
OVERVIEW:

core_view allows you to view various objects in TRINE by following the
provided conventions

Example:
:: Full instance, muted-print preview
z = core_view.instance_server(LINES=0, PRINT=0)
print(z)

or
:: Full instance, print-preview
z = core_view.instance_server(LINES=0, PRINT=1)

or
:: Qualified instance, no print-preview, last line
z = core_view.instance_server(LINES=1, PRINT=0)
print(z[LINES_NOW])

or
:: Qualified instance, print-preview
LINES_NOW = 2
z = core_view.instance_server(LINES=LINES_NOW, PRINT=1)

# full qualified_instance
print(z[0::LINES_NOW-1])
# instance slices (use a generated to loop through them)
print(z[0::LINES_NOW-1][0])
print(z[0::LINES_NOW-1][1])
# when exhausted
...
IndexError: list index out of range
"""
__version__ = "0.0.8"
__author__ = "Ryan McKenna"
__copyright__ = "Copyright (C) 2020-2023 New Entity Operations Inc."
__credits__ = [
 "Ryan McKenna",
 "New Entity Operations Inc.", "New Entity Operations, LLC"]
__email__ = "Operator@NewEntityOperations.com"
__license__ = "New Entity License"
__maintainer__ = "Ryan McKenna"
__status__ = "Production"

## MODE-> facilities
from MODE.facilities import (argv, ArgumentParser, BUCKET_PHASE,
 CReal, Cure, fVi, HView, LView, MODULE_MATCHER_MAIN, oFo, MView,
 OView, PATH_INSTANCE, TView)

## Bind dependent local variables
class BoundVariables:
 PATH_INSTANCE=PATH_INSTANCE

## _alerts
from core_alerts import (ALERT_LOGGING_INFO)
## _middlelayer
from core_middlelayer import (DIRDATA, PHASE_FIGMENT, PHASE_LOG, PHASE_SERVER)

## build_phase
def build_phase(LINES, PRINT,
 dir=Cure.muted, file=Cure.muted, helper=Cure.muted, location="SKIP",
 logger=Cure.muted, BUCKET_PHASE=BUCKET_PHASE):
 """
 Read from the CORE:

 Provide: dir, file, location, helper, logger, LINES, PRINT

 Any non-zero value for print returns a muted instance

 Provide a LINES=? value to get a returned ? value of most recent lines from
  the provided instance.

 location defaults to SKIP: This opens a localized phase. If location is
 overloaded, a custom path can be provided to a custom phase destination
 """
 PHASE = []
 if location=="SKIP":
  BoundVariables.PATH_INSTANCE=PATH_INSTANCE
 else:
  ## In the event of an overload, provide the updated values
  BoundVariables.PATH_INSTANCE=location
  dir=""
 with open(BoundVariables.PATH_INSTANCE+dir+file, oFo.read_text) as instance:
  ## flush the bucket_phase
  BUCKET_PHASE.clear()
  ## Read the instance
  ## If lines aren't specified, return the default 'instance_full'
  if LINES==CReal.no:
   data = instance.read()
   PHASE.append(data)
  else:
   for line in (serv.readlines() [-LINES:]):
    PHASE.append(line)
  ## LOGGER
  ALERT_LOGGING_INFO(variable=logger+helper)
  ## check for print
  if PRINT==CReal.no and LINES==CReal.no:
   ## Update the BUCKET_PHASE
   BUCKET_PHASE.append(data)
   return(data)
  else:
   ## This mode doesn't run with graphics, only with text-mode
   if PRINT == CReal.yes and LINES==CReal.no:
    print(logger+helper)
    print(data)
    ## Update the BUCKET_PHASE
    BUCKET_PHASE.append(data)
    return(data)
   elif PRINT == CReal.no and LINES != CReal.no:
    BUCKET_PHASE = PHASE.copy()
    ## return the instance
    return(PHASE[:])
   else:
    for i in PHASE:
     print(i)
    ## Update the BUCKET_PHASE
    BUCKET_PHASE = PHASE.copy()
    return(PHASE[:])

 ## Destroy the instance in memory
 instance.close()

## Call to the runner actions: These can be modified and extended as you need
## To create a new factor, add instance_* and supply the desired preset-values
def instance_figment(LINES=CReal.no, PRINT=CReal.no):
 """
 Provide a factory for your default figment instance 'PHASE_FIGMENT.es'
 """
 build_phase(LINES, PRINT, dir=DIRDATA, file=PHASE_FIGMENT,
  helper=LView.helper_figment, logger=LView.logger_figment,
  BUCKET_PHASE=BUCKET_PHASE)

def instace_log(LINES=CReal.no, PRINT=CReal.no):
 """
 Provide a factory for displaying the default log: complete 'log.es'
 """
 build_phase(LINES, PRINT, dir=DIRDATA, file=PHASE_LOG,
 helper=LView.helper_log, logger=LView.logger_log,
 BUCKET_PHASE=BUCKET_PHASE)

def instance_server(LINES=CReal.no, PRINT=CReal.no):
 """
 Provide a factory for your default server instance 'PHASE_SERVER.es'
 """
 build_phase(LINES, PRINT, dir=DIRDATA, file=PHASE_SERVER,
  helper=LView.helper_server, logger=LView.logger_server,
  BUCKET_PHASE=BUCKET_PHASE)

## MESH_CONTAINER
CONTAINER_MESH = {
 OView.LINES: Cure.muted,
 OView.PRINT: Cure.muted,
 OView.DIRECTORY: Cure.muted,
 OView.FILE: Cure.muted,
 OView.INSTANCE: Cure.muted,
 OView.HELPER: Cure.muted,
 OView.LOGGER: Cure.muted
}

# Runner: Run default view_* routines on import
if __name__ == MODULE_MATCHER_MAIN:
 parser_emulator = ArgumentParser()
 parser_emulator.add_argument(fVi.directory,
  help=HView[fVi.directory])
 parser_emulator.add_argument(fVi.file,
  help=HView[fVi.file])
 parser_emulator.add_argument(fVi.instance,
  help=HView[fVi.instance])
 parser_emulator.add_argument(fVi.LINES,
  help=HView[fVi.LINES])
 parser_emulator.add_argument(fVi.PRINT,
  help=HView[fVi.PRINT])
 parser_emulator.add_argument(fVi.helper,
  help=HView[fVi.helper])
 parser_emulator.add_argument(fVi.logger,
  help=HView[fVi.logger])
 args_available = parser_emulator.parse_args()
 ## example: default instance
 ## python core_view.py
 ## python core_view.py --instance
 ## example: custom instance
 ## python core_view.py --instance figment
 ##  --dir=/NOVASTORE/PROGRAMS/trine/DATA/ --file=PHASE_SERVER.es --LINES=0
 ##  --PRINT=1 --helper="provide full overview of server log]"
 ##  --logger="[view_server: "
 ## example: simple routine for the instance_server
 ## python core_view.py --instance server
 ARGS=argv[Cure.seperate]
 print(str(ARGS))
 ## If their is no arguments (just python core_view.py,
 ##  provide a default routine
 try:
  if argv[1]==Cure.muted:
   instance_figment(LINES=CReal.no, PRINT=CReal.yes)
  ## all runners start with a declared instance
  elif argv[1] == fVi.instance:
   try:
    ## if there is no argv[3] supplied, it's a preset routine
    try:
     z = argv[3]
     RUNNER = argv[2]
     if RUNNER == Cure.muted:
      print(TView.SET_ARGV_TO_DEFAULT)
      option = fVi.default
      instance_figment(LINES=CReal.no, PRINT=CReal.yes)
     else:
      MESH = CONTAINER_MESH
      print(TView.SET_ARGV_TO_CUSTOM)
      ## Provide a response of the provided inputs
      print(str(args_available))
      MESH_MERGE = {
      OView.LINES: args_available.LINES,
      OView.PRINT: args_available.PRINT,
      OView.DIRECTORY: args_available.dir,
      OView.FILE: args_available.file,
      OView.INSTANCE: args_available.instance,
      OView.HELPER: args_available.helper,
      OView.LOGGER: args_available.logger
      }
      MESH.update(MESH_MERGE)
      build_phase(dir=MESH[OView.DIRECTORY], file=MESH[OView.FILE],
       LINES=int(MESH[OView.LINES]), PRINT=int(MESH[OView.PRINT]),
       helper=MESH[OView.HELPER], logger=MESH[OView.LOGGER])
    except IndexError:
     try:
      RUNNER = argv[2]
      if RUNNER == MView.FIGMENT:
       instance_figment(LINES=CReal.no, PRINT=CReal.no)
      elif RUNNER == MView.SERVER:
       instance_server(LINES=CReal.no, PRINT=CReal.no)
      else:
       ## fallback to the default
       instance_figment(LINES=CReal.no, PRINT=CReal.no)
     except IndexError as e:
      print(str(e)+TView.INSTANCE_WAS_PROVIDED)
      instance_figment(LINES=CReal.no, PRINT=CReal.yes)
   except IndexError:
    print(TView.HAVE_TO_PROVIDE_INSTANCE)
 except IndexError:
  print(TView.HAVE_TO_PROVIDE_INSTANCE)



Return HOME