more fixes for phase 3

This commit is contained in:
Jay Lee
2026-07-04 05:57:12 -04:00
parent a5e22c1aea
commit a3f9cdc303
5 changed files with 10 additions and 151 deletions

View File

@@ -67,13 +67,6 @@ _DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds
def _getEnt():
return sys.modules['gam'].Ent
def _getInd():
return sys.modules['gam'].Ind
def handleServerError(e): def handleServerError(e):
errMsg = str(e) errMsg = str(e)
if 'setting tls' not in errMsg: if 'setting tls' not in errMsg:
@@ -164,7 +157,6 @@ def transportCreateRequest(httpObj=None):
return transportAgentRequest(httpObj) return transportAgentRequest(httpObj)
def doGAMCheckForUpdates(forceCheck): def doGAMCheckForUpdates(forceCheck):
Ind = _getInd()
def _gamLatestVersionNotAvailable(): def _gamLatestVersionNotAvailable():
if forceCheck: if forceCheck:
systemErrorExit(NETWORK_ERROR_RC, Msg.GAM_LATEST_VERSION_NOT_AVAILABLE) systemErrorExit(NETWORK_ERROR_RC, Msg.GAM_LATEST_VERSION_NOT_AVAILABLE)
@@ -273,7 +265,6 @@ class signjwtSignJwt(google.auth.crypt.Signer):
def handleOAuthTokenError(e, softErrors, displayError=False, i=0, count=0): def handleOAuthTokenError(e, softErrors, displayError=False, i=0, count=0):
from util.access import APIAccessDeniedExit, ClientAPIAccessDeniedExit, SvcAcctAPIAccessDeniedExit from util.access import APIAccessDeniedExit, ClientAPIAccessDeniedExit, SvcAcctAPIAccessDeniedExit
Ent = _getEnt()
errMsg = str(e).replace('.', '') errMsg = str(e).replace('.', '')
if ((errMsg in API.OAUTH2_TOKEN_ERRORS) or if ((errMsg in API.OAUTH2_TOKEN_ERRORS) or
errMsg.startswith('Invalid response') or errMsg.startswith('Invalid response') or
@@ -923,7 +914,6 @@ def callGDataPages(service, function,
softErrors=False, throwErrors=None, retryErrors=None, softErrors=False, throwErrors=None, retryErrors=None,
uri=None, uri=None,
**kwargs): **kwargs):
Ent = _getEnt()
if throwErrors is None: if throwErrors is None:
throwErrors = [] throwErrors = []
if retryErrors is None: if retryErrors is None:
@@ -1227,7 +1217,6 @@ def callGAPI(service, function,
systemErrorExit(GOOGLE_API_ERROR_RC, str(e)) systemErrorExit(GOOGLE_API_ERROR_RC, str(e))
def _showGAPIpagesResult(results, pageItems, totalItems, pageMessage, messageAttribute, entityType): def _showGAPIpagesResult(results, pageItems, totalItems, pageMessage, messageAttribute, entityType):
Ent = _getEnt()
showMessage = pageMessage.replace(TOTAL_ITEMS_MARKER, str(totalItems)) showMessage = pageMessage.replace(TOTAL_ITEMS_MARKER, str(totalItems))
if pageItems: if pageItems:
if messageAttribute: if messageAttribute:
@@ -1302,7 +1291,6 @@ def callGAPIpages(service, function, items,
throwReasons=None, retryReasons=None, throwReasons=None, retryReasons=None,
pageArgsInBody=False, pageArgsInBody=False,
**kwargs): **kwargs):
Ent = _getEnt()
if throwReasons is None: if throwReasons is None:
throwReasons = [] throwReasons = []
if retryReasons is None: if retryReasons is None:
@@ -1335,7 +1323,6 @@ def yieldGAPIpages(service, function, items,
throwReasons=None, retryReasons=None, throwReasons=None, retryReasons=None,
pageArgsInBody=False, pageArgsInBody=False,
**kwargs): **kwargs):
Ent = _getEnt()
if throwReasons is None: if throwReasons is None:
throwReasons = [] throwReasons = []
if retryReasons is None: if retryReasons is None:

View File

@@ -102,10 +102,6 @@ from util.errors import (
from util.fileio import readFile from util.fileio import readFile
from gam.var import Cmd, Ent from gam.var import Cmd, Ent
# Lazy accessor for Ent (runtime instance)
def _getEnt():
return sys.modules['gam'].Ent
# Lazy accessor for main module # Lazy accessor for main module
# --- Constants duplicated from __init__.py --- # --- Constants duplicated from __init__.py ---

View File

@@ -13,6 +13,7 @@ from gamlib import glmsgs as Msg
from gam.var import Act, Ent, Ind from gam.var import Act, Ent, Ind
from util.args import escapeCRsNLs
from util.output import ( from util.output import (
currentCountNL, currentCountNL,
formatKeyValueList, formatKeyValueList,
@@ -35,40 +36,26 @@ LAST_ITEM_MARKER = '%%last_item%%'
TOTAL_ITEMS_MARKER = '%%total_items%%' TOTAL_ITEMS_MARKER = '%%total_items%%'
def _getEnt():
"""Get the Ent instance from the main module (lazy accessor)."""
return sys.modules['gam'].Ent
def _getEscapeCRsNLs():
"""Get the escapeCRsNLs function from the main module (lazy accessor)."""
return sys.modules['gam'].escapeCRsNLs
# --- Warnings --- # --- Warnings ---
def badRequestWarning(entityType, itemType, itemValue): def badRequestWarning(entityType, itemType, itemValue):
Ent = _getEnt()
printWarningMessage(BAD_REQUEST_RC, printWarningMessage(BAD_REQUEST_RC,
f'{Msg.GOT} 0 {Ent.Plural(entityType)}: {Msg.INVALID} {Ent.Singular(itemType)} - {itemValue}') f'{Msg.GOT} 0 {Ent.Plural(entityType)}: {Msg.INVALID} {Ent.Singular(itemType)} - {itemValue}')
def emptyQuery(query, entityType): def emptyQuery(query, entityType):
Ent = _getEnt()
return f'{Ent.Singular(Ent.QUERY)} ({query}) {Msg.NO_ENTITIES_FOUND.format(Ent.Plural(entityType))}' return f'{Ent.Singular(Ent.QUERY)} ({query}) {Msg.NO_ENTITIES_FOUND.format(Ent.Plural(entityType))}'
def invalidQuery(query): def invalidQuery(query):
Ent = _getEnt()
return f'{Ent.Singular(Ent.QUERY)} ({query}) {Msg.INVALID}' return f'{Ent.Singular(Ent.QUERY)} ({query}) {Msg.INVALID}'
def invalidMember(query): def invalidMember(query):
Ent = _getEnt()
if query: if query:
badRequestWarning(Ent.GROUP, Ent.QUERY, invalidQuery(query)) badRequestWarning(Ent.GROUP, Ent.QUERY, invalidQuery(query))
return True return True
return False return False
def invalidUserSchema(schema): def invalidUserSchema(schema):
Ent = _getEnt()
if isinstance(schema, list): if isinstance(schema, list):
return f'{Ent.Singular(Ent.USER_SCHEMA)} ({",".join(schema)}) {Msg.INVALID}' return f'{Ent.Singular(Ent.USER_SCHEMA)} ({",".join(schema)}) {Msg.INVALID}'
return f'{Ent.Singular(Ent.USER_SCHEMA)} {schema}) {Msg.INVALID}' return f'{Ent.Singular(Ent.USER_SCHEMA)} {schema}) {Msg.INVALID}'
@@ -77,7 +64,6 @@ def invalidUserSchema(schema):
# --- Service Not Enabled Warnings --- # --- Service Not Enabled Warnings ---
def userServiceNotEnabledWarning(entityName, service, i=0, count=0): def userServiceNotEnabledWarning(entityName, service, i=0, count=0):
Ent = _getEnt()
setSysExitRC(SERVICE_NOT_APPLICABLE_RC) setSysExitRC(SERVICE_NOT_APPLICABLE_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[Ent.Singular(Ent.USER), entityName, Msg.SERVICE_NOT_ENABLED.format(service)], [Ent.Singular(Ent.USER), entityName, Msg.SERVICE_NOT_ENABLED.format(service)],
@@ -104,7 +90,7 @@ def userDriveServiceNotEnabledWarning(user, errMessage, i=0, count=0):
if errMessage.find('Drive apps') >= 0 or errMessage.find('Active session is invalid') >= 0: if errMessage.find('Drive apps') >= 0 or errMessage.find('Active session is invalid') >= 0:
userServiceNotEnabledWarning(user, 'Drive', i, count) userServiceNotEnabledWarning(user, 'Drive', i, count)
else: else:
entityActionNotPerformedWarning([_getEnt().USER, user], errMessage, i, count) entityActionNotPerformedWarning([Ent.USER, user], errMessage, i, count)
def userKeepServiceNotEnabledWarning(entityName, i=0, count=0): def userKeepServiceNotEnabledWarning(entityName, i=0, count=0):
userServiceNotEnabledWarning(entityName, 'Keep', i, count) userServiceNotEnabledWarning(entityName, 'Keep', i, count)
@@ -128,70 +114,60 @@ def userYouTubeServiceNotEnabledWarning(entityName, i=0, count=0):
# --- Entity Warning Functions --- # --- Entity Warning Functions ---
def entityServiceNotApplicableWarning(entityType, entityName, i=0, count=0): def entityServiceNotApplicableWarning(entityType, entityName, i=0, count=0):
Ent = _getEnt()
setSysExitRC(SERVICE_NOT_APPLICABLE_RC) setSysExitRC(SERVICE_NOT_APPLICABLE_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[Ent.Singular(entityType), entityName, Msg.SERVICE_NOT_APPLICABLE], [Ent.Singular(entityType), entityName, Msg.SERVICE_NOT_APPLICABLE],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityDoesNotExistWarning(entityType, entityName, i=0, count=0): def entityDoesNotExistWarning(entityType, entityName, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ENTITY_DOES_NOT_EXIST_RC) setSysExitRC(ENTITY_DOES_NOT_EXIST_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[Ent.Singular(entityType), entityName, Msg.DOES_NOT_EXIST], [Ent.Singular(entityType), entityName, Msg.DOES_NOT_EXIST],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityListDoesNotExistWarning(entityValueList, i=0, count=0): def entityListDoesNotExistWarning(entityValueList, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ENTITY_DOES_NOT_EXIST_RC) setSysExitRC(ENTITY_DOES_NOT_EXIST_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Msg.DOES_NOT_EXIST], Ent.FormatEntityValueList(entityValueList)+[Msg.DOES_NOT_EXIST],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityDoesNotHaveItemWarning(entityValueList, i=0, count=0): def entityDoesNotHaveItemWarning(entityValueList, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ENTITY_DOES_NOT_EXIST_RC) setSysExitRC(ENTITY_DOES_NOT_EXIST_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Msg.DOES_NOT_EXIST], Ent.FormatEntityValueList(entityValueList)+[Msg.DOES_NOT_EXIST],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityDuplicateWarning(entityValueList, i=0, count=0): def entityDuplicateWarning(entityValueList, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ENTITY_DUPLICATE_RC) setSysExitRC(ENTITY_DUPLICATE_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.Failed(), Msg.DUPLICATE], Ent.FormatEntityValueList(entityValueList)+[Act.Failed(), Msg.DUPLICATE],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityActionFailedWarning(entityValueList, errMessage, i=0, count=0): def entityActionFailedWarning(entityValueList, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_FAILED_RC) setSysExitRC(ACTION_FAILED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.Failed(), errMessage], Ent.FormatEntityValueList(entityValueList)+[Act.Failed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierItemValueListActionFailedWarning(entityValueList, modifier, infoTypeValueList, errMessage, i=0, count=0): def entityModifierItemValueListActionFailedWarning(entityValueList, modifier, infoTypeValueList, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_FAILED_RC) setSysExitRC(ACTION_FAILED_RC)
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList)+[Act.Failed(), errMessage], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList)+[Act.Failed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierActionFailedWarning(entityValueList, modifier, errMessage, i=0, count=0): def entityModifierActionFailedWarning(entityValueList, modifier, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_FAILED_RC) setSysExitRC(ACTION_FAILED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', Act.Failed(), errMessage], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', Act.Failed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierNewValueActionFailedWarning(entityValueList, modifier, newValue, errMessage, i=0, count=0): def entityModifierNewValueActionFailedWarning(entityValueList, modifier, newValue, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_FAILED_RC) setSysExitRC(ACTION_FAILED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', newValue, Act.Failed(), errMessage], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', newValue, Act.Failed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityNumEntitiesActionFailedWarning(entityType, entityName, itemType, itemCount, errMessage, i=0, count=0): def entityNumEntitiesActionFailedWarning(entityType, entityName, itemType, itemCount, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_FAILED_RC) setSysExitRC(ACTION_FAILED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[Ent.Singular(entityType), entityName, [Ent.Singular(entityType), entityName,
@@ -200,33 +176,28 @@ def entityNumEntitiesActionFailedWarning(entityType, entityName, itemType, itemC
currentCountNL(i, count))) currentCountNL(i, count)))
def entityActionNotPerformedWarning(entityValueList, errMessage, i=0, count=0): def entityActionNotPerformedWarning(entityValueList, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_NOT_PERFORMED_RC) setSysExitRC(ACTION_NOT_PERFORMED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.NotPerformed(), errMessage], Ent.FormatEntityValueList(entityValueList)+[Act.NotPerformed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityItemValueListActionNotPerformedWarning(entityValueList, infoTypeValueList, errMessage, i=0, count=0): def entityItemValueListActionNotPerformedWarning(entityValueList, infoTypeValueList, errMessage, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.NotPerformed(), '']+Ent.FormatEntityValueList(infoTypeValueList)+[errMessage], Ent.FormatEntityValueList(entityValueList)+[Act.NotPerformed(), '']+Ent.FormatEntityValueList(infoTypeValueList)+[errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierItemValueListActionNotPerformedWarning(entityValueList, modifier, infoTypeValueList, errMessage, i=0, count=0): def entityModifierItemValueListActionNotPerformedWarning(entityValueList, modifier, infoTypeValueList, errMessage, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.NotPerformed()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList)+[errMessage], Ent.FormatEntityValueList(entityValueList)+[f'{Act.NotPerformed()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList)+[errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityNumEntitiesActionNotPerformedWarning(entityValueList, itemType, itemCount, errMessage, i=0, count=0): def entityNumEntitiesActionNotPerformedWarning(entityValueList, itemType, itemCount, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_NOT_PERFORMED_RC) setSysExitRC(ACTION_NOT_PERFORMED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Ent.Choose(itemType, itemCount), itemCount, Act.NotPerformed(), errMessage], Ent.FormatEntityValueList(entityValueList)+[Ent.Choose(itemType, itemCount), itemCount, Act.NotPerformed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityBadRequestWarning(entityValueList, errMessage, i=0, count=0): def entityBadRequestWarning(entityValueList, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(BAD_REQUEST_RC) setSysExitRC(BAD_REQUEST_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[ERROR, errMessage], Ent.FormatEntityValueList(entityValueList)+[ERROR, errMessage],
@@ -236,7 +207,6 @@ def entityBadRequestWarning(entityValueList, errMessage, i=0, count=0):
# --- Getting / Paging Display --- # --- Getting / Paging Display ---
def printGettingAllAccountEntities(entityType, query='', qualifier='', accountType=None): def printGettingAllAccountEntities(entityType, query='', qualifier='', accountType=None):
Ent = _getEnt()
if accountType is None: if accountType is None:
accountType = Ent.ACCOUNT accountType = Ent.ACCOUNT
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
@@ -249,12 +219,10 @@ def printGettingAllAccountEntities(entityType, query='', qualifier='', accountTy
writeStderr(f'{Msg.GETTING_ALL} {Ent.PluralGetting()}{Ent.GettingPreQualifier()}{Ent.MayTakeTime(accountType)}\n') writeStderr(f'{Msg.GETTING_ALL} {Ent.PluralGetting()}{Ent.GettingPreQualifier()}{Ent.MayTakeTime(accountType)}\n')
def printGotAccountEntities(count): def printGotAccountEntities(count):
Ent = _getEnt()
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
writeStderr(f'{Msg.GOT} {count} {Ent.ChooseGetting(count)}{Ent.GettingPostQualifier()}\n') writeStderr(f'{Msg.GOT} {count} {Ent.ChooseGetting(count)}{Ent.GettingPostQualifier()}\n')
def setGettingAllEntityItemsForWhom(entityItem, forWhom, query='', qualifier=''): def setGettingAllEntityItemsForWhom(entityItem, forWhom, query='', qualifier=''):
Ent = _getEnt()
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
if query: if query:
Ent.SetGettingQuery(entityItem, query) Ent.SetGettingQuery(entityItem, query)
@@ -265,30 +233,25 @@ def setGettingAllEntityItemsForWhom(entityItem, forWhom, query='', qualifier='')
Ent.SetGettingForWhom(forWhom) Ent.SetGettingForWhom(forWhom)
def printGettingAllEntityItemsForWhom(entityItem, forWhom, i=0, count=0, query='', qualifier='', entityType=None): def printGettingAllEntityItemsForWhom(entityItem, forWhom, i=0, count=0, query='', qualifier='', entityType=None):
Ent = _getEnt()
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
setGettingAllEntityItemsForWhom(entityItem, forWhom, query=query, qualifier=qualifier) setGettingAllEntityItemsForWhom(entityItem, forWhom, query=query, qualifier=qualifier)
writeStderr(f'{Msg.GETTING_ALL} {Ent.PluralGetting()}{Ent.GettingPreQualifier()} {Msg.FOR} {forWhom}{Ent.MayTakeTime(entityType)}{currentCountNL(i, count)}') writeStderr(f'{Msg.GETTING_ALL} {Ent.PluralGetting()}{Ent.GettingPreQualifier()} {Msg.FOR} {forWhom}{Ent.MayTakeTime(entityType)}{currentCountNL(i, count)}')
def printGotEntityItemsForWhom(count): def printGotEntityItemsForWhom(count):
Ent = _getEnt()
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
writeStderr(f'{Msg.GOT} {count} {Ent.ChooseGetting(count)}{Ent.GettingPostQualifier()} {Msg.FOR} {Ent.GettingForWhom()}\n') writeStderr(f'{Msg.GOT} {count} {Ent.ChooseGetting(count)}{Ent.GettingPostQualifier()} {Msg.FOR} {Ent.GettingForWhom()}\n')
def printGettingEntityItem(entityType, entityItem, i=0, count=0): def printGettingEntityItem(entityType, entityItem, i=0, count=0):
Ent = _getEnt()
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
writeStderr(f'{Msg.GETTING} {Ent.Singular(entityType)} {entityItem}{currentCountNL(i, count)}') writeStderr(f'{Msg.GETTING} {Ent.Singular(entityType)} {entityItem}{currentCountNL(i, count)}')
def printGettingEntityItemForWhom(entityItem, forWhom, i=0, count=0): def printGettingEntityItemForWhom(entityItem, forWhom, i=0, count=0):
Ent = _getEnt()
if GC.Values[GC.SHOW_GETTINGS]: if GC.Values[GC.SHOW_GETTINGS]:
Ent.SetGetting(entityItem) Ent.SetGetting(entityItem)
Ent.SetGettingForWhom(forWhom) Ent.SetGettingForWhom(forWhom)
writeStderr(f'{Msg.GETTING} {Ent.PluralGetting()} {Msg.FOR} {forWhom}{currentCountNL(i, count)}') writeStderr(f'{Msg.GETTING} {Ent.PluralGetting()} {Msg.FOR} {forWhom}{currentCountNL(i, count)}')
def stderrEntityMessage(entityValueList, message, i=0, count=0): def stderrEntityMessage(entityValueList, message, i=0, count=0):
Ent = _getEnt()
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[message], Ent.FormatEntityValueList(entityValueList)+[message],
currentCountNL(i, count))) currentCountNL(i, count)))
@@ -310,7 +273,6 @@ def getPageMessage(showFirstLastItems=False, showDate=None):
return pageMessage return pageMessage
def getPageMessageForWhom(forWhom=None, showFirstLastItems=False, showDate=None, clearLastGotMsgLen=True): def getPageMessageForWhom(forWhom=None, showFirstLastItems=False, showDate=None, clearLastGotMsgLen=True):
Ent = _getEnt()
if not GC.Values[GC.SHOW_GETTINGS]: if not GC.Values[GC.SHOW_GETTINGS]:
return None return None
if forWhom: if forWhom:
@@ -348,7 +310,6 @@ def printKeyValueDict(kvDict):
writeStdout(formatKeyValueList(Ind.Spaces(), [key, value], '\n')) writeStdout(formatKeyValueList(Ind.Spaces(), [key, value], '\n'))
def printKeyValueWithCRsNLs(key, value): def printKeyValueWithCRsNLs(key, value):
escapeCRsNLs = _getEscapeCRsNLs()
if value.find('\n') >= 0 or value.find('\r') >= 0: if value.find('\n') >= 0 or value.find('\r') >= 0:
if GC.Values[GC.SHOW_CONVERT_CR_NL]: if GC.Values[GC.SHOW_CONVERT_CR_NL]:
printKeyValueList([key, escapeCRsNLs(value)]) printKeyValueList([key, escapeCRsNLs(value)])
@@ -367,25 +328,21 @@ def printJSONValue(value):
writeStdout(formatKeyValueList(' ', [value], '\n')) writeStdout(formatKeyValueList(' ', [value], '\n'))
def printEntity(entityValueList, i=0, count=0): def printEntity(entityValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList), Ent.FormatEntityValueList(entityValueList),
currentCountNL(i, count))) currentCountNL(i, count)))
def printEntityMessage(entityValueList, message, i=0, count=0): def printEntityMessage(entityValueList, message, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[message], Ent.FormatEntityValueList(entityValueList)+[message],
currentCountNL(i, count))) currentCountNL(i, count)))
def printEntitiesCount(entityType, entityList): def printEntitiesCount(entityType, entityList):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
[Ent.Plural(entityType), None if entityList is None else f'({len(entityList)})'], [Ent.Plural(entityType), None if entityList is None else f'({len(entityList)})'],
'\n')) '\n'))
def printEntityKVList(entityValueList, infoKVList, i=0, count=0): def printEntityKVList(entityValueList, infoKVList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+infoKVList, Ent.FormatEntityValueList(entityValueList)+infoKVList,
currentCountNL(i, count))) currentCountNL(i, count)))
@@ -394,111 +351,93 @@ def printEntityKVList(entityValueList, infoKVList, i=0, count=0):
# --- performAction / entityPerformAction --- # --- performAction / entityPerformAction ---
def performAction(entityType, entityValue, i=0, count=0): def performAction(entityType, entityValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
[f'{Act.ToPerform()} {Ent.Singular(entityType)} {entityValue}'], [f'{Act.ToPerform()} {Ent.Singular(entityType)} {entityValue}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def performActionNumItems(itemCount, itemType, i=0, count=0): def performActionNumItems(itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
[f'{Act.ToPerform()} {itemCount} {Ent.Choose(itemType, itemCount)}'], [f'{Act.ToPerform()} {itemCount} {Ent.Choose(itemType, itemCount)}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def performActionModifierNumItems(modifier, itemCount, itemType, i=0, count=0): def performActionModifierNumItems(modifier, itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
[f'{Act.ToPerform()} {modifier} {itemCount} {Ent.Choose(itemType, itemCount)}'], [f'{Act.ToPerform()} {modifier} {itemCount} {Ent.Choose(itemType, itemCount)}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def actionPerformedNumItems(itemCount, itemType, i=0, count=0): def actionPerformedNumItems(itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[f'{itemCount} {Ent.Choose(itemType, itemCount)} {Act.Performed()} '], [f'{itemCount} {Ent.Choose(itemType, itemCount)} {Act.Performed()} '],
currentCountNL(i, count))) currentCountNL(i, count)))
def actionFailedNumItems(itemCount, itemType, errMessage, i=0, count=0): def actionFailedNumItems(itemCount, itemType, errMessage, i=0, count=0):
Ent = _getEnt()
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[f'{itemCount} {Ent.Choose(itemType, itemCount)} {Act.Failed()}: {errMessage} '], [f'{itemCount} {Ent.Choose(itemType, itemCount)} {Act.Failed()}: {errMessage} '],
currentCountNL(i, count))) currentCountNL(i, count)))
def actionNotPerformedNumItemsWarning(itemCount, itemType, errMessage, i=0, count=0): def actionNotPerformedNumItemsWarning(itemCount, itemType, errMessage, i=0, count=0):
Ent = _getEnt()
setSysExitRC(ACTION_NOT_PERFORMED_RC) setSysExitRC(ACTION_NOT_PERFORMED_RC)
writeStderr(formatKeyValueList(Ind.Spaces(), writeStderr(formatKeyValueList(Ind.Spaces(),
[Ent.Choose(itemType, itemCount), itemCount, Act.NotPerformed(), errMessage], [Ent.Choose(itemType, itemCount), itemCount, Act.NotPerformed(), errMessage],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformAction(entityValueList, i=0, count=0): def entityPerformAction(entityValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()}'], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionNumItems(entityValueList, itemCount, itemType, i=0, count=0): def entityPerformActionNumItems(entityValueList, itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {itemCount} {Ent.Choose(itemType, itemCount)}'], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {itemCount} {Ent.Choose(itemType, itemCount)}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionModifierNumItems(entityValueList, modifier, itemCount, itemType, i=0, count=0): def entityPerformActionModifierNumItems(entityValueList, modifier, itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier} {itemCount} {Ent.Choose(itemType, itemCount)}'], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier} {itemCount} {Ent.Choose(itemType, itemCount)}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionNumItemsModifier(entityValueList, itemCount, itemType, modifier, i=0, count=0): def entityPerformActionNumItemsModifier(entityValueList, itemCount, itemType, modifier, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {itemCount} {Ent.Choose(itemType, itemCount)} {modifier}'], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {itemCount} {Ent.Choose(itemType, itemCount)} {modifier}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionSubItemModifierNumItems(entityValueList, subitemType, modifier, itemCount, itemType, i=0, count=0): def entityPerformActionSubItemModifierNumItems(entityValueList, subitemType, modifier, itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {Ent.Plural(subitemType)} {modifier} {itemCount} {Ent.Choose(itemType, itemCount)}'], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {Ent.Plural(subitemType)} {modifier} {itemCount} {Ent.Choose(itemType, itemCount)}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionSubItemModifierNumItemsModifierNewValue(entityValueList, subitemType, modifier1, itemCount, itemType, modifier2, newValue, i=0, count=0): def entityPerformActionSubItemModifierNumItemsModifierNewValue(entityValueList, subitemType, modifier1, itemCount, itemType, modifier2, newValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+ Ent.FormatEntityValueList(entityValueList)+
[f'{Act.ToPerform()} {Ent.Plural(subitemType)} {modifier1} {itemCount} {Ent.Choose(itemType, itemCount)} {modifier2}', newValue], [f'{Act.ToPerform()} {Ent.Plural(subitemType)} {modifier1} {itemCount} {Ent.Choose(itemType, itemCount)} {modifier2}', newValue],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionModifierNumItemsModifier(entityValueList, modifier1, itemCount, itemType, modifier2, i=0, count=0): def entityPerformActionModifierNumItemsModifier(entityValueList, modifier1, itemCount, itemType, modifier2, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier1} {itemCount} {Ent.Choose(itemType, itemCount)} {modifier2}'], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier1} {itemCount} {Ent.Choose(itemType, itemCount)} {modifier2}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionModifierItemValueList(entityValueList, modifier, infoTypeValueList, i=0, count=0): def entityPerformActionModifierItemValueList(entityValueList, modifier, infoTypeValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList), Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList),
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionModifierNewValue(entityValueList, modifier, newValue, i=0, count=0): def entityPerformActionModifierNewValue(entityValueList, modifier, newValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', newValue], Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', newValue],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionModifierNewValueItemValueList(entityValueList, modifier, newValue, infoTypeValueList, i=0, count=0): def entityPerformActionModifierNewValueItemValueList(entityValueList, modifier, newValue, infoTypeValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', newValue]+Ent.FormatEntityValueList(infoTypeValueList), Ent.FormatEntityValueList(entityValueList)+[f'{Act.ToPerform()} {modifier}', newValue]+Ent.FormatEntityValueList(infoTypeValueList),
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionItemValue(entityValueList, itemType, itemValue, i=0, count=0): def entityPerformActionItemValue(entityValueList, itemType, itemValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.ToPerform(), None, Ent.Singular(itemType), itemValue], Ent.FormatEntityValueList(entityValueList)+[Act.ToPerform(), None, Ent.Singular(itemType), itemValue],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityPerformActionInfo(entityValueList, infoValue, i=0, count=0): def entityPerformActionInfo(entityValueList, infoValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.ToPerform(), infoValue], Ent.FormatEntityValueList(entityValueList)+[Act.ToPerform(), infoValue],
currentCountNL(i, count))) currentCountNL(i, count)))
@@ -507,13 +446,11 @@ def entityPerformActionInfo(entityValueList, infoValue, i=0, count=0):
# --- entityActionPerformed / entityModifier --- # --- entityActionPerformed / entityModifier ---
def entityActionPerformed(entityValueList, i=0, count=0): def entityActionPerformed(entityValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.Performed()], Ent.FormatEntityValueList(entityValueList)+[Act.Performed()],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityActionPerformedMessage(entityValueList, message, i=0, count=0): def entityActionPerformedMessage(entityValueList, message, i=0, count=0):
Ent = _getEnt()
if message: if message:
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.Performed(), message], Ent.FormatEntityValueList(entityValueList)+[Act.Performed(), message],
@@ -524,37 +461,31 @@ def entityActionPerformedMessage(entityValueList, message, i=0, count=0):
currentCountNL(i, count))) currentCountNL(i, count)))
def entityNumItemsActionPerformed(entityValueList, itemCount, itemType, i=0, count=0): def entityNumItemsActionPerformed(entityValueList, itemCount, itemType, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{itemCount} {Ent.Choose(itemType, itemCount)} {Act.Performed()}'], Ent.FormatEntityValueList(entityValueList)+[f'{itemCount} {Ent.Choose(itemType, itemCount)} {Act.Performed()}'],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierActionPerformed(entityValueList, modifier, i=0, count=0): def entityModifierActionPerformed(entityValueList, modifier, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', None], Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', None],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierItemValueListActionPerformed(entityValueList, modifier, infoTypeValueList, i=0, count=0): def entityModifierItemValueListActionPerformed(entityValueList, modifier, infoTypeValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList), Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', None]+Ent.FormatEntityValueList(infoTypeValueList),
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierNewValueActionPerformed(entityValueList, modifier, newValue, i=0, count=0): def entityModifierNewValueActionPerformed(entityValueList, modifier, newValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', newValue], Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', newValue],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierNewValueItemValueListActionPerformed(entityValueList, modifier, newValue, infoTypeValueList, i=0, count=0): def entityModifierNewValueItemValueListActionPerformed(entityValueList, modifier, newValue, infoTypeValueList, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', newValue]+Ent.FormatEntityValueList(infoTypeValueList), Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', newValue]+Ent.FormatEntityValueList(infoTypeValueList),
currentCountNL(i, count))) currentCountNL(i, count)))
def entityModifierNewValueKeyValueActionPerformed(entityValueList, modifier, newValue, infoKey, infoValue, i=0, count=0): def entityModifierNewValueKeyValueActionPerformed(entityValueList, modifier, newValue, infoKey, infoValue, i=0, count=0):
Ent = _getEnt()
writeStdout(formatKeyValueList(Ind.Spaces(), writeStdout(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', newValue, infoKey, infoValue], Ent.FormatEntityValueList(entityValueList)+[f'{Act.Performed()} {modifier}', newValue, infoKey, infoValue],
currentCountNL(i, count))) currentCountNL(i, count)))

View File

@@ -9,6 +9,12 @@ from gamlib import glmsgs as Msg
from gam.var import Act, Cmd, Ent, Ind from gam.var import Act, Cmd, Ent, Ind
from gam.constants import (
ACTION_FAILED_RC, CLIENT_SECRETS_JSON_REQUIRED_RC,
ENTITY_DOES_NOT_EXIST_RC, ENTITY_IS_NOT_UNIQUE_RC,
INVALID_JSON_RC, OAUTH2_TXT_REQUIRED_RC,
OAUTH2SERVICE_JSON_REQUIRED_RC, USAGE_ERROR_RC,
)
from util.output import ( from util.output import (
currentCountNL, currentCountNL,
formatKeyValueList, formatKeyValueList,
@@ -18,87 +24,40 @@ from util.output import (
writeStderr, writeStderr,
) )
# Lazy accessor for Ent (runtime instance)
def _getEnt():
return sys.modules['gam'].Ent
# Constants imported from __init__.py at module level via lazy accessor
def _getConst(name):
return getattr(sys.modules['gam'], name)
# --- Return code constants (imported lazily) ---
ACTION_FAILED_RC = None
CLIENT_SECRETS_JSON_REQUIRED_RC = None
ENTITY_DOES_NOT_EXIST_RC = None
ENTITY_IS_NOT_UNIQUE_RC = None
INVALID_JSON_RC = None
OAUTH2_TXT_REQUIRED_RC = None
OAUTH2SERVICE_JSON_REQUIRED_RC = None
USAGE_ERROR_RC = None
def _ensureConstants():
global ACTION_FAILED_RC, CLIENT_SECRETS_JSON_REQUIRED_RC, ENTITY_DOES_NOT_EXIST_RC
global ENTITY_IS_NOT_UNIQUE_RC, INVALID_JSON_RC, OAUTH2_TXT_REQUIRED_RC
global OAUTH2SERVICE_JSON_REQUIRED_RC, USAGE_ERROR_RC
if ACTION_FAILED_RC is None:
m = sys.modules['gam']
ACTION_FAILED_RC = m.ACTION_FAILED_RC
CLIENT_SECRETS_JSON_REQUIRED_RC = m.CLIENT_SECRETS_JSON_REQUIRED_RC
ENTITY_DOES_NOT_EXIST_RC = m.ENTITY_DOES_NOT_EXIST_RC
ENTITY_IS_NOT_UNIQUE_RC = m.ENTITY_IS_NOT_UNIQUE_RC
INVALID_JSON_RC = m.INVALID_JSON_RC
OAUTH2_TXT_REQUIRED_RC = m.OAUTH2_TXT_REQUIRED_RC
OAUTH2SERVICE_JSON_REQUIRED_RC = m.OAUTH2SERVICE_JSON_REQUIRED_RC
USAGE_ERROR_RC = m.USAGE_ERROR_RC
# --- Credential file errors --- # --- Credential file errors ---
def invalidClientSecretsJsonExit(errMsg): def invalidClientSecretsJsonExit(errMsg):
_ensureConstants()
Ent = _getEnt()
stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.CLIENT_SECRETS_JSON_FILE), GC.Values[GC.CLIENT_SECRETS_JSON], errMsg)) stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.CLIENT_SECRETS_JSON_FILE), GC.Values[GC.CLIENT_SECRETS_JSON], errMsg))
writeStderr(Msg.INSTRUCTIONS_CLIENT_SECRETS_JSON) writeStderr(Msg.INSTRUCTIONS_CLIENT_SECRETS_JSON)
systemErrorExit(CLIENT_SECRETS_JSON_REQUIRED_RC, None) systemErrorExit(CLIENT_SECRETS_JSON_REQUIRED_RC, None)
def invalidOauth2serviceJsonExit(errMsg): def invalidOauth2serviceJsonExit(errMsg):
_ensureConstants()
Ent = _getEnt()
stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.OAUTH2SERVICE_JSON_FILE), GC.Values[GC.OAUTH2SERVICE_JSON], errMsg)) stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.OAUTH2SERVICE_JSON_FILE), GC.Values[GC.OAUTH2SERVICE_JSON], errMsg))
writeStderr(Msg.INSTRUCTIONS_OAUTH2SERVICE_JSON) writeStderr(Msg.INSTRUCTIONS_OAUTH2SERVICE_JSON)
systemErrorExit(OAUTH2SERVICE_JSON_REQUIRED_RC, None) systemErrorExit(OAUTH2SERVICE_JSON_REQUIRED_RC, None)
def invalidOauth2TxtExit(errMsg): def invalidOauth2TxtExit(errMsg):
_ensureConstants()
Ent = _getEnt()
stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.OAUTH2_TXT_FILE), GC.Values[GC.OAUTH2_TXT], errMsg)) stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.OAUTH2_TXT_FILE), GC.Values[GC.OAUTH2_TXT], errMsg))
writeStderr(Msg.EXECUTE_GAM_OAUTH_CREATE) writeStderr(Msg.EXECUTE_GAM_OAUTH_CREATE)
systemErrorExit(OAUTH2_TXT_REQUIRED_RC, None) systemErrorExit(OAUTH2_TXT_REQUIRED_RC, None)
def expiredRevokedOauth2TxtExit(): def expiredRevokedOauth2TxtExit():
_ensureConstants()
Ent = _getEnt()
stderrErrorMsg(Msg.IS_EXPIRED_OR_REVOKED.format(Ent.Singular(Ent.OAUTH2_TXT_FILE), GC.Values[GC.OAUTH2_TXT])) stderrErrorMsg(Msg.IS_EXPIRED_OR_REVOKED.format(Ent.Singular(Ent.OAUTH2_TXT_FILE), GC.Values[GC.OAUTH2_TXT]))
writeStderr(Msg.EXECUTE_GAM_OAUTH_CREATE) writeStderr(Msg.EXECUTE_GAM_OAUTH_CREATE)
systemErrorExit(OAUTH2_TXT_REQUIRED_RC, None) systemErrorExit(OAUTH2_TXT_REQUIRED_RC, None)
def invalidDiscoveryJsonExit(fileName, errMsg): def invalidDiscoveryJsonExit(fileName, errMsg):
_ensureConstants()
Ent = _getEnt()
stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.DISCOVERY_JSON_FILE), fileName, errMsg)) stderrErrorMsg(Msg.DOES_NOT_EXIST_OR_HAS_INVALID_FORMAT.format(Ent.Singular(Ent.DISCOVERY_JSON_FILE), fileName, errMsg))
systemErrorExit(INVALID_JSON_RC, None) systemErrorExit(INVALID_JSON_RC, None)
# --- Entity error exits --- # --- Entity error exits ---
def entityActionFailedExit(entityValueList, errMsg, i=0, count=0): def entityActionFailedExit(entityValueList, errMsg, i=0, count=0):
_ensureConstants()
Ent = _getEnt()
systemErrorExit(ACTION_FAILED_RC, formatKeyValueList(Ind.Spaces(), systemErrorExit(ACTION_FAILED_RC, formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.Failed(), errMsg], Ent.FormatEntityValueList(entityValueList)+[Act.Failed(), errMsg],
currentCountNL(i, count))) currentCountNL(i, count)))
def entityDoesNotExistExit(entityType, entityName, i=0, count=0, errMsg=None): def entityDoesNotExistExit(entityType, entityName, i=0, count=0, errMsg=None):
_ensureConstants()
Ent = _getEnt()
Cmd.Backup() Cmd.Backup()
writeStderr(Cmd.CommandLineWithBadArgumentMarked(False)) writeStderr(Cmd.CommandLineWithBadArgumentMarked(False))
systemErrorExit(ENTITY_DOES_NOT_EXIST_RC, formatKeyValueList(Ind.Spaces(), systemErrorExit(ENTITY_DOES_NOT_EXIST_RC, formatKeyValueList(Ind.Spaces(),
@@ -106,8 +65,6 @@ def entityDoesNotExistExit(entityType, entityName, i=0, count=0, errMsg=None):
currentCountNL(i, count))) currentCountNL(i, count)))
def entityDoesNotHaveItemExit(entityValueList, i=0, count=0): def entityDoesNotHaveItemExit(entityValueList, i=0, count=0):
_ensureConstants()
Ent = _getEnt()
Cmd.Backup() Cmd.Backup()
writeStderr(Cmd.CommandLineWithBadArgumentMarked(False)) writeStderr(Cmd.CommandLineWithBadArgumentMarked(False))
systemErrorExit(ENTITY_DOES_NOT_EXIST_RC, formatKeyValueList(Ind.Spaces(), systemErrorExit(ENTITY_DOES_NOT_EXIST_RC, formatKeyValueList(Ind.Spaces(),
@@ -115,8 +72,6 @@ def entityDoesNotHaveItemExit(entityValueList, i=0, count=0):
currentCountNL(i, count))) currentCountNL(i, count)))
def entityIsNotUniqueExit(entityType, entityName, valueType, valueList, i=0, count=0): def entityIsNotUniqueExit(entityType, entityName, valueType, valueList, i=0, count=0):
_ensureConstants()
Ent = _getEnt()
Cmd.Backup() Cmd.Backup()
writeStderr(Cmd.CommandLineWithBadArgumentMarked(False)) writeStderr(Cmd.CommandLineWithBadArgumentMarked(False))
systemErrorExit(ENTITY_IS_NOT_UNIQUE_RC, formatKeyValueList(Ind.Spaces(), systemErrorExit(ENTITY_IS_NOT_UNIQUE_RC, formatKeyValueList(Ind.Spaces(),
@@ -126,7 +81,6 @@ def entityIsNotUniqueExit(entityType, entityName, valueType, valueList, i=0, cou
# --- Usage/argument errors --- # --- Usage/argument errors ---
def usageErrorExit(message, extraneous=False): def usageErrorExit(message, extraneous=False):
_ensureConstants()
writeStderr(Cmd.CommandLineWithBadArgumentMarked(extraneous)) writeStderr(Cmd.CommandLineWithBadArgumentMarked(extraneous))
stderrErrorMsg(message) stderrErrorMsg(message)
FN_GAMCOMMANDS_TXT = _getConst('FN_GAMCOMMANDS_TXT') FN_GAMCOMMANDS_TXT = _getConst('FN_GAMCOMMANDS_TXT')
@@ -178,7 +132,6 @@ def deprecatedArgumentExit(argument):
usageErrorExit(f'{Cmd.ARGUMENT_ERROR_NAMES[Cmd.ARGUMENT_DEPRECATED][1]}: <{argument}>') usageErrorExit(f'{Cmd.ARGUMENT_ERROR_NAMES[Cmd.ARGUMENT_DEPRECATED][1]}: <{argument}>')
def deprecatedCommandExit(): def deprecatedCommandExit():
_ensureConstants()
systemErrorExit(USAGE_ERROR_RC, Msg.SITES_COMMAND_DEPRECATED.format(Cmd.CommandDeprecated())) systemErrorExit(USAGE_ERROR_RC, Msg.SITES_COMMAND_DEPRECATED.format(Cmd.CommandDeprecated()))
# Choices is the valid set of choices that was expected # Choices is the valid set of choices that was expected

View File

@@ -48,10 +48,6 @@ WARNING_PREFIX = WARNING + ': '
_ENT_FILE = glentity.GamEntity.FILE _ENT_FILE = glentity.GamEntity.FILE
def _getEnt():
"""Get the Ent instance from the main module (lazy accessor)."""
return sys.modules['gam'].Ent
def cleanFilename(filename): def cleanFilename(filename):
return sanitize_filename(filename, '_') return sanitize_filename(filename, '_')
@@ -82,7 +78,6 @@ def cleanFilepath(filepath):
return sanitize_filepath(filepath, platform='auto') return sanitize_filepath(filepath, platform='auto')
def fileErrorMessage(filename, e, entityType=_ENT_FILE): def fileErrorMessage(filename, e, entityType=_ENT_FILE):
Ent = _getEnt()
return f'{Ent.Singular(entityType)}: {filename}, {str(e)}' return f'{Ent.Singular(entityType)}: {filename}, {str(e)}'
@@ -209,7 +204,6 @@ def deleteFile(filename, continueOnError=False, displayError=True):
systemErrorExit(FILE_ERROR_RC, fileErrorMessage(filename, e)) systemErrorExit(FILE_ERROR_RC, fileErrorMessage(filename, e))
def getGDocSheetDataRetryWarning(entityValueList, errMsg, i=0, count=0): def getGDocSheetDataRetryWarning(entityValueList, errMsg, i=0, count=0):
Ent = _getEnt()
action = Act.Get() action = Act.Get()
Act.Set(Act.RETRIEVE_DATA) Act.Set(Act.RETRIEVE_DATA)
stderrWarningMsg(formatKeyValueList(Ind.Spaces(), stderrWarningMsg(formatKeyValueList(Ind.Spaces(),
@@ -218,7 +212,6 @@ def getGDocSheetDataRetryWarning(entityValueList, errMsg, i=0, count=0):
Act.Set(action) Act.Set(action)
def getGDocSheetDataFailedExit(entityValueList, errMsg, i=0, count=0): def getGDocSheetDataFailedExit(entityValueList, errMsg, i=0, count=0):
Ent = _getEnt()
Act.Set(Act.RETRIEVE_DATA) Act.Set(Act.RETRIEVE_DATA)
systemErrorExit(ACTION_FAILED_RC, formatKeyValueList(Ind.Spaces(), systemErrorExit(ACTION_FAILED_RC, formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Act.NotPerformed(), errMsg], Ent.FormatEntityValueList(entityValueList)+[Act.NotPerformed(), errMsg],
@@ -265,9 +258,8 @@ def openGAMCommandLog(Globals, name):
systemErrorExit(CONFIG_ERROR_RC, Msg.LOGGING_INITIALIZATION_ERROR.format(str(e))) systemErrorExit(CONFIG_ERROR_RC, Msg.LOGGING_INITIALIZATION_ERROR.format(str(e)))
def writeGAMCommandLog(Globals, logCmd, sysRC): def writeGAMCommandLog(Globals, logCmd, sysRC):
import sys as _sys # noqa: PLC0415 from util.args import currentISOformatTimeStamp
gam = _sys.modules['gam'] Globals[GM.CMDLOG_LOGGER].info(f'{currentISOformatTimeStamp()},{sysRC},{logCmd}')
Globals[GM.CMDLOG_LOGGER].info(f'{gam.currentISOformatTimeStamp()},{sysRC},{logCmd}')
def closeGAMCommandLog(Globals): def closeGAMCommandLog(Globals):
try: try: