npyscreen toggle option between TUI and CLI - python

I am developing a console application to manage firewall devices from a unix server. The console application is based on npyscreen library of python.
One of the options I need to provide to the users is login to the device CLI from the TUI thats developed using npyscreen.
For this I need to toggle between the TUI and the device CLI once the login has happened to the device from the unix server.
Can anyone (having experience with npyscreen) help me on how this can be done in npyscreen?
The flow here is like :
Select option to login to the device (in TUI)
The TUI executes backend script to login to the device
TUI allows user to see the device console may be by toggling from TUI to the CLI mode
The user does his things on the device in the console mode
User exits the device CLI and is landed back to the TUI again.
Any help will be appreciated.
Regards
Pradeep

The devices are usually unix based having shell prompt just like unix servers or they may have their own toolsets interactive shell.
Got the answer on this thread.
running command line program from npyscreen select option
There is a method in npyscreen called CallSubShell that be used for this purpose .

Related

Is there any way connect to a remote windows server from RHEL and execute a python program that does GUI automation

We have hosted our Jenkins server on an RHEL 7.9. We want to connect to the remote windows server from the RHEL box and execute a python program that uses pywinauto package to manipulate a GUI application that runs on the remote windows server for functional tests. Our python script that uses pywinauto is ready and working fine when executed from cmdline on the remote windows server and want to trigger the script from a Jenkins job. Now, Can someone here please let me know the options I should think of to connect to the Remote windows server from RHEL and execute a python script that does GUI automation?
Holla, I have done this recently from centOS 8, This was quite challenging though. Since pywinauto requires active desktop to perform actions on the UI. For this purpose we can not do SSH or similar ways.
Here is how to...step by step.
You can use to do the RDP connection to the windows server using xFreeRDP from RHEL.
xfreerdp /u:username /p:password /v:hostname
Ref.- FreeRDP
Up to this all works smooth here onwards you can not execute the commands on RDP session to trigger the execution.
But windows server is your savior. It does provide you the EVENTCREATE command which allows you to create event. It will create event on your behalf in your windows server. This command will allow you flexibility for scheduling your job. The events created by this command will be listed in the event-viewer utility of windows. To see the window event created by you, give meaningful message. To create event user should be administrator.
Example -
eventcreate /t INFORMATION /id 1000 /d "Create event in WinMgmt source"
In this step you will have to setup/schedule the job based on event occurred on windows. By right clicking on event and then select option 'Attach task to this event...' or by directly going in to the Task Schedular (another windows utility tool).
a. Open Task Schedular.
b. Right click on root tree node - "Task Schedular Library"
c. Select the option "Create Task..."
d. Popup will open to create Task Fill Name and description of task.
e. Select the checkbox "Run with highest privileges".
f. Go to trigger tab and New button.
g. Select the first dropdown value for "Begin the task" as "On an Event".
i. In the setting section of popup select log type of event.
ii. Source and Event ID values should be similar that you will use in your custom event(step 2 event).
iii. Select other scheduling setting as per your need.
i. Go to Actions tab and click on New button.
j. On the New Action popup, select Action as "Start a program"
k. Select your program (python script) to be executed and parameters if any in setting section.
l. Click OK and test this connection of event and task by firing event from cmd (step 2)
This is almost done now except the one critical part. And that is how to fire eventcreate command from RHEL. You can do that by writing small python code using SSH or paramiko packages.
NOTE's
Opening multiple RDP terminals is possible using XfreeRDP.
Multiple xfreeRDP windows will execute the scripts in parallel without any hassle.

How do built in macros on Emulators work?

I'm building a script to automate some stuff on my Android emulator I'm currently using pyautogui to do it tho it would be nice if there was some sort of way I can directly interact with the emulator without it relying on my mouse
I know there's an option using ADB but that requires the android to be rooted
a lot of android emulators like Nox, Bluestacks, LDplayer have built-in macros that don't require the device to be rooted.
How do these emulators send commands to the emulator is that something I can tap into and send commands through that instead?
Answer: These emulator run on virtual machines their macro is sending input command from the virtual machine input API

How do I set a program to run on startup and how desktop application's login check done

I have a small application built using python and tkinter, and I want that application to run on startup.
Here I have few questions
My question is how do I actually set the app to run at startup.
My application needs to login, but I don't understand how I can connect, application with database without placing database credentials in user's downloaded application.
There are 2 points here:
how to set-up an application to run at start-up?
If what you call startup if the machine startup before any user logs in, then the answer will depend on the OS. You will have rc scripts on Unix (and Unix-like) systems, or services on Windows.
how can an unattented application connect to the database?
A common way is to have the application run under a dedicated login (user name). Then you configure the database to accept passwordless connections from that specific login on that specific machine (ideally the same one). Of course that login should have the less possible privileges...
What platform do you want to do?
On Windows you can set your built (maybe .exe) in Task Scheduler.
press Start logo and Call Task Scheduler
Open it and Create task
and then setup what app do you want to run in Action tab and don't forget to Naming in General tab
On Linux I used to see somepeople follow this step you can follow from this link below :
How to Schedule Tasks on Linux: An Introduction to Crontab Files
Or you can search for Crontab to see how to setup task with Crontab commands

Pass command to KiTTY UI

I wish to automate the below task
Launch KiTTY
Enter username and password
Login successfully
Enter this below command to see the logs
tail -2000f /apps/test/good.log
I am able to achieve up to point 3 using below code
from subprocess import Popen
Popen("powershell kitty-0.73.1.1.exe sakthi#x.y.w.z -pw YYYY")
(new KiTTY windows is opened and user is logged in successfully)
But I don't know how to pass the below command
tail -2000f /apps/test/good.log
Note:
I am using Python3
I WANT THIS AUTOMATION AT UI LEVEL. I have around 5 to 6 log files to go through while testing. I don't want to open all the logs manually. So I am looking for a way to automate it.
I am using KiTTY, because it can re-connect automatically when there is any network problem.
KiTTY, as well as PuTTY, has -m command-line switch to provide a command for SSH "exec" channel.
This is discussed in: Automating command/script execution using PuTTY
KiTTY additionally has -cmd command-line switch, which (contrary to -m) simulates key strokes on SSH "shell" channel. It is an equivalent of KiTTY "Automatic Command" feature.
See also Open command line in C# and send commands PuTTY or KiTTY
Though if you want to automate testing, you better use a native Python SSH module, like Paramiko.

Control rs232 windows terminal program from python

I am testing a piece of hardware which hosts an ftp server. I connect to the server in order to configure the hardware in question.
My test environment is written in Python 3.
To start the ftp server, I need to launch a special proprietary terminal application on my pc. I must use this software as far as I know and I have no help files for it. I do however know how to use it to launch the ftp server and that's all I need it for.
When I start this app, I go to the menu and open a dialog where I select the com port/speed the hardware is connected to. I then enter the command to launch the ftp server in a console like window within the application. I am then prompted for the admin code for the hardware, which I enter. When I'm finished configuring the device, I issue a command to restart the hardware's software.
In order for me to fully automate my tests, I need to remove the manual starting of this ftp server for each test.
As far as I know, I have two options:
Windows GUI automation
Save the stream of data sent on the com port when using this application.
I've tried to find an GUI automater but pywinauto isn't supporting Python 3. Any other options here which I should look at?
Any suggestions on how I can monitor the com port in question and save the traffic on it?
Thanks,
Barry
Have you looked at pySerial? It's been a few years since I've used it but it was quite good at handling RS-232 communications and it looks like it's compatible with Python 3.x.
Sikuli might provide the kind of GUI automation you need.
I was also able to solve this using WScript, but pySerial was the preferred solution.

Categories