Conversion error in converting Redhawk device from 1.8.4 to 1.9 - redhawksdr

I am using Redhawk 1.9. I have created a Redhawk Device from the 1.8.4 IDE.
1.8.4 Redhawk Device (created with all default settings)
C++ implementation
Import existing project into 1.9 IDE
I read the Redhawk 1.9 Release notes on how to convert between 1.8.4 and 1.9 projects
*http://redhawksdr.github.io/Documentation/Release_Notes_1.9.0.pdf*
I import the default 1.8.4 device into the 1.9 IDE. I am able to run and build the 1.8.4 device in the 1.9 IDE. When I try to regenerate the code for 1.8.4 device, the IDE ask me if I want to upgrade to 1.9. The popup says "ConversionTestDevice uses deprecated code generators. Would you like to upgrade this project?". I decided to do an upgrade. I then get the following error message:
/usr/local/redhawk/core/bin/update_project returned with error code 1
Traceback (most recent call last):
File "/usr/local/redhawk/core/bin/update_project", line 222, in ?
if check_bulkio_input(compCpp):
File "/usr/local/redhawk/core/bin/update_project", line 105, in check_bulkio_input
for line in strip_comments(open(filename, 'r')):
File "/usr/local/redhawk/core/bin/update_project", line 86, in strip_comments
ch += safe_next(chars)
File "/usr/local/redhawk/core/bin/update_project", line 56, in safe_next
return next(item)
NameError: global name 'next' is not defined
I would appreciate suggestions on how to convert 1.8.4 device to 1.9 device.

Based on your error message "NameError: global name 'next' is not defined" and the contents of the 1.9.0 release of update_project python script, I am assuming that you are running a version of python less than 2.6. The next function is a python builtin that was introduced in Python 2.6 (http://docs.python.org/2/library/functions.html#next). This is a known bug in the upgrade script as it should be compatible with Python 2.4 as well as Python 2.6 (The default python installations in CentOS 5 and 6 respectively). To fix this, you may modify the update_project script located in $OSSIEHOME/bin/update_project and define the following function:
if not hasattr(__builtins__, 'next'):
# Python 2.4 does not have a free-standing next() function
def next(iterator, default):
"""
Backwards compatibility next() equivalent for Python 2.4.
"""
try:
return iterator.next()
except StopIteration:
return default
You should then remove the previously defined "safe_next" function.
Lastly, you need to replace the two calls to "safe_next" with a call to the newly implement next function and add a second argument of empty string ''
For clarity, a diff of update_project with these changes is below:
## -46,16 +46,16 ## Options:
_bulkio_re = re.compile('BULKIO_data[A-Za-z]+_In_i')
-def safe_next(item):
- """
- Returns the next value of the iterator, or an empty string if the end of
- iteration has been reached. Allows string processing to gracefully handle
- the end of a line without explicit catch statements.
- """
- try:
- return next(item)
- except StopIteration:
- return ''
+if not hasattr(__builtins__, 'next'):
+ # Python 2.4 does not have a free-standing next() function
+ def next(iterator, default):
+ """
+ Backwards compatibility next() equivalent for Python 2.4.
+ """
+ try:
+ return iterator.next()
+ except StopIteration:
+ return default
def strip_comments(source):
"""
## -75,7 +75,7 ## def strip_comments(source):
# Look for end comment token; if the end of the line is reached
# ch will be an empty string
while ch == '*':
- ch = safe_next(chars)
+ ch = next(chars, '')
if ch == '/':
inComment = False
break
## -83,7 +83,7 ## def strip_comments(source):
if ch == '/':
# Read the next character to see if it matches a comment token
# (if it does not, both characters will be added to the output)
- ch += safe_next(chars)
+ ch += next(chars, '')
if ch == '/*':
# Comment, start discarding
inComment = True

Related

Error about Selenium version using Python's webbot

I'm using Python 3.9 on macOS. I'm trying to start using webbot, but every time I try, I get this error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
exception: Missing or invalid capabilities
(Driver info: chromedriver=2.39.562713
(dd642283e958a93ebf6891600db055f1f1b4f3b2),platform=Mac OS X 10.14.6 x86_64)
I'm using macOS version 10.4 because I use 32 bit software. The part that really puzzles me is why is says chromedriver=2.39.562713. According to the pip, the driver's version is 103.0.5060.53. If I import selenium and try the command help(selenium), towards the end of the output, I get:
VERSION
4.3.0
Where does this lower version come from? I'm pretty sure that's why I have "missing or invalid capabilities." If I start selenium with:
from selenium import webdriver
driver = webdriver.Chrome()
It starts Chrome as expected. Obviously I'm missing something.
I used to start webbot with:
from webbot import Browser
driver = Browser()
But then, just to be sure, I changed it to:
from webbot import Browser
driver = Browser(True, None, '/usr/local/bin/')
'/usr/local/bin/' being the location of a chrome webdriver installed by brew that is explicitly version 103. No difference.
Solution
The approved response was not the solution, but it led me to the solution.
My version of webbot is the latest, but it has a very different __init__ method:
def __init__(self, showWindow=True, proxy=None , downloadPath:str=None):
Upon further inspection, I saw that the driverPath attribute (that I had tried to use earlier) was completely gone by design. So I decided to print the value of the inner variable driverpath inside the __init__ method. This returned the following:
project_root/virtualenvironment/lib/python3.9/site-packages/webbot/drivers/chrome_mac
There was my guilty party! I renamed that executable and in its place put a symbolic link to the correct binary. That worked.
driver = Browser(True, None, '/usr/local/bin/')
actually sets the downloadPath, not the driverPath. Use the parameter name explicitly
driver = Browser(driverPath='/usr/local/bin/')
From webbot.py
class Browser:
def __init__(self, showWindow=True, proxy=None , downloadPath:str=None, driverPath:str=None, arguments=["--disable-dev-shm-usage","--no-sandbox"]):
if driverPath is not None and isinstance(driverPath,str):
driverPath = os.path.abspath(driverPath)
if(not os.path.isdir(driverPath)):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), driverPath)
if driverPath is None:
driverfilename = ''
if sys.platform == 'linux' or sys.platform == 'linux2':
driverfilename = 'chrome_linux'
elif sys.platform == 'win32':
driverfilename = 'chrome_windows.exe'
elif sys.platform == 'darwin':
driverfilename = 'chrome_mac'
driverPath = os.path.join(os.path.split(__file__)[0], 'drivers{0}{1}'.format(os.path.sep, driverfilename))
self.driver = webdriver.Chrome(executable_path=driverPath, options=options)
If driverPath is None it will set to
/{parent_folder_abs_path}/drivers/chrome_mac or /{parent_folder_abs_path}/drivers/, I'm guessing you have an older chromedriver version there.

Python fdpexpect with multiple expects

Testing the simple example that should execute the external application and catch both inputs there.
# external_application.py
print('First_line:')
x = input()
print('Second_line:')
y = input()
print(f'Done: {x} and {y}')
And the runner:
# runner.py
import subprocess
import pexpect.fdpexpect
p = subprocess.Popen(("python", "external_application.py"), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
session = pexpect.fdpexpect.fdspawn(p.stdout.fileno())
session.expect("First_line:")
p.stdin.write(b'1')
print('first_done')
session.expect("Second_line:")
p.stdin.write(b'2')
print('second_done')
p.stdin.close()
print(f'Result: {p.stdout.read()}')
I can see that output of the print('first_done') and then it locks on the second expect. If we remove the second input and a second expect then everything works correctly till the end.
Running on the windows, python 3.7.9, pexpect 4.8.0
Am I missing some timeout or a flush?
When I check the dump, session matches b'First_line:\r\n', but p.stdin.write doesn't move the pexpect cursor forward to look for "Second_line:", as what happens with send() or sendline().
May I suggest a simpler way, using PopenSpawn? The docs state that it "provides an interface like pexpect.spawn interface (sic) using subprocess.Popen":
NOTE - Tested in Windows 11, using Python 3.9.
import pexpect
from pexpect import popen_spawn
session = pexpect.popen_spawn.PopenSpawn("python external_application.py")
session.expect("First_line:")
session.sendline("1")
print("first_done")
session.expect("Second_line:")
session.sendline("2")
print("second_done")
print(session.read().decode("utf-8"))
Output:
first_done
second_done
Done: 1 and 2

decodestrings is not an attribute of base64 error in python 3.9.1

After upgrading from python 3.8.0 to python 3.9.1, the tremc front-end of transmission bitTorrent client is throwing decodestrings is not an attribute of base64 error whenever i click on a torrent entry to check the details.
My system specs:
OS: Arch linux
kernel: 5.6.11-clear-linux
base64.encodestring() and base64.decodestring(), aliases deprecated since Python 3.1, have been removed.
use base64.encodebytes() and base64.decodebytes()
So i went to the site-packages directory and with ripgrep tried searching for the decodestring string.
rg decodestring
paramiko/py3compat.py
39: decodebytes = base64.decodestring
Upon examining the py3compat.py file,i found this block:
PY2 = sys.version_info[0] < 3
if PY2:
string_types = basestring # NOQA
text_type = unicode # NOQA
bytes_types = str
bytes = str
integer_types = (int, long) # NOQA
long = long # NOQA
input = raw_input # NOQA
decodebytes = base64.decodestring
encodebytes = base64.encodestring
So decodebytes have replaced(aliased) decodestring attribute of base64 for python version >= 3
This must be a new addendum because tremc was working fine in uptil version 3.8.*.
Opened tremc script, found the erring line (line 441), just replaced the attribute decodestring with decodebytes.A quick fix till the next update.
PS: Checked the github repository, and there's a pull request for it in waiting.
If you don't want to wait for the next release and also don't want to hack the way i did, you can get it freshly build from the repository, though that would be not much of a difference than my method

Is this python-click behaviour correct?

I am trying to use Pallets Click to make a command line program that takes a list of input parameters and one optional output parameter.
Same behavior on both Ubuntu 18.04 Python 3.6 and Windows 10 Python 3.7 with python-click version 7.0.
I made a test file click_test.py:
import click
#click.command()
#click.argument('src', nargs=-1, required=True)
#click.argument('dst', required=False)
def copy(src, dst):
print(f'{src!r}')
print(f'{dst!r}')
if __name__ == '__main__':
copy()
Running python click_test.py first-argument give this output:
Usage: click_test.py [OPTIONS] SRC... [DST]
Try "click_test.py --help" for help.
Error: Missing argument "SRC...".
The usage description describes what I am expecting. SRC is required, but DST is optional. But still, the error message says missing SRC.
It this correct behavior, or is this a bug?
Your desired command line is a bit ambiguous. How would click know when a src was a src or the last dst? So with the nargs=-1 the parser defers the value from src to dst.
However, the expectation in your question, can be achieved with a bit of re-plumbing in the form of a custom click.Argument class.
Custom Class:
def take_empty_from(other_param_name):
class EmptyFrom(click.Argument):
def consume_value(self, ctx, opts):
value = opts.get(self.name)
if value == () and opts.get(other_param_name):
value = opts[self.name] = (opts.get(other_param_name), )
opts[other_param_name] = None
return value
else:
return super(EmptyFrom, self).consume_value(ctx, opts)
return EmptyFrom
Using the Custom Class:
#click.command()
#click.argument('src', nargs=-1, required=True, cls=take_empty_from('dst'))
#click.argument('dst', required=False)
def copy(src, dst):
How does this work?
This works because click is a well designed OO framework. The #click.argument() decorator usually instantiates a click.Argument object but allows this behavior to be over ridden with the cls parameter. So it is a relatively easy matter to inherit from click.Argument in our own class and over ride desired methods.
In this case, we override click.Argument.consume_value() and then in the case of only one parameter grab the argument from dst and put it into src.
Note: that while this behavior meets the request in the question, it still leaves unanswered why src is only un-needed when there is a single dst parameter.
Test Code:
import click
#click.command()
#click.argument('src', nargs=-1, required=True, cls=take_empty_from('dst'))
#click.argument('dst', required=False)
def copy(src, dst):
click.echo('src: {}'.format(src))
click.echo('dst: {}'.format(dst))
if __name__ == "__main__":
commands = (
'',
'a',
'a b',
'a b c',
'--help',
)
import sys, time
time.sleep(1)
print('Click Version: {}'.format(click.__version__))
print('Python Version: {}'.format(sys.version))
for cmd in commands:
try:
time.sleep(0.1)
print('-----------')
print('> ' + cmd)
time.sleep(0.1)
copy(cmd.split())
except BaseException as exc:
if str(exc) != '0' and \
not isinstance(exc, (click.ClickException, SystemExit)):
raise
Results:
Click Version: 6.7
Python Version: 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
-----------
>
Usage: click_prog.py [OPTIONS] SRC... [DST]
Error: Missing argument "src".
-----------
> a
src: ('a',)
dst: None
-----------
> a b
src: ('a',)
dst: b
-----------
> a b c
src: ('a', 'b')
dst: c
-----------
> --help
Usage: click_prog.py [OPTIONS] SRC... [DST]
Options:
--help Show this message and exit.

Linecache getline does not work after my application was installed

I am creating a tool that gives an overview of hundredths of test results. This tool access a log file, checks for Pass and Fail verdicts. When it is a fail, I need to go back to previous lines of the log to capture the cause of failure.
The linecache.getline works in my workspace (Python Run via eclipse). But after I created a windows installer (.exe file) and installed the application in my computer, the linecache.getline returns nothing. Is there something I need to add into my setup.py file to fix this or is it my code issue?
Tool Code
precon:
from wx.FileDialog, access the log file
self.result_path = dlg.GetPath()
try:
with open(self.result_path, 'r') as file:
self.checkLog(self.result_path, file)
def checkLog(self, path, f):
line_no = 1
index = 0
for line in f:
n = re.search("FAIL", line, re.IGNORECASE) or re.search("PASS", line, re.IGNORECASE)
if n:
currentline = re.sub('\s+', ' ', line.rstrip())
finalresult = currentline
self.list_ctrl.InsertStringItem(index, finaltestname)
self.list_ctrl.SetStringItem(index, 1, finalresult)
if currentline == "FAIL":
fail_line1 = linecache.getline(path, int(line_no - 3)) #Get reason of failure
fail_line2 = linecache.getline(path, int(line_no - 2)) #Get reason of failure
cause = fail_line1.strip() + " " + fail_line2.strip()
self.list_ctrl.SetStringItem(index, 2, cause)
index += 1
line_no += 1
The issue was resolved by doing the get_line function from this link:
Python: linecache not working as expected?

Resources