GRAPHIC: New Entity Operations™ Alpha Logo

EntityScript



core_add




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

core_add is a module to make, create, alter, and reseed 'LOCAL',
'SYSTEM', and 'GLOBAL' communication attributes, including 'logs of last
resort'.

"""
__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 (BUCKET_BINGO, CReal, Cure, Empty,
 generic_bucket_write, oFo, LAdd, PATH_INSTANCE, system_member, terms_add,
 TimeZone, VerifiedTime, WAS_VALID)

## Imports: Custom
from core_middlelayer import (DIRDATA, FILE_TEXT_SERVER, PHASE_CORE,
 PHASE_FIGMENT, PHASE_SERVER, TIMECODE, TIMETYPE)

## Alerts, Testing, Logging
from core_alerts import (ALERT_LOGGING_INFO, ALERT_LOGGING_WARNING)

## MODE.debug_interface
from MODE.debug_interface import DEBUG_INTERFACE_OPTIONS

## MODE.debug_logger
from MODE.debug_logger import DEBUG_LOGGER

## MODE.debug_security
from MODE.debug_security import DEBUG_SECURITY

## Log maker
from core_interface import (Ring, io_bucket as IB, IPDVC, LogMaker as LM,
 TimeStamp as TS)

## C.ORE Class
"""
Information: core_add.py base information: Defaults to the author and version
provided by the program, but you can modify the author and version to any
format you find necessary to reflect the creator of entries on your machine
"""
Information = {terms_add.AUTHOR: __author__, terms_add.VERSION: __version__}

class SET_POSTER:
 """
 'SET_POSTER' will augment the logs I/O member record
 """
 def bind():
  """
  'bind' the attributes of the member to the log making code
  check member attributes
  """
  IB.member_bucket.clear()
  with open(
   PATH_INSTANCE+DIRDATA+'active_member.es', oFo.read) as ACTIVE_MEMBER_SETTER:
   for row in ACTIVE_MEMBER_SETTER:
    var_z = row
    IB.member_bucket.append(var_z)
  ACTIVE_MEMBER_SETTER.close()
  if IB.member_bucket[0] == system_member:
   DEBUG_SECURITY.member_in_use(TYPE=terms_add.USER_ADMIN_IN_USE)
  else:
   DEBUG_SECURITY.member_in_use(TYPE=terms_add.USER_STANDARD_IN_USE)

def default_add(default=Empty.instance, figment_stream=Empty.instance,
 PHASE=PHASE_FIGMENT):
 """
 Append a figment to PHASE_FIGMENT

 All 'figment_stream' instances default to None, but can be extended to be
 stored longer-term into a database structure

 To add a default figment:

 default_add()

 """
 if default is Empty.instance and figment_stream is Empty.instance:
  ## If default is provided as empty, ask for it. If not, the routine is
  ## sourced from a graphics instance and should be automated
  if default is Empty.instance:
   ADD_TO_PHASE = input(terms_add.GENERATE_FIGMENT)+Cure.terminate_line
   default = ADD_TO_PHASE
  else:
   ADD_TO_PHASE = str(default)
  Stream_Type = terms_add.STREAM_TYPE
  PHASE = PHASE
 elif PHASE.lower() == terms_add.PHASE_SERVER:
  ## If default is provided as empty, ask for it. If not, the routine is
  ## sourced from a graphics instance and should be automated
  if default is Empty.instance:
   ADD_TO_PHASE = input(terms_add.ADD_TO_PHASE_SERVER)+Cure.terminate_line
   default = ADD_TO_PHASE
  else:
   ADD_TO_PHASE = str(default)
  Stream_Type = figment_stream
  PHASE = PHASE_SERVER
 else:
  ADD_TO_PHASE = input(terms_add.ADD_TO_PHASE)+Cure.terminate_line
  Stream_Type = figment_stream
  PHASE = PHASE

 # Append to - won't skip a line
 with open(
  PATH_INSTANCE+DIRDATA+PHASE, oFo.append_text) as phase:
  time_stamp = LM.date
  date_stamp = LM.time
  if TIMETYPE == VerifiedTime.SERVER:
   # 'S' represents 'server-verified time'
   time_type = VerifiedTime.SERVER
  else:
   # U represents 'unverified time'
   time_type = VerifiedTime.UNVERIFIED
  if TIMECODE == TimeZone.UNIVERSAL:
   # Default is UTC
   time_code = TimeZone.UNIVERSAL
  else:
   ## Other specific codes are permitted
   time_code = TIMECODE

  SLUG_COMM = Cure.wall_left+time_type+Cure.wall_right+\
   Cure.wall_left+time_code+Cure.wall_right+\
   Cure.wall_left+date_stamp+Cure.wall_buffer_left+\
   Cure.wall_left+time_stamp+Cure.wall_right_buffer+\
   Cure.wall_buffer_left+IB.member_bucket[0]+Cure.wall_right_buffer_divider+\
   Cure.wall_buffer_left+Stream_Type+Cure.wall_right_buffer_divider+\
   ADD_TO_PHASE

  ## Commit the slug
  DEBUG_ADD.server_comm(COMM=SLUG_COMM)
  phase.write(SLUG_COMM)

  ## Update the Ring
  if PHASE==PHASE_FIGMENT:
   DEBUG_INTERFACE_OPTIONS.phase_to_tally_figment()
   Ring.ENTITY.tally_phase_figment()
  if PHASE==PHASE_SERVER:
   DEBUG_INTERFACE_OPTIONS.phase_to_tally_server()
   Ring.ENTITY.tally_phase_server()
  ## Provide any additional phases that require a re-tally
  else:
   DEBUG_INTERFACE_OPTIONS.phase_to_tally_none()

  ## Provide the SLUG_COMM
  return(SLUG_COMM)

  ## LOGGER: Special
  logger = LAdd.logger_default_add
  helper = LAdd.helper_default_add
  special = Cure.wall_left+IB.member_bucket[0]+generic_bucket_write+\
   time_code+Cure.wall_right
  DEBUG_LOGGER.special(INSTANCE=logger+helper+\
   ALERT_LOGGING_INFO(variable=logger+helper+special))
 ## Close the phase
 phase.close()

def server_add(wipe=CReal.no):
 """
 Take your local PHASE_SERVER.es file and append it to your core.es
 master dump-all-to file.
 """
 def wipe_local():
  """
  Establish the default 'wipe_local' routine in the current scope
  """
  # Write to - will overwrite the core.es file
  with open(
   PATH_INSTANCE+DIRDATA+PHASE_SERVER, oFo.write_text) as phase_server:
   phase_server.write(FILE_TEXT_SERVER+Cure.terminate_line)
   ## LOGGER
   logger =LAdd.logger_server_add_wipe
   helper = LAdd.helper_server_add_wipe
   DEBUG_LOGGER.generic(INSTANCE=logger+helper+\
    ALERT_LOGGING_WARNING(variable=logger+helper+Cure.terminate_line))
  phase_server.close()

 def do():
  """
  'do' routine - a method to submit and reseed 'PHASE_SERVER' on
  behalf of merging into 'core.es' with storage-ready values
  """
  with open(PATH_INSTANCE+DIRDATA+PHASE_CORE, oFo.append) as serv:
   with open(PATH_INSTANCE+DIRDATA+PHASE_SERVER, oFo.read) as phase_server:
    # Go to Line 1, ignoring the heading
    for line in phase_server:
     if line.startswith(Cure.pound):
      pass
     else:
      serv.write(line)
      ## LOGGER
      server_add__do__LOGGER = logger_default_add_do
      server_add__do__helper = helper_default_add_do
      DEBUG_LOGGER.generic(INSTANCE=server_add__do__LOGGER+\
       server_add__do__helper+ALERT_LOGGING_WARNING(variable=\
        server_add__do__LOGGER+\
        server_add__do__helper))
   phase_server.close()
  serv.close()

 ## If you do not wipe the instance, a backup is made
 if wipe == CReal.no:
  do()
  wipe_local()
  DEBUG_ADD.server(OPTIONS=terms_add.ADDED_TO_CORE_NO_WIPE)
 ## If you wipe the instance, no backup is made, and the phase is destroyed
 elif wipe == CReal.yes:
  wipe_local()
  DEBUG_ADD.server(OPTIONS=terms_add.ADDED_TO_CORE_WIPED)

# This runs every time core_add is imported or used with Run: core_add.py
# default_add()

# This runs each additional time you want to add figments once imported
def server_add_default():
 """
 Default 'add' method to add one figment instance to 'PHASE_SERVER'
 """
 default_add()

def add_to_server():
 """
 Default 'add to server' method to add the 'PHASE_SERVER' information
 to local server, that can be forked into a distributed peer-read-writable
 server
 """
 server_add()



Return HOME