# -*- coding: utf-8 -*-
"""
COPYRIGHT (C) 2020-2023 NEW ENTITY OPERATIONS INC. ALL RIGHTS RESERVED
INSTANCE: core_modify
MODIFIED: 2023/05/31
OVERVIEW:
core_modify allows you to perform basic read/write operations in the program.
The default silo is for "PHASE_SERVER.es" -> "PHASE_CORE.es"
"""
__version__ = "0.0.5"
__author__ = "Ryan McKenna"
__copyright__ = "Copyright (C) 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 (oFo, terms_modify)
## Imports: Custom
from core_middlelayer import (DIRDATA, PATH_INSTANCE, PHASE_CORE,
PHASE_SERVER)
class Scope:
"""
Modify an entry 'Scope' based off of various defined routines
There are two types of values:
1. global
2. temporary
'global' interacts with the 'core.es'
'PHASE_CORE.es' is the compiled combination of all aggregated data-silos.
'temporary' represents all in transit (non-perma/stored) data chunks
'temporary' phases interact with the 'PHASE_CORE.es' facility through writing
at the line entry only, while in other instances, PHASE_CORE.es
only is appended to.
'PHASE_SERVER.es' doesn't leave your machine by default, but you can set
temporary server instances to leave the machine by offloading them to
PHASE_CORE.es, an instance that can be kept elsewhere and then gated to
specific key-user pairs. By default, it is not distributed, but local.
If you're storing chats in PHASE_CORE.es through an offload, you need to set
your chat-instance to distributed, in which case your server is shared to peers
that will also be able to write to the PHASE_CORE.es instance.
You can also be the only peer in a distributed instance and use a network-based
PHASE_CORE.es instance
Right now, only exact full-line matching is supported, but you can extend
to various match patterns as you need them. If you're using a database,
you should tie in one of the db/* instances in here and make a generic handler
for the lookup and match according to convention.
The feature is meant to be built upon by the operator
"""
# Two part replacement logic
def modify():
ModifyValue = input(terms_modify.QUESTION_TO_MODIFY)
ModifyValueWith = input(terms_modify.QUESTION_TO_REPLACE_WITH)
## global logic
def modify_global():
"""
Modify a PHASE_CORE.es entry
"""
## Preset global instance: core
GLOBAL_file_to_modify = PATH_INSTANCE+DIRDATA+PHASE_CORE
## Open and replace logic
with open(GLOBAL_file_to_modify, oFo.read_text) as f_read:
data = f_read.read()
data = data.replace(ModifyValue, ModifyValueWith)
with open(GLOBAL_file_to_modify, oFo.write_text) as f_write:
f_write.write(data)
f_write.close()
f_read.close()
## temporary logic
def modify_temporary():
"""
Modify a PHASE_SERVER.es entry
"""
## Preset temporary instance: server
TEMPORARY_file_to_modify = PATH_INSTANCE+DIRDATA+PHASE_SERVER
## Open and replace logic
with open(LOCAL_file_to_modify, oFo.read_text) as f_read:
data = f_read.read()
data = data.replace(ModifyValue, ModifyValueWith)
with open(LOCAL_file_to_modify, oFo.write_text) as f_write:
f_write.write(data)
f_write.close()
f_read.close()
## Runners
modify_global()
modify_temporary()