def linuxPkg_versionGet(pkgName, ): """ ** Return version as string if Python pkgName is installed ** Return None if Python pkgName is not installed """ dpkgQueryOpts = """dpkg-query --show --showformat='${db:Status-Status}\n'""" outcome = icm.subProc_bash("""{dpkgQueryOpts} {pkgName}""".format( dpkgQueryOpts=dpkgQueryOpts, pkgName=pkgName)).log() if outcome.isProblematic(): icm.EH_badOutcome(outcome) return None resultStr = outcome.stdout.strip() if resultStr == "": return None dpkgQueryOpts = """dpkg-query --show --showformat='${Version}\n'""" outcome = icm.subProc_bash("""{dpkgQueryOpts} {pkgName}""".format( dpkgQueryOpts=dpkgQueryOpts, pkgName=pkgName)).log() if outcome.isProblematic(): icm.EH_badOutcome(outcome) return None resultStr = outcome.stdout.strip() if resultStr == "": return None else: return resultStr
def cmnd(self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate(callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: outcome = icm.subProc_bash("""\ wget http://petstore.swagger.io/v2/swagger.json""" ).log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) outcome = icm.subProc_bash("""\ {myName} -i headersCreate > {headersFileName}""" .format( myName=G.icmMyName(), headersFileName="./bearerToken.headers", ) ).log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=None, )
def cmnd( self, interactive=False, # Can also be called non-interactively sessionType=None, # or Cmnd-Input nuOfDisplays=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'sessionType': sessionType, 'nuOfDisplays': nuOfDisplays, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome sessionType = callParamsDict['sessionType'] nuOfDisplays = callParamsDict['nuOfDisplays'] ####+END: if not nuOfDisplays: outcome = nuOfDisplaysGet().cmnd() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) nuOfDisplays = outcome.results outcome = screenstudioRcStdout().cmnd( interactive=False, sessionType=sessionType, nuOfDisplays=nuOfDisplays, ) if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) screenstudioRcStr = outcome.results screenstudioRcPath = screenstudioRcFileNameGet(sessionType, nuOfDisplays) with open(screenstudioRcPath, "w") as thisFile: thisFile.write(screenstudioRcStr + '\n') if interactive: icm.ANN_here( "screenstudioRcPath={val}".format(val=screenstudioRcPath)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=screenstudioRcPath, )
def cmnd( self, interactive=False, # Can also be called non-interactively panelBase=None, # or Cmnd-Input argsList=None, # or Args-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome effectiveArgsList = G.icmRunArgsGet().cmndArgs else: effectiveArgsList = argsList callParamsDict = { 'panelBase': panelBase, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome panelBase = callParamsDict['panelBase'] ####+END: for eachArg in effectiveArgsList: outcome = icm.subProc_bash("""\ {eachArg} -i bleepPlayUpdated""".format(eachArg=eachArg)).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome))
def cmnd( self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: """ ** TODO UnUsed. """ #offlineimaprcPath = withInMailDomGetOfflineimaprcPath(controlProfile, inMailAcct) outcome = icm.subProc_bash("""screenstudio""").log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=None, )
def cmnd( self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: outcome = icm.subProc_bash("""\ xrandr -q | grep ' connected' | wc -l\ """).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) nuOfScreens = outcome.stdout.strip('\n') if interactive: icm.ANN_write("{}".format(nuOfScreens)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=nuOfScreens, )
def cmnd( self, interactive=False, # Can also be called non-interactively bxoId=None, # or Cmnd-Input sr=None, # or Cmnd-Input inMailAcct=None, # or Cmnd-Input argsList=[], # or Args-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome effectiveArgsList = G.icmRunArgsGet().cmndArgs else: effectiveArgsList = argsList callParamsDict = { 'bxoId': bxoId, 'sr': sr, 'inMailAcct': inMailAcct, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome bxoId = callParamsDict['bxoId'] sr = callParamsDict['sr'] inMailAcct = callParamsDict['inMailAcct'] cmndArgsSpecDict = self.cmndArgsSpec() if not self.cmndArgsValidate( effectiveArgsList, cmndArgsSpecDict, outcome=cmndOutcome): return cmndOutcome ####+END: cmndArgs = self.cmndArgsGet("0&-1", cmndArgsSpecDict, effectiveArgsList) joinedArgs = ucf.str_joinedArgs(cmndArgs) defaultMailDom = marmeAcctsLib.enabledInMailAcctObtain( bxoId=bxoId, sr=sr, ) configFile = withInMailDomGetNotmuchConfigPath( defaultMailDom, bxoId=bxoId, sr=sr, ) outcome = icm.subProc_bash( """notmuch --config={configFile} {joinedArgs}""".format( configFile=configFile, joinedArgs=joinedArgs, )).out() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) if interactive: pass return outcome.set(opError=icm.OpError.Success, #opResults=outcome.stdout )
def cmnd( self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: G = icm.IcmGlobalContext() argsList = G.icmRunArgsGet().cmndArgs G_myFullName = sys.argv[0] for eachArg in argsList: outcome = icm.subProc_bash( """{icmName} -v 20 -i {command}""".format( icmName=G_myFullName, command=eachArg, )).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) # eval("""{command}().cmnd(interactive=False,)""".format( # command=eachArg, # )) return cmndOutcome
def cmnd(self, interactive=False, # Can also be called non-interactively inMailAcct=None, # or IIF Parameter ): """ """ myName=self.myName() G = icm.IcmGlobalContext() thisOutcome = icm.OpOutcome(invokerName=myName) if interactive: if not self.cmndLineValidate(outcome=thisOutcome): return(thisOutcome) if not inMailAcct: if not interactive: return icm.eh_problem_usageError( thisOutcome, "Missing Non-Interactive Arg (inMailAcct)", ) inMailAcct = G.usageParams.inMailAcct outcome = icm.subProc_bash("""echo Preparing the package""").log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) return thisOutcome.set( opError=icm.OpError.Success, opResults=None, )
def update(self): pkgsList = self.pkgsListObtain() activateFile = os.path.join(self.virtualenvBaseDir, "bin/activate") for each in pkgsList: outcome = icm.subProc_bash("""\ source {activateFile}; \ pip install --no-cache-dir {each}; \ """.format(activateFile=activateFile, each=each)).out() if outcome.isProblematic(): return icm.EH_badOutcome(outcome)
def cmnd( self, interactive=False, # Can also be called non-interactively sessionType=None, # or Cmnd-Input nuOfDisplays=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'sessionType': sessionType, 'nuOfDisplays': nuOfDisplays, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome sessionType = callParamsDict['sessionType'] nuOfDisplays = callParamsDict['nuOfDisplays'] ####+END: if not nuOfDisplays: outcome = nuOfDisplaysGet().cmnd() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) nuOfDisplays = outcome.result cwd = os.getcwd() if sessionType == "narratedSession": audiosystemStr = """Monitor of Built-in Audio Analog Stereo""" microphoneStr = """None""" elif sessionType == "liveSession": audiosystemStr = """None""" microphoneStr = """Yeti Stereo Microphone Analog Stereo""" else: icm.EH_usageError("Bad sessionType -- {}".format(sessionType)) displaysStr = screenstudioRcTemplate(nuOfDisplays, ) if displaysStr: resStr = displayStr.format( audiosystemStr=audiosystemStr, microphoneStr=microphoneStr, outputvideofolderStr=cwd, ) else: resStr = "" # NOTYET, Is This An Error? if interactive: print(resStr) return cmndOutcome.set(opError=icm.OpError.Success, opResults=resStr)
def inFilesListForOne(mainLatexFile): thisPrefix, thisExtension = os.path.splitext(mainLatexFile) thisOutcome = icm.OpOutcome(invokerName=G.icmMyFullName()) thisOutcome = icm.subProc_bash( """xelatex -recorder {mainLatexFile}""".format( mainLatexFile=mainLatexFile), stdin=None, outcome=thisOutcome, ) #.out() if thisOutcome.isProblematic(): return (icm.EH_badOutcome(thisOutcome)) thisOutcome = icm.subProc_bash( """egrep '(^INPUT )([a-z|A-Z]|\.)' {thisPrefix}.fls | sort | uniq | egrep -v 'aux$' | cut -d ' ' -f 2""" .format(thisPrefix=thisPrefix), stdin=None, outcome=thisOutcome, ) #.out() if thisOutcome.isProblematic(): return (icm.EH_badOutcome(thisOutcome)) inFilesList = list() for each in thisOutcome.stdout.splitlines(): thisPrefix, thisExtension = os.path.splitext(each) if thisExtension in [ ".vrb", ".out", ".bbl", ".nav", ".cut", ".toc", ".lof", ]: continue else: inFilesList.append(each) return inFilesList
def pythonPkg_install_pip( pkgName, pkgVersion, ): """ ** Install a given Python pkg based on its canonical name and version. If version is specified, the package is installed or updated to that version. If version is None, if package is already installed no action is taken if package is not installed, the latest is installed """ installedVersion = pythonPkg_versionGet(pkgName) if pkgVersion: if installedVersion == pkgVersion: icm.ANN_write( "Python:: {pkgName} ver={ver} (as expected) is already installed -- skipped" .format(pkgName=pkgName, ver=installedVersion)) return else: outcome = icm.subProc_bash( """echo pip install {pkgName}=={pkgVersion}""".format( pkgName=pkgName, pkgVersion=pkgVersion)).log() if outcome.isProblematic(): return icm.EH_badOutcome(outcome) resultStr = outcome.stdout.strip() icm.ANN_write(resultStr) return installedVersion = pythonPkg_versionGet(pkgName) if installedVersion: icm.ANN_write( "Python:: {pkgName} ver={ver} (as any) is already installed -- skipped" .format(pkgName=pkgName, ver=installedVersion)) return else: outcome = icm.subProc_bash( """echo pip install {pkgName}""".format(pkgName=pkgName)).log() if outcome.isProblematic(): return icm.EH_badOutcome(outcome) resultStr = outcome.stdout.strip() icm.ANN_write(resultStr) return
def cmnd( self, interactive=False, # Can also be called non-interactively rsrc=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'rsrc': rsrc, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome rsrc = callParamsDict['rsrc'] ####+END: rsrcPath = os.path.normpath(rsrc) rsrcParts = rsrcPath.split(os.sep) rsrcBase = rsrcParts[0] system = rsrcParts[1] user = rsrcParts[2] outcome = cryptKeyring.clearPasswdGet().cmnd( interactive=False, rsrc=rsrc, ).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) accessKey = user secretKey = outcome.results outcome = getToken().cmnd( interactive=False, accessKey=accessKey, secretKey=secretKey, ).log() token = outcome.results if interactive: print(json.dumps(token, indent=4)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=token, )
def prepare(self): ####+END: """ create ucrypt policy. """ outcome = symCrypt.createEncryptionPolicy().cmnd( interactive=False, rsrc="policy", policy=self.__class__.ucryptPolicy, keyringPolicy=self.__class__.ucryptKeyPasswdPolicy, #argsList=[], ).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) print(outcome.results)
def linuxPkgInstall_yum( pkgName, pkgVersion, ): """ ** Install a given linux pkg with yum based on its canonical name and version. """ outcome = icm.subProc_bash( """sudo yum install {pkgName}""".format(pkgName=pkgName)).log() if outcome.isProblematic(): return icm.EH_badOutcome(outcome) resultStr = outcome.stdout.strip() icm.ANN_write(resultStr) return
def linuxPkgInstall_aptGet( pkgName, pkgVersion, ): """ ** Install a given linux pkg with apt-get based on its canonical name and version. """ installedVersion = linuxPkg_versionGet(pkgName) if pkgVersion: if installedVersion == pkgVersion: icm.ANN_write( "Linux:: {pkgName} ver={ver} (as expected) is already installed -- skipped" .format(pkgName=pkgName, ver=installedVersion)) return else: outcome = icm.subProc_bash( """echo NOTYET pip install {pkgName}=={pkgVersion}""".format( pkgName=pkgName, pkgVersion=pkgVersion)).log() if outcome.isProblematic(): return icm.EH_badOutcome(outcome) resultStr = outcome.stdout.strip() icm.ANN_write(resultStr) return installedVersion = linuxPkg_versionGet(pkgName) if installedVersion: icm.ANN_write( "Linux:: {pkgName} ver={ver} (as any) is already installed -- skipped" .format(pkgName=pkgName, ver=installedVersion)) return else: outcome = icm.subProc_bash("""sudo apt-get install {pkgName}""".format( pkgName=pkgName)).log() if outcome.isProblematic(): return icm.EH_badOutcome(outcome) resultStr = outcome.stdout.strip() icm.ANN_write(resultStr) return
def cmnd( self, interactive=False, # Can also be called non-interactively bxoId=None, # or Cmnd-Input sr=None, # or Cmnd-Input controlProfile=None, # or Cmnd-Input inMailAcct=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'bxoId': bxoId, 'sr': sr, 'controlProfile': controlProfile, 'inMailAcct': inMailAcct, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome bxoId = callParamsDict['bxoId'] sr = callParamsDict['sr'] controlProfile = callParamsDict['controlProfile'] inMailAcct = callParamsDict['inMailAcct'] ####+END: """ ** TODO Make inMailAcct come from args not params """ offlineimaprcPath = withInMailDomGetOfflineimaprcPath( controlProfile, inMailAcct, bxoId, sr, ) outcome = icm.subProc_bash( """offlineimap -c {offlineimaprcPath}""".format( offlineimaprcPath=offlineimaprcPath)).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=None, )
def pythonPkg_locationGet(pkgName, ): """ ** Return location as string if Python pkgName is installed ** Return None if Python pkgName is not installed """ outcome = icm.subProc_bash( """pip show {pkg} | egrep '^Location' | cut -d ':' -f 2""".format( pkg=pkgName)).log() if outcome.isProblematic(): icm.EH_badOutcome(outcome) return None resultStr = outcome.stdout.strip() if resultStr == "": return None else: return resultStr
def cmnd(self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate(callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: outcome = icm.subProc_bash( """inMailRetrieve.py -v 20 -i offlineimapRun""" ).log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) return cmndOutcome
def passwdGet(self): ####+END: """ Return passwd.""" keyringPasswd = keyring.get_password(self.system, self.user) outcome = symCrypt.decrypt().cmnd( interactive=False, rsrc="policy/{}".format(self.__class__.ucryptPolicy), cipherText=keyringPasswd, ).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) clearPasswd = outcome.results icm.LOG_here(clearPasswd) return clearPasswd
def cmnd( self, interactive=False, # Can also be called non-interactively panelBase=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'panelBase': panelBase, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome panelBase = callParamsDict['panelBase'] ####+END: panelBasePath = panelBasePathObtain(panelBase) icmName = G.icmMyName() icmPrefix, icmExtension = os.path.splitext(icmName) panelFileName = "{}-Panel.org".format(icmPrefix) panelFileFullPath = os.path.join( panelBasePath, panelFileName, ) if os.path.isfile(panelFileFullPath): outcome = icm.subProc_bash("""\ emacsclient -n --eval '(find-file \"{panelFileFullPath}\")' """.format( panelFileFullPath=panelFileFullPath)).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) else: icm.EH_problem("Missing File -- Run Update First") icm.ANN_note("ls -l {}".format(panelFileFullPath)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=None, )
def cmnd( self, interactive=False, # Can also be called non-interactively argsList=[], # or Args-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome effectiveArgsList = G.icmRunArgsGet().cmndArgs else: effectiveArgsList = argsList callParamsDict = {} if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome cmndArgsSpec = self.cmndArgsSpec() if not icm.cmndArgsValidate( effectiveArgsList, cmndArgsSpec, outcome=cmndOutcome): return cmndOutcome ####+END: action = effectiveArgsList[0] effectiveArgsList.pop(0) print(action) for each in effectiveArgsList: print(each) outcome = icm.subProc_bash("""\ echo action={action} {argsList}""".format( action=action, argsList=" ".join(effectiveArgsList))).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=None, ) ####+BEGIN: bx:icm:python:method :methodName "cmndArgsSpec" :methodType "anyOrNone" :retType "bool" :deco "default" :argsList "" """
def cmnd( self, interactive=False, # Can also be called non-interactively periodicity=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'periodicity': periodicity, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome periodicity = callParamsDict['periodicity'] ####+END: G = icm.IcmGlobalContext() argsList = G.icmRunArgsGet().cmndArgs G_myFullName = sys.argv[0] while True: for eachArg in argsList: outcome = icm.subProc_bash( """{icmName} -v 20 -i {command}""".format( icmName=G_myFullName, command=eachArg, )).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) icm.ANN_note( "sleeping for: {periodicity}".format(periodicity=periodicity)) try: time.sleep(int(periodicity)) except KeyboardInterrupt: print('\n\nKeyboard exception received. Exiting.') exit() icm.ANN_note("End of sleeping")
def cmnd(self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate(callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: #G = icm.IcmGlobalContext() outcome = icm.subProc_bash( """inMailDsnProc.py -v 20 -i maildirApplyToMsg dsnTestSendToCoRecipients""" ).log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) return cmndOutcome
def cmnd(self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate(callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: #G = icm.IcmGlobalContext() outcome = icm.subProc_bash( """inMailUserAgent.py -v 20 -i runNotmuch new""" ).log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) return cmndOutcome
def passwdSet( self, passwd, ): ####+END: """ Return passwd string from keyring. """ outcome = symCrypt.encrypt().cmnd( interactive=False, rsrc="policy/{}".format(self.__class__.ucryptPolicy), clearText=passwd, ).log() if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) cipheredPasswd = outcome.results keyring.set_password(self.system, self.user, cipheredPasswd) keyringPasswd = keyring.get_password(self.system, self.user) icm.LOG_here(keyringPasswd) return keyringPasswd
def cmnd( self, interactive=False, # Can also be called non-interactively bxoId=None, # or Cmnd-Input sr=None, # or Cmnd-Input inFile=None, # or Cmnd-Input msg=None, # asFunc when interactive==False ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'bxoId': bxoId, 'sr': sr, 'inFile': inFile, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome bxoId = callParamsDict['bxoId'] sr = callParamsDict['sr'] inFile = callParamsDict['inFile'] ####+END: G = icm.IcmGlobalContext() if not msg: if inFile: msg = msgIn.getMsgFromFile(inFile) else: # Stdin then msg = msgIn.getMsgFromStdin() else: # non-interactive call with msg if not bxoId: icm.EH_problem_usageError("") return cmndOutcome icm.LOG_here(msgOut.strLogMessage( "Msg As Input:", msg, )) icm.LOG_here(G.icmRunArgsGet().runMode) outcome = msgOut.sendingRunControlSet(msg, G.icmRunArgsGet().runMode) if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) bx822Set_setMandatoryFields(msg) outcome = bx822Get_sendingFieldsPipelineLoad( bxoId, sr, msg, ) if outcome.isProblematic(): return (icm.EH_badOutcome(outcome)) if outcome.results != "INCOMPLETE": icm.LOG_here("Complete Message Being Sent") return (msgOut.sendBasedOnHeadersInfo(msg)) icm.LOG_here("Incomplete Message -- using qmail+dryrun") msgOut.injectionParams( msg, injectionProgram=msgOut.InjectionProgram.qmail, sendingRunControl=msgOut.SendingRunControl.dryRun, ) return msgOut.sendBasedOnHeadersInfo(msg)
def mailSendingExample(): bxoId = curGet_bxoId() sr = curGet_sr() sendingMethod = msgOut.SendingMethod.submit msg = email.message.Message() #msg = MIMEText() # MIMEMultipart() msg['From'] = fromLine msg['To'] = toLine msg['Subject'] = """Example Of A Simple And Tracked Message""" envelopeAddr = envelopeLine if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return msgOut.sendingMethodSet(msg, sendingMethod) msg.add_header('Content-Type', 'text') msg.set_payload(""" This is a simple example message with a simple attachment being sent using the current enabled controlledProfile and mailAcct. On the sending end, use mailAcctsManage.py with -i enabledControlProfileSet and -i enabledMailAcctSet to select the outgoing profile. The current settings are: ControlProfile={controlProfile} -- MailAcct={mailAcct} This message is then submitted for sending with sendCompleteMessage().cmnd(msg) """.format(controlProfile=marmeAcctsLib.enabledControlProfileObtain( curGet_bxoId(), curGet_sr(), ), mailAcct=marmeAcctsLib.enabledInMailAcctObtain( curGet_bxoId(), curGet_sr(), ))) # ########################### # # Above is the real content of the email. # # We now augment the message with: # - explicit envelope address -- To be used for Delivery-Status-Notifications (DSN) # - The email is to be tagged for crossReferencing when DSN is received (e.g. with peepid) # - Request that non-delivery-reports be acted upon and sent to co-recipients # - Explicit delivery-reports are requested # - Explicit read-receipts are requested # - Injection/Submission parameters are specified # The message is then sent out # msgOut.envelopeAddrSet( msg, mailBoxAddr=envelopeAddr, # Mandatory ) # # e.g., peepId will be used to crossRef StatusNotifications # msgOut.crossRefInfo( msg, crossRefInfo="XrefForStatusNotifications" # Mandatory ) # # Delivery Status Notifications will be sent to notifyTo=envelopeAddr # msgOut.nonDeliveryNotificationRequetsForTo( msg, notifyTo=envelopeAddr, ) # # In case of Non-Delivery, coRecipientsList will be informed # msgOut.nonDeliveryNotificationActions( msg, coRecipientsList=[toLine], ) # # Explicit Delivery Report is requested # msgOut.deliveryNotificationRequetsForTo( msg, recipientsList=[toLine], notifyTo=envelopeAddr, ) # # Explicit Read Receipt is requested # msgOut.dispositionNotificationRequetsForTo( msg, recipientsList=[toLine], notifyTo=envelopeAddr, ) if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return icm.EH_badLastOutcome() if not marmeSendLib.bx822Set_sendWithEnabledAcct( msg=msg, sendingMethod=sendingMethod, bxoId=bxoId, sr=sr, ): return icm.EH_badOutcome() marmeTrackingLib.trackDelivery_injectBefore( bxoId, sr, msg, ) cmndOutcome = marmeSendLib.sendCompleteMessage().cmnd( interactive=False, msg=msg, bxoId=bxoId, sr=sr, ) marmeTrackingLib.trackDelivery_injectAfter( bxoId, sr, msg, ) return cmndOutcome
def cmnd(self, interactive=False, # Can also be called non-interactively argsList=[], # or Args-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome effectiveArgsList = G.icmRunArgsGet().cmndArgs else: effectiveArgsList = argsList callParamsDict = {} if not icm.cmndCallParamsValidate(callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome cmndArgsSpecDict = self.cmndArgsSpec() if not self.cmndArgsValidate(effectiveArgsList, cmndArgsSpecDict, outcome=cmndOutcome): return cmndOutcome ####+END: def withPbdNameGetRootForPlatform(pbdName): rootDirName = None bxPlatformConfigBase = bxPlatformThis.pkgBase_configDir() if pbdName == "bisosRoot": rootDirName = bxPlatformConfig.rootDir_bisos_fpObtain(bxPlatformConfigBase) elif pbdName == "deRunRoot": rootDirName = bxPlatformConfig.rootDir_bxo_fpObtain(bxPlatformConfigBase) elif pbdName == "bxoRoot": rootDirName = bxPlatformConfig.rootDir_deRun_fpObtain(bxPlatformConfigBase) else: icm.EH_problem_usageError("") return rootDirName bisosUserName = "******" #bisosUserName_obtain() bisosGroupName = "NOTYET" #bisosGroupName_obtain() pbdNamesList = self.cmndArgsGet("0&-1", cmndArgsSpecDict, effectiveArgsList) if pbdNamesList[0] == "all": cmndArgsSpec = cmndArgsSpecDict.argPositionFind("0&-1") argChoices = cmndArgsSpec.argChoicesGet() argChoices.pop(0) pbdNamesList = argChoices for each in pbdNamesList: rootDir = withPbdNameGetRootForPlatform(each) # icm.ANN_here("{} -- {}".format(each, rootDir)) try: os.makedirs(rootDir) except OSError: if not os.path.isdir(rootDir): raise # Python 3 #shutil.chown(rootDir, bisosUserName, bisosGroupName) uid = pwd.getpwnam(bisosUserName).pw_uid gid = grp.getgrnam(bisosGroupName).gr_gid os.chown(rootDir, uid, gid) os.chmod(rootDir, 0o775) outcome = icm.subProc_bash("""\ ls -ld {rootDir}""" .format(rootDir=rootDir) ).log() if outcome.isProblematic(): return(icm.EH_badOutcome(outcome)) #icm.ANN_here("{}".format(bisosUserName)) return cmndOutcome.set( opError=icm.OpError.Success, opResults=None, )