Add Agent NEW_CONSOLE to subprocess

Add New def in Agent to list all process in user
Update Guide
dev-linux
Ivan Maslov 4 years ago
parent 21f7f1f86d
commit b0b821aed8

@ -1 +0,0 @@
C:\Abs\Archive\scopeSrcUL\OpenRPA\WebTest.py

@ -0,0 +1,23 @@
####################################
2. Defs
####################################
**************************************************
pyOpenRPA.Agent.__Agent__
**************************************************
.. automodule:: pyOpenRPA.Agent.__Agent__
:members:
:autosummary:
**********
References
**********
`reStructuredText`_
.. target-notes::
.. _`reStructuredText`: http://docutils.sourceforge.net/rst.html

@ -155,3 +155,10 @@ Guide content
:glob:
Orchestrator/*
.. toctree::
:maxdepth: 3
:caption: AGENT
:glob:
Agent/*

@ -1,6 +1,7 @@
import threading, socket, getpass, sys, uuid, subprocess, base64
import threading, socket, getpass, sys, uuid, subprocess, base64, psutil, getpass
from . import O2A, A2O # Data flow Orchestrator To Agent
from . import Processor # Processor Queue
from subprocess import CREATE_NEW_CONSOLE # Flag to create new process in another CMD
# Create binary file by the base64 string (safe for JSON transmition)
def OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str,inGSettings = None):
@ -41,7 +42,7 @@ def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None, inSendOutputToOrche
lL = inGSettings.get("Logger",None) if type(inGSettings) is dict else None
lResultStr = ""
lOSCMDKeyStr = str(uuid.uuid4())[0:4].upper()
lCMDProcess = subprocess.Popen(f'cmd /c {inCMDStr}', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
lCMDProcess = subprocess.Popen(f'cmd /c {inCMDStr}', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, creationflags=CREATE_NEW_CONSOLE)
lListenBool = True
lMessageStr = f"{lOSCMDKeyStr}: # # # # AGENT CMD Process has been STARTED # # # # "
if lL: lL.info(lMessageStr)
@ -76,6 +77,31 @@ def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None, inSendOutputToOrche
return lResultStr
def ProcessWOExeUpperUserListGet():
"""
Return the process list only for the current user (where Agent is running) without .EXE in upper case. Can use in ActivityItem from Orchestrator to Agent
:param inProcessNameWOExeList:
:return: list of the agent user process in upper case without .EXE. Example ["NOTEPAD","..."],
"""
lUserNameStr = getpass.getuser()
lResult = []
# Create updated list for quick check
lProcessNameWOExeList = []
# Iterate over the list
for proc in psutil.process_iter():
try:
# Fetch process details as dict
pinfo = proc.as_dict(attrs=['pid', 'name', 'username'])
# Add if empty inProcessNameWOExeList or if process in inProcessNameWOExeList
lUserNameWODomainStr = proc.username().split('\\')[-1]
if lUserNameWODomainStr == lUserNameStr:
lResult.append(pinfo['name'][:-4].upper())
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return lResult
# Main def
def Agent(inGSettings):
lL = inGSettings["Logger"]

@ -116,6 +116,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -112,6 +112,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -116,6 +116,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -0,0 +1,309 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>2. Defs &mdash; pyOpenRPA v1.2.0 documentation</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="prev" title="5. UAC - User Access Control" href="../Orchestrator/05_UAC.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home"> pyOpenRPA
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">GENERAL</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../01_HowToInstall.html">1. How to install</a></li>
<li class="toctree-l1"><a class="reference internal" href="../02_RoadMap.html">2. Roadmap</a></li>
<li class="toctree-l1"><a class="reference internal" href="../03_Copyrights_Contacts.html">3. Copyrights &amp; Contacts</a></li>
</ul>
<p class="caption"><span class="caption-text">ROBOT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Robot/01_Robot.html">1. Description</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Robot/02_Defs.html">2. Defs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Robot/03_HowToUse.html">3. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Robot/04_Dependencies.html">4. Dependencies</a></li>
</ul>
<p class="caption"><span class="caption-text">STUDIO</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Studio/01_Studio.html">1. Description</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Studio/02_HowToUse.html">2. How to use</a></li>
</ul>
<p class="caption"><span class="caption-text">ORCHESTRATOR</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/01_Orchestrator.html">1. Description</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/02_Defs.html">2. Defs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/03_gSettingsTemplate.html">3. gSettings Template</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">2. Defs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-pyOpenRPA.Agent.__Agent__">pyOpenRPA.Agent.__Agent__</a></li>
<li class="toctree-l2"><a class="reference internal" href="#references">References</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">pyOpenRPA</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
<li>2. Defs</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/Agent/02_Defs.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="defs">
<h1>2. Defs<a class="headerlink" href="#defs" title="Permalink to this headline"></a></h1>
<div class="section" id="module-pyOpenRPA.Agent.__Agent__">
<span id="pyopenrpa-agent-agent"></span><h2>pyOpenRPA.Agent.__Agent__<a class="headerlink" href="#module-pyOpenRPA.Agent.__Agent__" title="Permalink to this headline"></a></h2>
<p><strong>Functions:</strong></p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#pyOpenRPA.Agent.__Agent__.OSCMD" title="pyOpenRPA.Agent.__Agent__.OSCMD"><code class="xref py py-obj docutils literal notranslate"><span class="pre">OSCMD</span></code></a>(inCMDStr[, inRunAsyncBool, …])</p></td>
<td><p>Execute CMD on the Agent daemonic process</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate" title="pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">OSFileBinaryDataBase64StrCreate</span></code></a>(…[, …])</p></td>
<td><p>Create binary file by the base64 string (safe for JSON transmition)</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet" title="pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ProcessWOExeUpperUserListGet</span></code></a>()</p></td>
<td><p>Return the process list only for the current user (where Agent is running) without .EXE in upper case.</p></td>
</tr>
</tbody>
</table>
<dl class="py function">
<dt id="pyOpenRPA.Agent.__Agent__.OSCMD">
<code class="sig-prename descclassname">pyOpenRPA.Agent.__Agent__.</code><code class="sig-name descname">OSCMD</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">inCMDStr</span></em>, <em class="sig-param"><span class="n">inRunAsyncBool</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">inGSettings</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">inSendOutputToOrchestratorLogsBool</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">inCMDEncodingStr</span><span class="o">=</span><span class="default_value">'cp1251'</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/pyOpenRPA/Agent/__Agent__.html#OSCMD"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyOpenRPA.Agent.__Agent__.OSCMD" title="Permalink to this definition"></a></dt>
<dd><p>Execute CMD on the Agent daemonic process</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>inCMDStr</strong> command to execute on the Agent session</p></li>
<li><p><strong>inRunAsyncBool</strong> True - Agent processor dont wait execution; False - Agent processor wait cmd execution</p></li>
<li><p><strong>inGSettings</strong> Agent global settings dict</p></li>
<li><p><strong>inSendOutputToOrchestratorLogsBool</strong> True - catch cmd execution output and send it to the Orchestrator logs; Flase - else case; Default True</p></li>
<li><p><strong>inCMDEncodingStr</strong> Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is “cp1251” early was “cp866” - need test</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt id="pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate">
<code class="sig-prename descclassname">pyOpenRPA.Agent.__Agent__.</code><code class="sig-name descname">OSFileBinaryDataBase64StrCreate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">inFilePathStr</span></em>, <em class="sig-param"><span class="n">inFileDataBase64Str</span></em>, <em class="sig-param"><span class="n">inGSettings</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/pyOpenRPA/Agent/__Agent__.html#OSFileBinaryDataBase64StrCreate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate" title="Permalink to this definition"></a></dt>
<dd><p>Create binary file by the base64 string (safe for JSON transmition)</p>
</dd></dl>
<dl class="py function">
<dt id="pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet">
<code class="sig-prename descclassname">pyOpenRPA.Agent.__Agent__.</code><code class="sig-name descname">ProcessWOExeUpperUserListGet</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/pyOpenRPA/Agent/__Agent__.html#ProcessWOExeUpperUserListGet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet" title="Permalink to this definition"></a></dt>
<dd><p>Return the process list only for the current user (where Agent is running) without .EXE in upper case. Can use in ActivityItem from Orchestrator to Agent</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>inProcessNameWOExeList</strong> </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>list of the agent user process in upper case without .EXE. Example [“NOTEPAD”,”…”],</p>
</dd>
</dl>
</dd></dl>
</div>
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> <a class="footnote-reference brackets" href="#id1" id="id2">1</a></p>
<dl class="footnote brackets">
<dt class="label" id="id1"><span class="brackets"><a class="fn-backref" href="#id2">1</a></span></dt>
<dd><p><a class="reference external" href="http://docutils.sourceforge.net/rst.html">http://docutils.sourceforge.net/rst.html</a></p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../Orchestrator/05_UAC.html" class="btn btn-neutral float-left" title="5. UAC - User Access Control" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&#169; Copyright 2021, Ivan Maslov.
</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

@ -119,6 +119,10 @@
<li class="toctree-l1"><a class="reference internal" href="04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -128,6 +128,10 @@
<li class="toctree-l1"><a class="reference internal" href="04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -112,6 +112,10 @@
<li class="toctree-l1"><a class="reference internal" href="04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -112,6 +112,10 @@
<li class="toctree-l1 current"><a class="current reference internal" href="#">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -40,6 +40,7 @@
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="2. Defs" href="../Agent/02_Defs.html" />
<link rel="prev" title="4. How to use" href="04_HowToUse.html" />
</head>
@ -115,6 +116,10 @@
</ul>
</li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>
@ -237,6 +242,7 @@
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../Agent/02_Defs.html" class="btn btn-neutral float-right" title="2. Defs" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
<a href="04_HowToUse.html" class="btn btn-neutral float-left" title="4. How to use" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
</div>

@ -112,6 +112,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -115,6 +115,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -141,6 +141,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -112,6 +112,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -112,6 +112,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -135,6 +135,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -110,6 +110,10 @@
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../Agent/02_Defs.html">2. Defs</a></li>
</ul>
@ -173,7 +177,8 @@
<div itemprop="articleBody">
<h1>All modules for which code is available</h1>
<ul><li><a href="pyOpenRPA/Orchestrator/__Orchestrator__.html">pyOpenRPA.Orchestrator.__Orchestrator__</a></li>
<ul><li><a href="pyOpenRPA/Agent/__Agent__.html">pyOpenRPA.Agent.__Agent__</a></li>
<li><a href="pyOpenRPA/Orchestrator/__Orchestrator__.html">pyOpenRPA.Orchestrator.__Orchestrator__</a></li>
<li><a href="pyOpenRPA/Robot/UIDesktop.html">pyOpenRPA.Robot.UIDesktop</a></li>
</ul>

@ -0,0 +1,360 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pyOpenRPA.Agent.__Agent__ &mdash; pyOpenRPA v1.2.0 documentation</title>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> pyOpenRPA
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">GENERAL</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../01_HowToInstall.html">1. How to install</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../02_RoadMap.html">2. Roadmap</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../03_Copyrights_Contacts.html">3. Copyrights &amp; Contacts</a></li>
</ul>
<p class="caption"><span class="caption-text">ROBOT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Robot/01_Robot.html">1. Description</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Robot/02_Defs.html">2. Defs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Robot/03_HowToUse.html">3. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Robot/04_Dependencies.html">4. Dependencies</a></li>
</ul>
<p class="caption"><span class="caption-text">STUDIO</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Studio/01_Studio.html">1. Description</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Studio/02_HowToUse.html">2. How to use</a></li>
</ul>
<p class="caption"><span class="caption-text">ORCHESTRATOR</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/01_Orchestrator.html">1. Description</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/02_Defs.html">2. Defs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/03_gSettingsTemplate.html">3. gSettings Template</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Agent/02_Defs.html">2. Defs</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">pyOpenRPA</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html" class="icon icon-home"></a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li>pyOpenRPA.Agent.__Agent__</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pyOpenRPA.Agent.__Agent__</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">threading</span><span class="o">,</span> <span class="nn">socket</span><span class="o">,</span> <span class="nn">getpass</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">uuid</span><span class="o">,</span> <span class="nn">subprocess</span><span class="o">,</span> <span class="nn">base64</span><span class="o">,</span> <span class="nn">psutil</span><span class="o">,</span> <span class="nn">getpass</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">O2A</span><span class="p">,</span> <span class="n">A2O</span> <span class="c1"># Data flow Orchestrator To Agent</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">Processor</span> <span class="c1"># Processor Queue</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">CREATE_NEW_CONSOLE</span> <span class="c1"># Flag to create new process in another CMD</span>
<span class="c1"># Create binary file by the base64 string (safe for JSON transmition)</span>
<div class="viewcode-block" id="OSFileBinaryDataBase64StrCreate"><a class="viewcode-back" href="../../../Agent/02_Defs.html#pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate">[docs]</a><span class="k">def</span> <span class="nf">OSFileBinaryDataBase64StrCreate</span><span class="p">(</span><span class="n">inFilePathStr</span><span class="p">,</span> <span class="n">inFileDataBase64Str</span><span class="p">,</span><span class="n">inGSettings</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Create binary file by the base64 string (safe for JSON transmition)&quot;&quot;&quot;</span>
<span class="n">lFile</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">inFilePathStr</span><span class="p">,</span> <span class="s2">&quot;wb&quot;</span><span class="p">)</span>
<span class="n">lFile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">base64</span><span class="o">.</span><span class="n">b64decode</span><span class="p">(</span><span class="n">inFileDataBase64Str</span><span class="p">))</span>
<span class="n">lFile</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">lL</span> <span class="o">=</span> <span class="n">inGSettings</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Logger&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">inGSettings</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">dict</span> <span class="k">else</span> <span class="kc">None</span>
<span class="n">lMessageStr</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;AGENT Binary file </span><span class="si">{</span><span class="n">inFilePathStr</span><span class="si">}</span><span class="s2"> has been created.&quot;</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">lMessageStr</span><span class="p">)</span>
<span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="n">lMessageStr</span><span class="p">])</span></div>
<span class="c1"># Create text file by the string</span>
<span class="k">def</span> <span class="nf">OSFileTextDataStrCreate</span><span class="p">(</span><span class="n">inFilePathStr</span><span class="p">,</span> <span class="n">inFileDataStr</span><span class="p">,</span> <span class="n">inEncodingStr</span> <span class="o">=</span> <span class="s2">&quot;utf-8&quot;</span><span class="p">,</span><span class="n">inGSettings</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="n">lFile</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">inFilePathStr</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="n">inEncodingStr</span><span class="p">)</span>
<span class="n">lFile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">inFileDataStr</span><span class="p">)</span>
<span class="n">lFile</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">lL</span> <span class="o">=</span> <span class="n">inGSettings</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Logger&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">inGSettings</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">dict</span> <span class="k">else</span> <span class="kc">None</span>
<span class="n">lMessageStr</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;AGENT Text file </span><span class="si">{</span><span class="n">inFilePathStr</span><span class="si">}</span><span class="s2"> has been created.&quot;</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">lMessageStr</span><span class="p">)</span>
<span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="n">lMessageStr</span><span class="p">])</span>
<span class="c1"># Send CMD to OS. Result return to log + Orchestrator by the A2O connection</span>
<div class="viewcode-block" id="OSCMD"><a class="viewcode-back" href="../../../Agent/02_Defs.html#pyOpenRPA.Agent.__Agent__.OSCMD">[docs]</a><span class="k">def</span> <span class="nf">OSCMD</span><span class="p">(</span><span class="n">inCMDStr</span><span class="p">,</span> <span class="n">inRunAsyncBool</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">inGSettings</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">inSendOutputToOrchestratorLogsBool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">inCMDEncodingStr</span> <span class="o">=</span> <span class="s2">&quot;cp1251&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Execute CMD on the Agent daemonic process</span>
<span class="sd"> :param inCMDStr: command to execute on the Agent session</span>
<span class="sd"> :param inRunAsyncBool: True - Agent processor don&#39;t wait execution; False - Agent processor wait cmd execution</span>
<span class="sd"> :param inGSettings: Agent global settings dict</span>
<span class="sd"> :param inSendOutputToOrchestratorLogsBool: True - catch cmd execution output and send it to the Orchestrator logs; Flase - else case; Default True</span>
<span class="sd"> :param inCMDEncodingStr: Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is &quot;cp1251&quot; early was &quot;cp866&quot; - need test</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">lResultStr</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="c1"># Subdef to listen OS result</span>
<span class="k">def</span> <span class="nf">_CMDRunAndListenLogs</span><span class="p">(</span><span class="n">inCMDStr</span><span class="p">,</span> <span class="n">inSendOutputToOrchestratorLogsBool</span><span class="p">,</span> <span class="n">inCMDEncodingStr</span><span class="p">,</span> <span class="n">inGSettings</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="n">lL</span> <span class="o">=</span> <span class="n">inGSettings</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Logger&quot;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span> <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">inGSettings</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">dict</span> <span class="k">else</span> <span class="kc">None</span>
<span class="n">lResultStr</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">lOSCMDKeyStr</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="n">lCMDProcess</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;cmd /c </span><span class="si">{</span><span class="n">inCMDStr</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span><span class="p">,</span> <span class="n">creationflags</span><span class="o">=</span><span class="n">CREATE_NEW_CONSOLE</span><span class="p">)</span>
<span class="n">lListenBool</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">lMessageStr</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">lOSCMDKeyStr</span><span class="si">}</span><span class="s2">: # # # # AGENT CMD Process has been STARTED # # # # &quot;</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">lMessageStr</span><span class="p">)</span>
<span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span><span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="n">lMessageStr</span><span class="p">])</span>
<span class="n">lMessageStr</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">lOSCMDKeyStr</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">inCMDStr</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">lMessageStr</span><span class="p">)</span>
<span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="n">lMessageStr</span><span class="p">])</span>
<span class="k">while</span> <span class="n">lListenBool</span><span class="p">:</span>
<span class="n">lOutputLineBytes</span> <span class="o">=</span> <span class="n">lCMDProcess</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="k">if</span> <span class="n">lOutputLineBytes</span> <span class="o">==</span> <span class="sa">b</span><span class="s2">&quot;&quot;</span><span class="p">:</span>
<span class="n">lListenBool</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">lStr</span> <span class="o">=</span> <span class="n">lOutputLineBytes</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">inCMDEncodingStr</span><span class="p">)</span> <span class="c1"># was cp866, on win server don&#39;t work properly - set cp1251</span>
<span class="k">if</span> <span class="n">lStr</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">):</span> <span class="n">lStr</span> <span class="o">=</span> <span class="n">lStr</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">lMessageStr</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">lOSCMDKeyStr</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">lStr</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">lMessageStr</span><span class="p">)</span>
<span class="k">if</span> <span class="n">inSendOutputToOrchestratorLogsBool</span><span class="p">:</span> <span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="n">lMessageStr</span><span class="p">])</span>
<span class="n">lResultStr</span><span class="o">+=</span><span class="n">lStr</span>
<span class="n">lMessageStr</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">lOSCMDKeyStr</span><span class="si">}</span><span class="s2">: # # # # AGENT CMD Process has been FINISHED # # # # &quot;</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">lMessageStr</span><span class="p">)</span>
<span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="n">lMessageStr</span><span class="p">])</span>
<span class="k">return</span> <span class="n">lResultStr</span>
<span class="c1"># New call</span>
<span class="k">if</span> <span class="n">inRunAsyncBool</span><span class="p">:</span>
<span class="n">lThread</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">_CMDRunAndListenLogs</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;inCMDStr&quot;</span><span class="p">:</span><span class="n">inCMDStr</span><span class="p">,</span> <span class="s2">&quot;inGSettings&quot;</span><span class="p">:</span><span class="n">inGSettings</span><span class="p">,</span> <span class="s2">&quot;inSendOutputToOrchestratorLogsBool&quot;</span><span class="p">:</span><span class="n">inSendOutputToOrchestratorLogsBool</span><span class="p">,</span> <span class="s2">&quot;inCMDEncodingStr&quot;</span><span class="p">:</span><span class="n">inCMDEncodingStr</span> <span class="p">})</span>
<span class="n">lThread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="n">lResultStr</span><span class="o">=</span><span class="s2">&quot;ActivityList has been started in async mode - no output is available here.&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lResultStr</span> <span class="o">=</span> <span class="n">_CMDRunAndListenLogs</span><span class="p">(</span><span class="n">inCMDStr</span><span class="o">=</span><span class="n">inCMDStr</span><span class="p">,</span> <span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inSendOutputToOrchestratorLogsBool</span> <span class="o">=</span> <span class="n">inSendOutputToOrchestratorLogsBool</span><span class="p">,</span> <span class="n">inCMDEncodingStr</span> <span class="o">=</span> <span class="n">inCMDEncodingStr</span><span class="p">)</span>
<span class="c1">#lCMDCode = &quot;cmd /c &quot; + inCMDStr</span>
<span class="c1">#subprocess.Popen(lCMDCode)</span>
<span class="c1">#lResultCMDRun = 1 # os.system(lCMDCode)</span>
<span class="k">return</span> <span class="n">lResultStr</span></div>
<div class="viewcode-block" id="ProcessWOExeUpperUserListGet"><a class="viewcode-back" href="../../../Agent/02_Defs.html#pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet">[docs]</a><span class="k">def</span> <span class="nf">ProcessWOExeUpperUserListGet</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the process list only for the current user (where Agent is running) without .EXE in upper case. Can use in ActivityItem from Orchestrator to Agent</span>
<span class="sd"> :param inProcessNameWOExeList:</span>
<span class="sd"> :return: list of the agent user process in upper case without .EXE. Example [&quot;NOTEPAD&quot;,&quot;...&quot;],</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">lUserNameStr</span> <span class="o">=</span> <span class="n">getpass</span><span class="o">.</span><span class="n">getuser</span><span class="p">()</span>
<span class="n">lResult</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1"># Create updated list for quick check</span>
<span class="n">lProcessNameWOExeList</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1"># Iterate over the list</span>
<span class="k">for</span> <span class="n">proc</span> <span class="ow">in</span> <span class="n">psutil</span><span class="o">.</span><span class="n">process_iter</span><span class="p">():</span>
<span class="k">try</span><span class="p">:</span>
<span class="c1"># Fetch process details as dict</span>
<span class="n">pinfo</span> <span class="o">=</span> <span class="n">proc</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;pid&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="s1">&#39;username&#39;</span><span class="p">])</span>
<span class="c1"># Add if empty inProcessNameWOExeList or if process in inProcessNameWOExeList</span>
<span class="n">lUserNameWODomainStr</span> <span class="o">=</span> <span class="n">proc</span><span class="o">.</span><span class="n">username</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\\</span><span class="s1">&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">if</span> <span class="n">lUserNameWODomainStr</span> <span class="o">==</span> <span class="n">lUserNameStr</span><span class="p">:</span>
<span class="n">lResult</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pinfo</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">][:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span>
<span class="k">except</span> <span class="p">(</span><span class="n">psutil</span><span class="o">.</span><span class="n">NoSuchProcess</span><span class="p">,</span> <span class="n">psutil</span><span class="o">.</span><span class="n">AccessDenied</span><span class="p">,</span> <span class="n">psutil</span><span class="o">.</span><span class="n">ZombieProcess</span><span class="p">):</span>
<span class="k">pass</span>
<span class="k">return</span> <span class="n">lResult</span></div>
<span class="c1"># Main def</span>
<span class="k">def</span> <span class="nf">Agent</span><span class="p">(</span><span class="n">inGSettings</span><span class="p">):</span>
<span class="n">lL</span> <span class="o">=</span> <span class="n">inGSettings</span><span class="p">[</span><span class="s2">&quot;Logger&quot;</span><span class="p">]</span>
<span class="c1"># Append Orchestrator def to ProcessorDictAlias</span>
<span class="n">lModule</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">modules</span><span class="p">[</span><span class="vm">__name__</span><span class="p">]</span>
<span class="n">lModuleDefList</span> <span class="o">=</span> <span class="nb">dir</span><span class="p">(</span><span class="n">lModule</span><span class="p">)</span>
<span class="k">for</span> <span class="n">lItemDefNameStr</span> <span class="ow">in</span> <span class="n">lModuleDefList</span><span class="p">:</span>
<span class="c1"># Dont append alias for defs Agent</span>
<span class="k">if</span> <span class="n">lItemDefNameStr</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Agent&quot;</span><span class="p">]:</span>
<span class="n">lItemDef</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">lModule</span><span class="p">,</span><span class="n">lItemDefNameStr</span><span class="p">)</span>
<span class="k">if</span> <span class="n">callable</span><span class="p">(</span><span class="n">lItemDef</span><span class="p">):</span> <span class="n">inGSettings</span><span class="p">[</span><span class="s2">&quot;ProcessorDict&quot;</span><span class="p">][</span><span class="s2">&quot;AliasDefDict&quot;</span><span class="p">][</span><span class="n">lItemDefNameStr</span><span class="p">]</span><span class="o">=</span><span class="n">lItemDef</span>
<span class="c1"># Detect Machine host name and username</span>
<span class="n">inGSettings</span><span class="p">[</span><span class="s2">&quot;AgentDict&quot;</span><span class="p">][</span><span class="s2">&quot;HostNameUpperStr&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">gethostname</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="n">inGSettings</span><span class="p">[</span><span class="s2">&quot;AgentDict&quot;</span><span class="p">][</span><span class="s2">&quot;UserUpperStr&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">getpass</span><span class="o">.</span><span class="n">getuser</span><span class="p">()</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="c1"># Processor thread</span>
<span class="n">lProcessorThread</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span> <span class="n">Processor</span><span class="o">.</span><span class="n">ProcessorRunSync</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;inGSettings&quot;</span><span class="p">:</span><span class="n">inGSettings</span><span class="p">})</span>
<span class="n">lProcessorThread</span><span class="o">.</span><span class="n">daemon</span> <span class="o">=</span> <span class="kc">True</span> <span class="c1"># Run the thread in daemon mode.</span>
<span class="n">lProcessorThread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span> <span class="c1"># Start the thread execution.</span>
<span class="k">if</span> <span class="n">lL</span><span class="p">:</span> <span class="n">lL</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Processor has been started (ProcessorDict)&quot;</span><span class="p">)</span> <span class="c1">#Logging</span>
<span class="c1"># Start thread to wait data from Orchestrator (O2A)</span>
<span class="n">lO2AThread</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">O2A</span><span class="o">.</span><span class="n">O2A_Loop</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;inGSettings&quot;</span><span class="p">:</span><span class="n">inGSettings</span><span class="p">})</span>
<span class="n">lO2AThread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="c1"># Send log that Agent has been started</span>
<span class="n">A2O</span><span class="o">.</span><span class="n">LogListSend</span><span class="p">(</span><span class="n">inGSettings</span><span class="o">=</span><span class="n">inGSettings</span><span class="p">,</span> <span class="n">inLogList</span><span class="o">=</span><span class="p">[</span><span class="sa">f</span><span class="s1">&#39;Host: </span><span class="si">{</span><span class="n">inGSettings</span><span class="p">[</span><span class="s2">&quot;AgentDict&quot;</span><span class="p">][</span><span class="s2">&quot;HostNameUpperStr&quot;</span><span class="p">]</span><span class="si">}</span><span class="s1">, User: </span><span class="si">{</span><span class="n">inGSettings</span><span class="p">[</span><span class="s2">&quot;AgentDict&quot;</span><span class="p">][</span><span class="s2">&quot;UserUpperStr&quot;</span><span class="p">]</span><span class="si">}</span><span class="s1">, Agent has been started.&#39;</span><span class="p">])</span>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&#169; Copyright 2021, Ivan Maslov.
</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

@ -110,6 +110,10 @@
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -110,6 +110,10 @@
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../Agent/02_Defs.html">2. Defs</a></li>
</ul>

@ -0,0 +1,23 @@
####################################
2. Defs
####################################
**************************************************
pyOpenRPA.Agent.__Agent__
**************************************************
.. automodule:: pyOpenRPA.Agent.__Agent__
:members:
:autosummary:
**********
References
**********
`reStructuredText`_
.. target-notes::
.. _`reStructuredText`: http://docutils.sourceforge.net/rst.html

@ -155,3 +155,10 @@ Guide content
:glob:
Orchestrator/*
.. toctree::
:maxdepth: 3
:caption: AGENT
:glob:
Agent/*

@ -110,6 +110,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>
@ -238,6 +242,8 @@
module
<ul>
<li><a href="Agent/02_Defs.html#module-pyOpenRPA.Agent.__Agent__">pyOpenRPA.Agent.__Agent__</a>
</li>
<li><a href="Orchestrator/02_Defs.html#module-pyOpenRPA.Orchestrator.__Orchestrator__">pyOpenRPA.Orchestrator.__Orchestrator__</a>
</li>
<li><a href="Robot/02_Defs.html#module-pyOpenRPA.Robot.UIDesktop">pyOpenRPA.Robot.UIDesktop</a>
@ -253,11 +259,17 @@
</li>
<li><a href="Orchestrator/02_Defs.html#pyOpenRPA.Orchestrator.__Orchestrator__.OrchestratorSessionSave">OrchestratorSessionSave() (in module pyOpenRPA.Orchestrator.__Orchestrator__)</a>
</li>
<li><a href="Agent/02_Defs.html#pyOpenRPA.Agent.__Agent__.OSCMD">OSCMD() (in module pyOpenRPA.Agent.__Agent__)</a>
<ul>
<li><a href="Orchestrator/02_Defs.html#pyOpenRPA.Orchestrator.__Orchestrator__.OSCMD">(in module pyOpenRPA.Orchestrator.__Orchestrator__)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="Orchestrator/02_Defs.html#pyOpenRPA.Orchestrator.__Orchestrator__.OSCMD">OSCMD() (in module pyOpenRPA.Orchestrator.__Orchestrator__)</a>
</li>
<li><a href="Orchestrator/02_Defs.html#pyOpenRPA.Orchestrator.__Orchestrator__.OSCredentialsVerify">OSCredentialsVerify() (in module pyOpenRPA.Orchestrator.__Orchestrator__)</a>
</li>
<li><a href="Agent/02_Defs.html#pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate">OSFileBinaryDataBase64StrCreate() (in module pyOpenRPA.Agent.__Agent__)</a>
</li>
</ul></td>
</tr></table>
@ -279,15 +291,24 @@
</li>
<li><a href="Orchestrator/02_Defs.html#pyOpenRPA.Orchestrator.__Orchestrator__.ProcessStart">ProcessStart() (in module pyOpenRPA.Orchestrator.__Orchestrator__)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="Orchestrator/02_Defs.html#pyOpenRPA.Orchestrator.__Orchestrator__.ProcessStop">ProcessStop() (in module pyOpenRPA.Orchestrator.__Orchestrator__)</a>
</li>
<li><a href="Agent/02_Defs.html#pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet">ProcessWOExeUpperUserListGet() (in module pyOpenRPA.Agent.__Agent__)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="Robot/02_Defs.html#pyOpenRPA.Robot.UIDesktop.PWASpecification_Get_PWAApplication">PWASpecification_Get_PWAApplication() (in module pyOpenRPA.Robot.UIDesktop)</a>
</li>
<li><a href="Robot/02_Defs.html#pyOpenRPA.Robot.UIDesktop.PWASpecification_Get_UIO">PWASpecification_Get_UIO() (in module pyOpenRPA.Robot.UIDesktop)</a>
</li>
<li>
pyOpenRPA.Agent.__Agent__
<ul>
<li><a href="Agent/02_Defs.html#module-pyOpenRPA.Agent.__Agent__">module</a>
</li>
</ul></li>
<li>
pyOpenRPA.Orchestrator.__Orchestrator__
<ul>

@ -111,6 +111,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>
@ -371,6 +375,16 @@ At the time of this writing the pyOpenRPA is successfully using in several big R
</li>
</ul>
</div>
<div class="toctree-wrapper compound">
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Agent/02_Defs.html#module-pyOpenRPA.Agent.__Agent__">pyOpenRPA.Agent.__Agent__</a></li>
<li class="toctree-l2"><a class="reference internal" href="Agent/02_Defs.html#references">References</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>

Binary file not shown.

@ -113,6 +113,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>
@ -192,6 +196,11 @@
<td>
<code class="xref">pyOpenRPA</code></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;
<a href="Agent/02_Defs.html#module-pyOpenRPA.Agent.__Agent__"><code class="xref">pyOpenRPA.Agent.__Agent__</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&#160;&#160;&#160;

@ -113,6 +113,10 @@
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/04_HowToUse.html">4. How to use</a></li>
<li class="toctree-l1"><a class="reference internal" href="Orchestrator/05_UAC.html">5. UAC - User Access Control</a></li>
</ul>
<p class="caption"><span class="caption-text">AGENT</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Agent/02_Defs.html">2. Defs</a></li>
</ul>

File diff suppressed because one or more lines are too long

@ -0,0 +1,72 @@
# 2. Defs
## pyOpenRPA.Agent.__Agent__
**Functions:**
| `OSCMD`(inCMDStr[, inRunAsyncBool, …])
| Execute CMD on the Agent daemonic process
|
| `OSFileBinaryDataBase64StrCreate`(…[, …])
| Create binary file by the base64 string (safe for JSON transmition)
|
| `ProcessWOExeUpperUserListGet`()
| Return the process list only for the current user (where Agent is running) without .EXE in upper case.
|
### pyOpenRPA.Agent.__Agent__.OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings=None, inSendOutputToOrchestratorLogsBool=True, inCMDEncodingStr='cp1251')
Execute CMD on the Agent daemonic process
* **Parameters**
* **inCMDStr** command to execute on the Agent session
* **inRunAsyncBool** True - Agent processor dont wait execution; False - Agent processor wait cmd execution
* **inGSettings** Agent global settings dict
* **inSendOutputToOrchestratorLogsBool** True - catch cmd execution output and send it to the Orchestrator logs; Flase - else case; Default True
* **inCMDEncodingStr** Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is “cp1251” early was “cp866” - need test
* **Returns**
### pyOpenRPA.Agent.__Agent__.OSFileBinaryDataBase64StrCreate(inFilePathStr, inFileDataBase64Str, inGSettings=None)
Create binary file by the base64 string (safe for JSON transmition)
### pyOpenRPA.Agent.__Agent__.ProcessWOExeUpperUserListGet()
Return the process list only for the current user (where Agent is running) without .EXE in upper case. Can use in ActivityItem from Orchestrator to Agent
* **Parameters**
**inProcessNameWOExeList**
* **Returns**
list of the agent user process in upper case without .EXE. Example [“NOTEPAD”,”…”],
## References
[reStructuredText](http://docutils.sourceforge.net/rst.html)

@ -328,3 +328,13 @@ In wiki you can use the following docs:
* UAC Dict for Orchestrator WEB UI rights
* 2. Defs
* pyOpenRPA.Agent.__Agent__
* References

Loading…
Cancel
Save