EntityScript

Draft 1.2:
Index


core_add




"""
Copyright (C) 2020 New Entity Operations Inc.

ALL RIGHTS RESERVED

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

"""
## Import the system stettings
from core_settings import (
    system_member,
)

## Imports: Custom
from core_middlelayer import (
    TIMECODE, TIMETYPE,
    COREES, DIRDATA,
    CONSTRUCTEDCOREES, CORE_FILE_TEXT
)

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

## Log maker
from core_interface import (
    Ring,
    TimeStamp as TS
)

AUTHOR = 'Ryan McKenna'
VERSION = 'Version 1.0'

## C.ORE Class
"""
Information: core_add.py base

"""
Information = {'author': AUTHOR, 'Version': VERSION}

class LogMaker:
    """
    Create standardized Logs. Inputs include date/time
    'LogMaker' can be expanded to include any preset routines or program schedules

    """
    date = TS.time_stamp_time()
    time = TS.date_stamp_day()

class io_bucket:
    """
    The 'io_bucket' holds the current member and defaults to 'system_member'

    """
    member_bucket = [system_member]

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

        """
        io_bucket.member_bucket.clear()
        with open('DATA/active_member.es', 'r') as ACTIVE_MEMBER_SETTER:
            for row in ACTIVE_MEMBER_SETTER:
                var_z = row
                io_bucket.member_bucket.append(var_z)
        ACTIVE_MEMBER_SETTER.close()
        if io_bucket.member_bucket[0] == system_member:
            print("Admin Member in use.")
        else:
            print("Standard Member in use.")

def default_add(default=None, figment_stream=None):
    """
    Append a figment to your local core.es file

    All 'figment_stream' instances default to None, but can be extended

    """
    if default is None and figment_stream is None:
        Core_Add = input("Generate Figment: ") + ' \n'
        Stream_Type = 'Stream_Type: default'
    else:
        Core_Add = default
        Stream_Type = figment_stream

    # Append to - won't skip a line
    with open(DIRDATA+COREES, 'at') as file_core_es:
        time_stamp = LogMaker.date
        date_stamp = LogMaker.time

        if TIMETYPE == 'S':
            # 'S' represents 'server-verified time'
            time_type = 'S'
        else:
            # U represents 'unverified time'
            time_type = 'U'

        if TIMECODE == 'UTC':
            # Default is UTC
            time_code = 'UTC'
        else:
            # Other specific codes are permitted
            time_code = TIMECODE

            SLUG_COMM = "["+time_type+"]"+"["+time_code+"]"+\
                "["+date_stamp+"] "+"["+time_stamp+"] "+\
                "[ "+io_bucket.member_bucket[0]+" :] "+\
                "[ "+Stream_Type+" :] "+Core_Add

            file_core_es.write("["+time_type+"]"+"["+time_code+"]"+\
                "["+date_stamp+"] "+"["+time_stamp+"] "+\
                "[ "+io_bucket.member_bucket[0]+" :] "+\
                "[ "+Stream_Type+" :] "+Core_Add)
            Ring.ENTITY.tally_core()
            return(SLUG_COMM)

            # LOGGER: Special
            default_add__LOGGER = "[default_add__LOGGER: "
            default_add__helper = "added a message to the stack]"
            default_add__special = " ["+io_bucket.member_bucket[0]+\
                ": write] ["+time_code+"]"
            print(default_add__LOGGER+default_add__helper+\
                ALERT_LOGGING_INFO(variable=default_add__LOGGER+\
                    default_add__helper+default_add__special)+"\n")
    file_core_es.close()

def server_add(wipe=1):
    """
    Take your local core.es file and append it to your CONSTRUCTED_core.es
    master catch-all file.
    """
    def wipe_local():
        """
        Establish the default 'wipe_local' routine in the current scope
        """
        # Write to - will overwrite the core.es file
        with open(DIRDATA+COREES, 'wt') as file_core_es:
            file_core_es.write(CORE_FILE_TEXT+'\n')
            # LOGGER
            server_add__wipe_local__LOGGER =\
            "[server_add__wipe_local__LOGGER: "
            server_add__wipe_local__helper =\
            "added COREES to CONSTRUCTEDCORE: "\
            "Wipe No]"
            print(server_add__wipe_local__LOGGER+\
                server_add__wipe_local__helper+\
                ALERT_LOGGING_WARNING(variable=\
                    server_add__wipe_local__LOGGER+\
                    server_add__wipe_local__helper)+"\n")
        file_core_es.close()

    def do():
        """
        'do' routine - a method to submit and reseed 'COREES' on behalf of setting
        up 'CONSTRUCTEDCORE' with seed-able values and either wiped after of kept.

        """
        with open(DIRDATA+CONSTRUCTEDCOREES, 'a') as serv:
            with open(DIRDATA+COREES, 'r') as file_core_es:
                # Go to Line 1, ignoring the heading
                for line in file_core_es:
                    if line.startswith("#"):
                        pass
                    else:
                        serv.write(line)
                        # LOGGER
                        server_add__do__LOGGER =\
                        "[server_add__do__LOGGER: "
                        server_add__do__helper =\
                        "added COREES to CONSTRUCTEDCORE: "\
                        "Wipe Yes]"
                        print(server_add__do__LOGGER+\
                            server_add__do__helper+\
                            ALERT_LOGGING_WARNING(variable=\
                                server_add__do__LOGGER+\
                                server_add__do__helper)+"\n")
                file_core_es.close()
        serv.close()

    if wipe == 0:
        do()
        print("core.es entries added to the CONSTRUCTED_CORE.es")
    elif wipe == 1:
        do()
        wipe_local()
        print("core.es entries added to the CONSTRUCTED_core.es, 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 add():
    """
    Default 'add' method to add one figment instance to 'COREES'

    """
    default_add()

def add_to_server():
    """
    Default 'add to server' method to add the 'COREES' information
    to global server.

    """
    server_add()



Return HOME