return information using pexpect - pexpect

I am learning how to use pexpect and i had a question. I am trying to find the version number of a remote server and based on that version number I want to choose the right driver number. I am not entirely sure how should I go about doing this. Something along the lines of a getline function. Let me know if there are any functions I could use

The child .before and .after properties contain the stdout before resp. after the matched expectation.
import pexpect
child = pexpect.spawn('cat /etc/issue')
child.expect('Ubuntu.*')
print(child.after)
Which of the commands requires input? If it is the driver installation you could use fabric & fexpect:
from ilogue.fexpect import expect, expecting, run
output = run('get-system-version')
prompts = []
prompts += expect('Which driver version do you want to install?',output)
with expecting(prompts):
run('install-driver-command')

Related

Is there any way to batch export TLS States with additional files?

From https://sumo.dlr.de/docs/Simulation/Output/Traffic_Lights.html#tls_states , I know that I can use command <timedEvent type="SaveTLSStates" source="<TLS_ID>" dest="<OUTPUT_FILE>"/> in additional file to output the state of the traffic light, whose ID is "TLS_ID" defined in .net.xml file. However I wonder that if I use this way to output the TLS, do I have to enter this command for each ID of the traffic light? Is there a statement that can output the state of all traffic light defined in .net.xml?
No, but you can write a small python script to achieve that:
import sumolib
net = sumolib.net.readNet("net.net.xml")
states_xml = sumolib.xml.create_document("additional")
for tls in net.getTrafficLights():
event = states_xml.addChild("timedEvent")
event.setAttribute("type", "SaveTLSStates")
event.setAttribute("source", tls.getID())
event.setAttribute("dest", "states.xml")
with open("output.add.xml", 'w') as out:
out.write(states_xml.toXML())
Please be aware that I did not test the code above.

Is there a way to set a default cooldown for commands in discord.py

So I need all of my commands to have a two second cooldown, is there a way to set a default cooldown for all of them (as opposed to individually adding it using decorators)? If so, are you also able to change other specific commands to separate cooldowns in addition? Thanks for your help!
discord.py has a decorator for cooldowns.
from discord.ext.commands.cooldowns import BucketType
#commands.cooldown(rate,per,BucketType)
*A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns can be based either on a per-guild, per-channel, per-user, per-role or global basis. Denoted by the third argument of type which must be of enum type BucketType.
If a cooldown is triggered, then CommandOnCooldown is triggered in on_command_error() and the local error handler.
A command can only have a single cooldown.*
Ok so after looking at the discord module I found a really simple solution to give each command a cooldown, it can very easily be modified to give different cooldowns for different commands and just automate cooldowns instead of using the decorator
default_cooldown = commands.Cooldown(1, 2, commands.BucketType.user)
for command in self.bot.commands:
command._buckets._cooldown = default_cooldown

Python script for Pymol with user input

I have prepared a script for Pymol that works well in evaluating RMSD values for a list of residues of proteins of interest (targetted residues are generated by script embedded commands). However, I wished to implement the script to allow the user to select the analysed residues. I have tried to use the input function, but it fails to work. Since the code is a bit long, I simplified progressively the scripts. In that way, I ended up with the following two scripts:
"test.py":
import Bio.PDB
import numpy as np
from pymol import cmd
import os,glob
from LFGA_functions import user_entered
List_tot = user_entered()
print (List_tot)
which calls the simple "user_entered" function from inside the "My_function.py" script:
def user_entered():
List_res = []
List_tot = []
a = input("Please indicate the number of residues to analyze/per monomer:")
numberRes =int(a)
for i in range(numberRes):
Res = input("Please provide each residue NUMBER and hit ENTER:")
Res1 = int(Res)
Res2 = Res1+2000
Res3 = Res1+3000
Res4 = Res1+4000
Res5 = Res1+5000
Res6 = Res1+6000
List_res = (str(Res1),str(Res2),str(Res3),str(Res4),str(Res5),str(Res6))
List_tot.append(List_res)
return List_tot
The script "test.py" works well when executed by Python (3.7.5, which is installed with Pymol 2.3.4,under Windows 7 Prof) from a windows command line. An example of result:
[first input to indicate that 2 cases will be treated, followed by the identification number for each case][1]
However, when the script is run from Pymol GUI, I get the following error message: input():lost sys.stdin
Does anybody know what is the problem. Obviously, I am a very primitive Python user...
I profit also to ask something related to this problem... in the original script that works well in Pymol, before trying to implement the "input" option, I store transiently some data (residue name, type and chain) in the form of a "set". I need a set, and not a list, because it removes automatically data repeatitions. However, when I try to run it from PYthon (thinking of overcoming the abovementioned problem of input), it stops with a message: name 'close_to_A' not defined. However, it is as shown in the portion of code shown here below, and indeed works in Pymol.
...
# Step 3:
# listing of residues sufficiently close to chainA
# that will be considered in calculation of RMSD during trajectory
cmd.load("%s/%s" %(path3,"Average.pdb"), "Average", quiet=0)
cmd.select("around_A", "Average and chain B+C near_to 5 of chain A")
cmd.select("in_A", "Average and chain A near_to 5 of chain B+C")
close_to_A = set()
cmd.iterate("(around_A)","close_to_A.add((chain,resi,resn))")
cmd.iterate("(in_A)","close_to_A.add((chain,resi,resn))")
cmd.delete("around_A")
cmd.delete("in_A")
...
How shall I define a set in Python 3 ? Why does it work when run from Pymol ?
I would really appreciate if you could help me to solve these two problems. Thank you in advance,
Best regards,
Luis

OpenEdge 10.2A - INPUT THROUGH set does not work after Windows Update 1703 on Windows 10

We were using below code to get the name of the computer.
def new shared var cHost as char format "x(40)" no-undo.
INPUT THROUGH hostname NO-ECHO.
SET cHost.
INPUT CLOSE.
DISPLAY chost.
After we have updated our computers (Windows 10 - 1703), it no longer works. It seems SET cHost is the part where it fails. I have tried IMPORT UNFORMATTED cHost but it does not work.
PS: I can get computer name using OS-GETENV("COMPUTERNAME") but I have to do it using INPUT THROUGH statement.
Edit: It seems that it is not only a problem with 10.2A but a more general one. Also it is not just related to hostname but all console applications and ms-dos commands. Now I will try to replace INPUT THROUGH statement with another Progress command if there is any, or try to communicate with existing console applications with some other method.
The first thing I would do is to verify that the 'hostname' command is still working properly from a command window.
Assuming that it is I would code your snippet something like this:
INPUT THROUGH VALUE( "hostname" ).
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
DISPLAY cHOST format "x(60)".
Which might reveal a more useful error message than "it no longer works".
Since COMPUTERNAME meets your needs but you must use INPUT THROUGH for some very mysterious reason you might also try:
INPUT THROUGH VALUE( "echo %COMPUTERNAME%" ).
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
DISPLAY cHOST format "x(60)".
It seems the problem may not be limited to Openedge version 10. I am running a windows 10 winver 1703 device for development, using Progress/Openedge 8.3 and I am no longer able to execute this.
def var a as char format "x(70)".
input through "echo %cd%" no-echo.
import unformatted a.
input close.
message a. pause.
This runs on a windows server 2012 R2, using progress/openedge 8.3.
Where is no longer works, it just exits from within the program when it hits the import command.
Since it seems as a bug, until someone comes up with a better solution, this is how I will change my codes:
DEF VAR cHost AS CHAR FORMAT "x(40)" NO-UNDO.
OS-CREATE-DIR VALUE("c:\temp").
OS-COMMAND SILENT VALUE("hostname >c:\temp\hostname.txt").
INPUT FROM VALUE("c:\temp\hostname.txt").
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
MESSAGE cHost.
This code can be used for other ms-dos commands and console applications as well.
DEF VAR cHost AS CHAR FORMAT "x(40)" NO-UNDO.
OS-CREATE-DIR VALUE("c:\temp").
OS-COMMAND SILENT VALUE("ECHO %cd% >c:\temp\result.txt").
INPUT FROM VALUE("c:\temp\result.txt").
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
MESSAGE cHost.
Thanks for your help.

How to print right-to-left report on odoo 8

I created a report in odoo 8 using RML, everything is good. but when i print the report, caracteres are printed from left to right. I tried with drawRightString but nothing does appears on the PDF.
I used openerp-rtl module but I noticed no changes.
What can i do to print it in RTL mode.
Generally people working on Right to left text on Arbic Language.
so in this case you just install the below python-bidi package :
https://pypi.python.org/pypi/python-bidi/
python-bidi package is helpful to set the Pure python implementation of the BiDi layout algorithm.
And also add the bidi directory in your OpenERP report dir and use the get_display(string) method for making your sting convert into the arbic formate and also use with the arabic_reshaper class
You can do some thing like
import arabic_reshaper
from bidi.algorithm import get_display
def get_arabic_string(string):
reshaped_text = arabic_reshaper.reshape(string)
bidi_text = get_display(reshaped_text)
return bidi_text
Just need to use the get_arbic_string function in your rml file and set it on rml and pass the sting as arbic formate.
just check another source :
pyfribidi for windows or any other bidi algorithm

Resources