Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 support #58

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Python3 support #58

wants to merge 11 commits into from

Conversation

schuellerf
Copy link
Contributor

Hi

On my setup this fixes ldtp to work with python3
I only tested in the context of my xfce-test project: https://github.com/schuellerf/xfce-test

@Werni2A
Copy link

Werni2A commented Jun 9, 2020

In setup.py the version string is changed from "3.5.1" to "3.4.1". Is this change intentional? This could explain the discussion in #54

@schuellerf
Copy link
Contributor Author

@Werni2A changing the version number was kind of intentional to mark that the API changed to work with my python 3 setup.
I have no clue why I set it to 3.4.1 - I wanted to "update" the minor version ...
I set it now to 3.6.0 although I'm not familiar with the LDTP2 release process and this is also not ment to be be a proper release. Just a note that this branch is not fully API compatible.

def launchapp(cmd, args = [], delay = 0, env = 1, lang = "C"):
return _remote_launchapp(cmd, args, delay, env, lang)
def launchapp(cmd, args = [], delay = 0, env = 1, lang = "C", logfiles = None ):
return _remote_launchapp(cmd, args, delay, env, lang, logfiles)
def hasstate(window_name, object_name, state, guiTimeOut = 0):
return _remote_hasstate(window_name, object_name, state, guiTimeOut)
def selectrow(window_name, object_name, row_text):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 449, there is a unicode() call that should be converted to str() for python3

implemented as suggested by @ikawada
(looks good - couldn't test myself)
@linuxqiao
Copy link

hi @schuellerf I test your patch, I find another 2 issue in python3:
1,

$ python ldtp-interface.py 
/usr/lib/python3.9/site-packages/gi/overrides/Gtk.py:1649: Warning: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
  return _Gtk_main(*args, **kwargs)
Traceback (most recent call last):
  File "/home/test/ldtp-interface.py", line 6, in <module>
    from ooldtp import *
  File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ooldtp/__init__.py", line 33, in <module>
    import thread
ModuleNotFoundError: No module named 'thread'

2,

$ python ldtp-interface.py 
/usr/lib/python3.9/site-packages/gi/overrides/Gtk.py:1649: Warning: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
  return _Gtk_main(*args, **kwargs)
Traceback (most recent call last):
  File "/home/test/ldtp-interface.py", line 6, in <module>
    from ooldtp import *
  File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ooldtp/__init__.py", line 40, in <module>
    import xmlrpclib
ModuleNotFoundError: No module named 'xmlrpclib'

After this patch, my test script works:

$ git diff
diff --git a/ooldtp/__init__.py b/ooldtp/__init__.py
index 75eedbf..13d0802 100644
--- a/ooldtp/__init__.py
+++ b/ooldtp/__init__.py
@@ -30,14 +30,14 @@ import types
 import atexit
 import signal
 import socket
-import thread
+import _thread
 import logging
 import datetime
 import platform
 import tempfile
 import warnings
 import traceback
-import xmlrpclib
+import xmlrpc.client as xmlrpclib
 import subprocess
 from log import logger
 from base64 import b64decode

1 similar comment
@linuxqiao
Copy link

hi @schuellerf I test your patch, I find another 2 issue in python3:
1,

$ python ldtp-interface.py 
/usr/lib/python3.9/site-packages/gi/overrides/Gtk.py:1649: Warning: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
  return _Gtk_main(*args, **kwargs)
Traceback (most recent call last):
  File "/home/test/ldtp-interface.py", line 6, in <module>
    from ooldtp import *
  File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ooldtp/__init__.py", line 33, in <module>
    import thread
ModuleNotFoundError: No module named 'thread'

2,

$ python ldtp-interface.py 
/usr/lib/python3.9/site-packages/gi/overrides/Gtk.py:1649: Warning: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
  return _Gtk_main(*args, **kwargs)
Traceback (most recent call last):
  File "/home/test/ldtp-interface.py", line 6, in <module>
    from ooldtp import *
  File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ooldtp/__init__.py", line 40, in <module>
    import xmlrpclib
ModuleNotFoundError: No module named 'xmlrpclib'

After this patch, my test script works:

$ git diff
diff --git a/ooldtp/__init__.py b/ooldtp/__init__.py
index 75eedbf..13d0802 100644
--- a/ooldtp/__init__.py
+++ b/ooldtp/__init__.py
@@ -30,14 +30,14 @@ import types
 import atexit
 import signal
 import socket
-import thread
+import _thread
 import logging
 import datetime
 import platform
 import tempfile
 import warnings
 import traceback
-import xmlrpclib
+import xmlrpc.client as xmlrpclib
 import subprocess
 from log import logger
 from base64 import b64decode

@nfelt14
Copy link
Contributor

nfelt14 commented Mar 30, 2021

@nagappan, when could this be merged? Currently python 3 is not supported by ldtp.

@nfelt14
Copy link
Contributor

nfelt14 commented Apr 22, 2021

@nagappan, any updates on this?

@BigIan1969
Copy link

Having no luck getting this working with python 3.8.10

get the following whenever I try to import ldtp

Traceback (most recent call last):
File "LinuxDesktopFileSelection.py", line 20, in
from ldtp import *
File "/usr/local/lib/python3.8/dist-packages/ldtp-3.6.0-py3.8.egg/ldtp/init.py", line 594, in
_populateNamespace(globals())
File "/usr/local/lib/python3.8/dist-packages/ldtp-3.6.0-py3.8.egg/ldtp/init.py", line 247, in _populateNamespace
for method in client._client.system.listMethods():
File "/usr/lib/python3.8/xmlrpc/client.py", line 1109, in call
return self.__send(self.__name, args)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1450, in __request
response = self.__transport.request(
File "/usr/local/lib/python3.8/dist-packages/ldtp-3.6.0-py3.8.egg/ldtp/client.py", line 156, in request
h=self.send_request(host, handler, request_body, bool(verbose))
File "/usr/lib/python3.8/xmlrpc/client.py", line 1278, in send_request
self.send_content(connection, request_body)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1308, in send_content
connection.endheaders(request_body)
File "/usr/lib/python3.8/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1007, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 947, in send
self.connect()
File "/usr/lib/python3.8/http/client.py", line 918, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Apologies if this is an LDTP noob issue

@jdhicks121350
Copy link

I was able to get the current code - apply all the fixes described in this thread - and then I was able to run a simple test. I am working on an Ubuntu 20.04 image on a Windows-10 Hyper-V VM on a small laptop. I used VS Code and Python 3.8.10. I have never contributed to anything on GitHub - if you want the code I have running, how do we/I proceed? There are some original changes that I made but most of it is the changes made by scheullerf and ikawada-zz

@schuellerf
Copy link
Contributor Author

@jdhicks121350 usually you just fork the repository into your GitHub account, commit/push your changes there and finally also create a pullrequest to the original project or mine (or both 😅) that does not really matter in the end (thanks to git 😉)

@pchowdam
Copy link

pchowdam commented Jul 6, 2022

When I use this branch on RHEL 9 with Python 3.9, LDTP daemon is not starting when I import ldtp in Python prompt / script.
Following error is generated, client is unable to connect to server.

Command ldtp is working fine on Terminal, issue is only with Python import.

>>> from ldtp import * Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ldtp/__init__.py", line 594, in <module> _populateNamespace(globals()) File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ldtp/__init__.py", line 247, in _populateNamespace for method in client._client.system.listMethods(): File "/usr/lib64/python3.9/xmlrpc/client.py", line 1122, in __call__ return self.__send(self.__name, args) File "/usr/lib64/python3.9/xmlrpc/client.py", line 1464, in __request response = self.__transport.request( File "/usr/local/lib/python3.9/site-packages/ldtp-3.6.0-py3.9.egg/ldtp/client.py", line 156, in request h=self.send_request(host, handler, request_body, bool(verbose)) File "/usr/lib64/python3.9/xmlrpc/client.py", line 1291, in send_request self.send_content(connection, request_body) File "/usr/lib64/python3.9/xmlrpc/client.py", line 1321, in send_content connection.endheaders(request_body) File "/usr/lib64/python3.9/http/client.py", line 1280, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib64/python3.9/http/client.py", line 1040, in _send_output self.send(msg) File "/usr/lib64/python3.9/http/client.py", line 980, in send self.connect() File "/usr/lib64/python3.9/http/client.py", line 946, in connect self.sock = self._create_connection( File "/usr/lib64/python3.9/socket.py", line 844, in create_connection raise err File "/usr/lib64/python3.9/socket.py", line 832, in create_connection sock.connect(sa) OSError: [Errno 99] Cannot assign requested address

Didn't observe this issue with python2 version. Could you let us know what might be the issue ?

@jdhicks121350
Copy link

I'm having the exact problem since I moved from Ubuntu to openSUSE. I am now confused and have been trying to do exactly what you describe. I'm truing to run ldtp -s from a terminal and also using from ldtp import * and none of the examples are now working for me at all. That is why I have not submitted my code - fearing I have created a bug. On my Ubuntu box I was easily able to manipulate the Calculator APP. On openSUSE I cant get past the first "from ldtp import *" that one line just hangs like it started another process!

@jdhicks121350
Copy link

Also - I have tried 3.7.12, 3.8.7, 3.9.10 and 2 different versions of SUSE - nothing has made any difference. 10 days or more now...

@jdhicks121350
Copy link

jdhicks121350 commented Jul 7, 2022 via email

@pchowdam
Copy link

pchowdam commented Jul 7, 2022

No, there is port reservation.
LDTP Engine uses that port but that engine is not started when we import in python prompt.
So LDTP client is unable to open socket to server ( server is not started ).
Checking for some more insights.

@jdhicks121350
Copy link

jdhicks121350 commented Jul 7, 2022 via email

@jdhicks121350
Copy link

jdhicks121350 commented Jul 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants