Add New def in Agent to list all process in user Update Guidedev-linux
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
|
@ -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__ — 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 & 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> »</li>
|
||||||
|
|
||||||
|
<li><a href="../../index.html">Module code</a> »</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">""" Create binary file by the base64 string (safe for JSON transmition)"""</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">"wb"</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">"Logger"</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">"AGENT Binary file </span><span class="si">{</span><span class="n">inFilePathStr</span><span class="si">}</span><span class="s2"> has been created."</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">"utf-8"</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">"w"</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">"Logger"</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">"AGENT Text file </span><span class="si">{</span><span class="n">inFilePathStr</span><span class="si">}</span><span class="s2"> has been created."</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">"cp1251"</span><span class="p">):</span>
|
||||||
|
<span class="sd">"""</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'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 "cp1251" early was "cp866" - need test</span>
|
||||||
|
<span class="sd"> :return:</span>
|
||||||
|
<span class="sd"> """</span>
|
||||||
|
<span class="n">lResultStr</span> <span class="o">=</span> <span class="s2">""</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">"Logger"</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">""</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">'cmd /c </span><span class="si">{</span><span class="n">inCMDStr</span><span class="si">}</span><span class="s1">'</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">"</span><span class="si">{</span><span class="n">lOSCMDKeyStr</span><span class="si">}</span><span class="s2">: # # # # AGENT CMD Process has been STARTED # # # # "</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">"</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">"</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">""</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'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">"</span><span class="se">\n</span><span class="s2">"</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">"</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">"</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">"</span><span class="si">{</span><span class="n">lOSCMDKeyStr</span><span class="si">}</span><span class="s2">: # # # # AGENT CMD Process has been FINISHED # # # # "</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">"inCMDStr"</span><span class="p">:</span><span class="n">inCMDStr</span><span class="p">,</span> <span class="s2">"inGSettings"</span><span class="p">:</span><span class="n">inGSettings</span><span class="p">,</span> <span class="s2">"inSendOutputToOrchestratorLogsBool"</span><span class="p">:</span><span class="n">inSendOutputToOrchestratorLogsBool</span><span class="p">,</span> <span class="s2">"inCMDEncodingStr"</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">"ActivityList has been started in async mode - no output is available here."</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 = "cmd /c " + 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">"""</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 ["NOTEPAD","..."],</span>
|
||||||
|
|
||||||
|
<span class="sd"> """</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">'pid'</span><span class="p">,</span> <span class="s1">'name'</span><span class="p">,</span> <span class="s1">'username'</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">'</span><span class="se">\\</span><span class="s1">'</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">'name'</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">"Logger"</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">"Agent"</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">"ProcessorDict"</span><span class="p">][</span><span class="s2">"AliasDefDict"</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">"AgentDict"</span><span class="p">][</span><span class="s2">"HostNameUpperStr"</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">"AgentDict"</span><span class="p">][</span><span class="s2">"UserUpperStr"</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">"inGSettings"</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">"Processor has been started (ProcessorDict)"</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">"inGSettings"</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">'Host: </span><span class="si">{</span><span class="n">inGSettings</span><span class="p">[</span><span class="s2">"AgentDict"</span><span class="p">][</span><span class="s2">"HostNameUpperStr"</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">"AgentDict"</span><span class="p">][</span><span class="s2">"UserUpperStr"</span><span class="p">]</span><span class="si">}</span><span class="s1">, Agent has been started.'</span><span class="p">])</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
<div role="contentinfo">
|
||||||
|
<p>
|
||||||
|
© 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>
|
@ -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
|
Binary file not shown.
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue