# -*- coding: utf-8 -*-
"""
COPYRIGHT (C) 2020-2022 NEW ENTITY OPERATIONS INC. ALL RIGHTS RESERVED
INSTANCE: origin
MODIFIED: 2022/01/12
OVERVIEW:
core_creator allows you to create a .entity/.ds relationship in text-mode.
This includes system routines for modules running within C.ORE.
These modules must adhere to the that rely on add/edit/delete/inspect
methodology offered in temple
"""
__version__ = "0.0.6"
__author__ = "Ryan McKenna"
__copyright__ = "Copyright (C) 2020-2022 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__ = "Prototype"
## MODE-> facilities
from MODE.facilities import (Path, PATH_INSTANCE, rmtree)
## MODE-> creator
from MODE.debug_creator import DEBUG_CREATOR
## Imports: Custom
from core_middlelayer import (
ENTITYSLUG,
DATASHEETFOLDER, EXTDS, EXTENTITY, LINEBLANK,
DATASHEETNAME, DATASHEETKEY,
ENTITYTITLE, ENTITYINDEX, ENTITYIDENTIFIER,
PTYPE, VIRTUALPACKAGEID,
DATASCRIPTMODULE, INCLUDEDMODULE,
chosen_entity_path,
ACCESSPATH, MASTERLISTPATH, MEMBERFILE, MEMBERPATH,
INSTALLED, CONTEXTENGINE, CONTROLS, VIRTUALPACKAGE,
SLUG_LL_FULL, SLUG_LL, LLES, KEY_LL_PLAIN, KEY_LLB_PLAIN,
SLUG_LLB_FULL, SLUG_LLB_COMPACT, SLUG_LLB, LLBES,
DASH_UTIL,
RING_KEY_LOCATION)
class CREATOR_ENTITY_OPTIONS:
"""
This can be used to go through an exact input format.
The Utility and robust delivery of hardened functionality behind inputs
will continue over time.
"""
global chosen_entity_path
def entity_form():
def summarize():
"""
Summarize the entity-instance information
"""
DEBUG_CREATOR.provide_entity_snapshot(
DATASCRIPT_MODULE=DATASCRIPTMODULE,
DATASHEET_KEY=DATASHEETKEY,
DATASHEET_NAME=DATASHEETNAME,
ENTITY_ID=ENTITYIDENTIFIER,
ENTITY_INDEX=ENTITYINDEX,
ENTITY_TITLE=ENTITYTITLE,
MODULE_INCLUDED=INCLUDEDMODULE,
PACKAGE_ID=VIRTUALPACKAGEID,
PACKAGE_TYPE=PTYPE)
def run_creator(INSTANCE):
"""
Build unprotected entity-instances from default data-types
"""
global datasheet_name
global datasheet_key
global title
global ptype
global package_id
global index
global identifier_type
global datascript_module
global included_module
## Define your input questions for the exact format.
datasheet_name = input(DATASHEETNAME)
datasheet_key = input(DATASHEETKEY)
title = input(ENTITYTITLE)
ptype = input(PTYPE)
package_id = input(VIRTUALPACKAGEID)
index = input(ENTITYINDEX)
identifier_type = input(ENTITYIDENTIFIER)
datascript_module = input(DATASCRIPTMODULE)
included_module = input(INCLUDEDMODULE)
global generated_template
generated_template = \
LINEBLANK+\
datasheet_name+EXTDS+\
" - KEY::: ""'"+datasheet_key+"'"+\
"\n \n# Entity Snapshot\ndatascript_id = ['"+datasheet_key+\
"']\ntitle = ['"+title+\
"']\n \n# Package Snapshot\npackage_type = ['"+ptype+\
"']\npackage_id = ['"+package_id+\
"']\n \n# Directory List-file\nDLIST = ['"+datasheet_name+\
".ds']\n \n# Index-List\nINDEX = ["+index+\
"]\n \n# Identifier Overview\nidentifier_type = [\n"+identifier_type+\
"\n]\n \n# Datascript Module Context\ndatascript_module = [\n"+\
datascript_module+\
"\n]\n \n# INCLUDE - Additional modules that were included"+\
"\ninclude_module = [\n"+included_module+"\n]\n"
## Write the .entity
## Append to - won't skip a line
with open(ENTITYSLUG+INSTANCE+datasheet_name+EXTENTITY, 'x+') as f:
f.write(str(generated_template))
f.close()
## Write the .ds
with open(ENTITYSLUG+INSTANCE+DATASHEETFOLDER+datasheet_name+\
EXTDS, 'x+') as f:
f.write(str(index))
f.close()
## Default runner
summarize()
global chosen_entity_path
## If you don't want to modify/create something,
## 0 will pass to the loops end.
ENTITY_Add = input(
"Would you like to add a New Entity? (1) for Yes - (0) for No")
if str(ENTITY_Add) == "0" or str(ENTITY_Add).lower() == "n":
pass
## If you want to create something, 1 will bring you into the creator.
elif str(ENTITY_Add) == "1" or str(ENTITY_Add).lower() == "y":
## Setup your global to export the chosen_entity_path at the end of the
## loop.
## All standard options can be configured automatically at the end of this
## block will take you to the manual setting.
## Exact adherence to the structure is required for operations until
## regex is used to clean the inputs.
## If you want to fall back to your automation routine, select 1
## Else, if you want to adhere to the format, select 0 and proceed.
auto_add = input(
"Would you like to automate this process? : "+\
"(1) for Yes - (0) for No")
if str(auto_add) == "0" or str(auto_add).lower() == "n":
MEMBERPATH = ACCESSPATH+MASTERLISTPATH
## Establish the base folders here
## ALIAS
ext_path_alias = "ALIAS/"
## INSTALLED
ext_path_context = INSTALLED+CONTEXTENGINE
ext_path_controls = INSTALLED+CONTROLS
ext_path_inquisitor = INSTALLED+"INQUISITOR/"
ext_path_system_images = INSTALLED+"SYSTEM_IMAGES/"
ext_path_virtual_package = INSTALLED+VIRTUALPACKAGE
## HUMAN
ext_path_human = "HUMAN/"
## Ask the questoin that states the creator
entity_type_selector = input(
"Would you like to generate this process for... :" \
"(a) for Alias OR " \
"{ENTITY: (b) Context - (c) Figments - (d) Human -" \
"(e) Alias}?")
## This doesn't run_program(): Default Alias adding
if entity_type_selector == 'a':
alias_type_selector = input("What are you doing?" \
" : (a) for Add MEMBER - (b) for Modify your VCN Alias List (VCN)")
## Outline relevant access lists
chosen_member_path = MEMBERPATH
member_file = MEMBERFILE
ext_path = chosen_member_path+member_file
## Start your alias creation logic for various instance types
if alias_type_selector == 'a':
ext_path = "MASKED_MASTER/"
# make sure Alias writes to the correct folder
print('Add-> Member to: '+ext_path)
## The rest of the routine logic goes here to write the member in,
## but will require you to enter admin password on your machine to make
## the file writeable, which requires it to be unmuted.
elif alias_type_selector == 'b':
ext_path = "VCN_DIRECTORY/"
print('Modify-> VCN Alias: '+ext_path)
## The rest of the modify logic loop would go here. Which follows a
## similar pattern
## from above.
else:
print('Please, only (a), or (b)')
elif entity_type_selector == 'b':
alias_type_selector = input("What type of entity are you creating?" \
" : (a) Context Engine - (b) Controller - (c) Virtual Package")
chosen_entity_selector = 'INSTALLED/'
if alias_type_selector == 'a':
ext_path = 'CONTEXT_ENGINE'
print('Creating a Context Engine at path: '+ext_path_context)
run_creator(INSTANCE=ext_path_context)
elif alias_type_selector == 'b':
ext_path = 'CONTROLS/'
print('Creating Controls at path: '+ext_path_controls)
run_creator(INSTANCE=ext_path_controls)
elif alias_type_selector == 'c':
ext_path = 'INQUISITOR/'
print('Creating INQUISITOR additions at path: '+ext_path_inquisitor)
run_creator(INSTANCE=ext_path_inquisitor)
elif alias_type_selector == 'c':
ext_path = 'SYSTEM_IMAGES/'
print('Creating a system image at path: '+ext_path_system_images)
run_creator(INSTANCE=ext_path_system_images)
elif alias_type_selector == 'e':
ext_path = 'VIRTUAL_PACKAGE/'
print('Creating a Virtual Package at path: '+ext_path_virtual_package)
run_creator(INSTANCE=ext_path_virtual_package)
else:
print('Please, only (a), (b), (c), (d), or (e)')
elif entity_type_selector == 'c':
alias_type_selector = input("What are you doing?" \
": a for Quick Format - b for Staging")
chosen_entity_path = 'FIGMENTS/'
if alias_type_selector == 'a':
ext_path = 'QUICK_FORMAT/'
print('Add a Quick format datasript sheet.')
run_creator(INSTANCE=chosen_entity_path+ext_path)
elif alias_type_selector == 'b':
ext_path = 'STAGING/'
## print('Add a datascript sheet to staging.')
run_creator(INSTANCE=chosen_entity_path+ext_path)
else:
print('Please, only (a) or (b)')
elif entity_type_selector == 'd':
alias_type_selector = input("What type of Human are you adding?" \
"a for Contact - b for Ficticious - c for a Person")
chosen_entity_path = 'HUMAN/'
if alias_type_selector == 'a':
ext_path = 'CONTACT/'
print('Add contact sheet')
run_creator(INSTANCE=ext_path_human+ext_path)
elif alias_type_selector == 'b':
ext_path = 'FICTICIOUS/'
print('Add a ficticious character sheet')
run_creator(INSTANCE=ext_path_human+ext_path)
elif alias_type_selector == 'c':
ext_path = 'PERSON/'
print('Add a personal contact sheet')
run_creator(INSTANCE=ext_path_human+ext_path)
else:
print('Please, only (a), (b), or (c)')
## This doesn't run_program()
## Special Alias types
elif entity_type_selector == 'e':
alias_type_selector = input("Are you creating an aliased file type?" \
"(a) Masked (b) VCN_KEY")
chosen_entity_path = 'ALIAS/'
if alias_type_selector == 'a':
ext_path = 'MASKED_MASTER/'
print("Selected Masked creation")
elif alias_type_selector == 'b':
ext_path = "VCN_DIRECTORY/"
print("Selected VCN Creation")
else:
print('Please, only (a) or (b)')
## fallback block
## Automation Block: Blank for the time being
elif str(auto_add) == "1" or str(auto_add).lower() == "y":
pass
else:
## If you put in anything else you'll fall into the else block and
## restart
print("Please, Only 1/0 and y/n")
class LockerLink:
"""
Offer a LockerLink generic creator factory
"""
def create_LockerLink(a, b, c, d, e, f, g, h, i, j, k):
no_spaces_a = a.replace(" ", "-")
no_caps_a = no_spaces_a.lower()
no_spaces_a = no_caps_a.replace("'", "")
no_quotes_a = no_spaces_a.replace("\"", "")
try:
Path(PATH_INSTANCE+SLUG_LL_FULL+no_quotes_a).mkdir(exist_ok=False,
parents=True)
with open(PATH_INSTANCE+SLUG_LL_FULL+no_quotes_a+DASH_UTIL+\
LLES, 'w') as LL_s:
LL_s.write('TITLE: '+a+'\n'+\
'LL1: '+b+'\n'+\
'LL2: '+c+'\n'+\
'LL3: '+d+'\n'+\
'LL4: '+e+'\n'+\
'LL5: '+f+'\n'+\
'LL6: '+g+'\n'+\
'LL7: '+h+'\n'+\
'LL8: '+i+'\n'+\
'LL9: '+j+'\n'+\
'LL10: '+k+'\n'+\
'features: https-only'+'\n'+\
'DIRECTORY: '+'LL'+no_quotes_a)
LL_s.close()
except:
print("Directory Exists")
def edit_LockerLink(a, b, c, d, e, f, g, h, i, j, k, SLUG_current_LockerLink):
no_spaces_a = a.replace(" ", "-")
no_caps_a = no_spaces_a.lower()
no_spaces_a = no_caps_a.replace("'", "")
no_quotes_a = no_spaces_a.replace("\"", "")
try:
Path(SLUG_LL_FULL+no_quotes_a).mkdir(exist_ok=False, parents=True)
with open(
PATH_INSTANCE+SLUG_LL_FULL+no_quotes_a+DASH_UTIL+LLES, 'w') as LL_s:
LL_s.write('TITLE: '+a+'\n'+\
'LL1: '+b+'\n'+\
'LL2: '+c+'\n'+\
'LL3: '+d+'\n'+\
'LL4: '+e+'\n'+\
'LL5: '+f+'\n'+\
'LL6: '+g+'\n'+\
'LL7: '+h+'\n'+\
'LL8: '+i+'\n'+\
'LL9: '+j+'\n'+\
'LL10: '+k+'\n'+\
'features: https-only'+'\n'+\
'DIRECTORY: '+'LL'+no_quotes_a)
rmtree(PATH_INSTANCE+SLUG_LLB_COMPACT+SLUG_current_LockerLink)
LL_s.close()
except:
print("Directory Exists")
class LockerLink_BrowseMeh:
"""
Offer a LockerLink - Browsemeh specific creator factory
"""
def create_LockerLink_BrowseMeh(NEW_LLB_TITLE, SLUG_LLB_BrowseMeh):
no_spaces_title = NEW_LLB_TITLE.replace(" ", "-")
no_caps_title = no_spaces_title.lower()
no_quote_strings_title = no_caps_title.replace("'", "")
no_quotes_title = no_quote_strings_title.replace("\"", "")
try:
Path(PATH_INSTANCE+SLUG_LLB_FULL+no_quotes_title).mkdir(exist_ok=False,
parents=True)
with open(PATH_INSTANCE+SLUG_LLB_FULL+\
no_quotes_title+DASH_UTIL+LLBES, 'w') as LLB_s:
LLB_s.write('TITLE: '+NEW_LLB_TITLE+'\n'+\
'features: local-only'+'\n'+\
'DIRECTORY: '+'LLB'+no_quotes_title+'\n'+\
'QUALITY: none'+'\n'+\
'TOKEN_ID: 0'+'\n'+\
'CATEGORY_SET_RANK: (0,0)'+'\n'+\
'CATEGORY_SET_CHARACTER: (0,0)'+'\n'+\
SLUG_LLB_BrowseMeh+'\n')
LLB_s.close()
except:
print("Directory Exists")
return("Directory Exists")
def LLB_destroy(DESTROY_THIS_LLB):
try:
rmtree(SLUG_LLB_COMPACT+DESTROY_THIS_LLB)
print("LLB DESTROY: "+DESTROY_THIS_LLB)
except:
print("Nothing was found...")
return("Nothing was found...")
def LLB_treeswap(DESTROY_THIS_LLB_TREE, NEW_LLB_TITLE, SLUG_LLB_BrowseMeh):
SWAP_ME = DESTROY_THIS_LLB_TREE
try:
rmtree(SLUG_LLB_COMPACT+DESTROY_THIS_LLB_TREE)
print(KEY_LLB_PLAIN+" SWAP STARTED: "+DESTROY_THIS_LLB_TREE)
try:
Path(SLUG_LLB_COMPACT+SWAP_ME).mkdir(exist_ok=False, parents=True)
with open(PATH_INSTANCE+SLUG_LLB_COMPACT+SWAP_ME+DASH_UTIL+\
LLBES, 'w') as LLB_s:
LLB_s.write('TITLE: '+NEW_LLB_TITLE+'\n'+\
'features: local-only'+'\n'+\
'DIRECTORY: '+'LLB'+no_quotes_title+'\n'+\
'QUALITY: none'+'\n'+\
'TOKEN_ID: 0'+'\n'+\
'CATEGORY_SET_RANK: (0,0)'+'\n'+\
'CATEGORY_SET_CHARACTER: (0,0)'+'\n'+\
SLUG_LLB_BrowseMeh+'\n')
LLB_s.close()
except:
print("LLB_treeswap: State Error")
except:
print("Nothing was found to SWAP/overwrite...")
return("Nothing was found to SWAP/overwrite...")