Re: pysftp / paramiko problem

2019-06-13 Thread Robin Becker

On 13/06/2019 05:56, dieter wrote:

Robin Becker  writes:

On 12/06/2019 05:59, dieter wrote:

Robin Becker  writes:

I am trying to convert older code that uses ftplib as the endpoint has switched 
to sftp only.

...
Well with real sftp I can cd to that path so if it is a symlink it goes 
somewhere.

With pysftp I am unable to chdir or cd into it. With a bit of
difficulty I can use subprocess + sshpass + sftp to do the required
transfer.


Maybe, the problem is the "u" prefix.
Can you try your script with Python 3 or encode the unicode
into a native ``str``?


no same happens in a fresh python 3.6 environment


$ cat - > tsftp.py
def main():
import pysftp
with pysftp.Connection('ftp.remote.com', username='me', password='ucl20 
11') as sftp:
print('top level')
print(sftp.listdir())
print(sftp.normalize(''))

if __name__ == '__main__':
main()
(tpy3) rptlab@app1:~/tmp/tpy3
$ python tsftp.py
top level
['']
Traceback (most recent call last):
  File "tsftp.py", line 9, in 
main()
  File "tsftp.py", line 6, in main
print(sftp.normalize(''))
  File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/pysftp/__init__.py", 
line 640, in normalize
return self._sftp.normalize(remotepath)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 632, in normalize
t, msg = self._request(CMD_REALPATH, path)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 813, in _request
return self._read_response(num)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 865, in _read_response
self._convert_status(msg)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 894, in _convert_status
raise IOError(errno.ENOENT, text)
FileNotFoundError: [Errno 2] No such file.


this is what real sftp does


(tpy3) rptlab@app1:~/tmp/tpy3
$ sshpass -p ucl2011 sftp m...@ftp.remote.com
Connected to ftp.remote.com.
sftp> cd 
sftp> pwd
Remote working directory: /
sftp> ls
OLD GR 
  Z.pdf
sftp> ^D
(tpy3) rptlab@app1:~/tmp/tpy3




--
Robin Becker

--
https://mail.python.org/mailman/listinfo/python-list


Re: pysftp / paramiko problem

2019-06-13 Thread MRAB

On 2019-06-13 14:57, Robin Becker wrote:

On 13/06/2019 05:56, dieter wrote:

Robin Becker  writes:

On 12/06/2019 05:59, dieter wrote:

Robin Becker  writes:

I am trying to convert older code that uses ftplib as the endpoint has switched 
to sftp only.

...
Well with real sftp I can cd to that path so if it is a symlink it goes 
somewhere.

With pysftp I am unable to chdir or cd into it. With a bit of
difficulty I can use subprocess + sshpass + sftp to do the required
transfer.


Maybe, the problem is the "u" prefix.
Can you try your script with Python 3 or encode the unicode
into a native ``str``?


no same happens in a fresh python 3.6 environment


$ cat - > tsftp.py
def main():
import pysftp
with pysftp.Connection('ftp.remote.com', username='me', password='ucl20 
11') as sftp:
print('top level')
print(sftp.listdir())
print(sftp.normalize(''))

if __name__ == '__main__':
main()
(tpy3) rptlab@app1:~/tmp/tpy3
$ python tsftp.py
top level
['']
Traceback (most recent call last):
  File "tsftp.py", line 9, in 
main()
  File "tsftp.py", line 6, in main
print(sftp.normalize(''))
  File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/pysftp/__init__.py", 
line 640, in normalize
return self._sftp.normalize(remotepath)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 632, in normalize
t, msg = self._request(CMD_REALPATH, path)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 813, in _request
return self._read_response(num)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 865, in _read_response
self._convert_status(msg)
  File 
"/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", 
line 894, in _convert_status
raise IOError(errno.ENOENT, text)
FileNotFoundError: [Errno 2] No such file.


this is what real sftp does


(tpy3) rptlab@app1:~/tmp/tpy3
$ sshpass -p ucl2011 sftp m...@ftp.remote.com
Connected to ftp.remote.com.
sftp> cd 
sftp> pwd
Remote working directory: /
sftp> ls
OLD GR 
  Z.pdf
sftp> ^D
(tpy3) rptlab@app1:~/tmp/tpy3



What does:

sftp.normalize('.')

return?
--
https://mail.python.org/mailman/listinfo/python-list


The trailing comma bites! You have a new tuple.

2019-06-13 Thread Cameron Simpson

Just venting :-(

I've just wasted a surprising amount of time on a simple mistake.

Former code:

 task = IngestTask(...,
 logical_dirpath=join(source_dir, subdir, rpath),
 ...)

During a reworking it became this:

 logical_dirpath = join(
 source_dir,
 subdir,
 rpath
 ),
 task = IngestTask(...,
 logical_dirpath=logical_dirpath,
 ...)

Typing badness ensues. In a subsequent function call far far away.

Grumble,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


How control a GUI for an unrelated application from a Python script?

2019-06-13 Thread Christian Seberino
I have a third party GUI that manages some hardware.

I want to control the hardware from a Python script.

This seems to mean I need to somehow have Python code
  that imitates a human doing the necessary
actions on the GUI (selecting menu options, pressing buttons, etc.)

Is this possible / easy / doable?

Thanks!

Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How control a GUI for an unrelated application from a Python script?

2019-06-13 Thread Chris Angelico
On Fri, Jun 14, 2019 at 9:51 AM Christian Seberino  wrote:
>
> I have a third party GUI that manages some hardware.
>
> I want to control the hardware from a Python script.
>
> This seems to mean I need to somehow have Python code
>   that imitates a human doing the necessary
> actions on the GUI (selecting menu options, pressing buttons, etc.)
>
> Is this possible / easy / doable?
>

Possible? Yes. Easy? Probably not. So I would recommend first seeing
if there's any sort of command-line tool, or command-line invocation
for the GUI tool (some programs will open a GUI if given no arguments,
but you can provide args to make them do stuff straight away).

Once you've exhausted all options of easy automation, yes, you CAN
have a program manipulate a GUI. It's fiddly, though.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How control a GUI for an unrelated application from a Python script?

2019-06-13 Thread Michael Torrie
On 06/13/2019 05:49 PM, Christian Seberino wrote:
> I have a third party GUI that manages some hardware.
> 
> I want to control the hardware from a Python script.
> 
> This seems to mean I need to somehow have Python code
>   that imitates a human doing the necessary
> actions on the GUI (selecting menu options, pressing buttons, etc.)
> 
> Is this possible

Maybe.

> / easy 
No.

> doable?

Maybe.

It's kind of the old "if you have to ask" sort of question.

There are ways of programatically driving other applications' user
interfaces.  You haven't said what OS you are using.  We used to use an
application called AutoIt to drive GUI programs.  You can send clicks,
keystrokes, and work with certain controls (read values, set values,
etc), at least if they are standard win32 widgets.  More and more
applications draw their own controls these days rather than use win32
widgets, which wouldn't be usable for that kind of modification.

As far as modifying a running GUI to add functionality, the answer to
that is probably "very difficult" to "impossible."  If the GUI itself is
just a frontend for command-line tools or even libraries that interact
with the hardware, then you probably could develop your own GUI from
scratch.

This is one reason why free and open source software wins. It's just
that much more flexible to manipulate and make to do cool new things.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How control a GUI for an unrelated application from a Python script?

2019-06-13 Thread Julio Oña
try https://pypi.org/project/PyAutoIt/

Regards
Julio

El jue., 13 de jun. de 2019 a la(s) 21:37, Michael Torrie
(torr...@gmail.com) escribió:
>
> On 06/13/2019 05:49 PM, Christian Seberino wrote:
> > I have a third party GUI that manages some hardware.
> >
> > I want to control the hardware from a Python script.
> >
> > This seems to mean I need to somehow have Python code
> >   that imitates a human doing the necessary
> > actions on the GUI (selecting menu options, pressing buttons, etc.)
> >
> > Is this possible
>
> Maybe.
>
> > / easy
> No.
>
> > doable?
>
> Maybe.
>
> It's kind of the old "if you have to ask" sort of question.
>
> There are ways of programatically driving other applications' user
> interfaces.  You haven't said what OS you are using.  We used to use an
> application called AutoIt to drive GUI programs.  You can send clicks,
> keystrokes, and work with certain controls (read values, set values,
> etc), at least if they are standard win32 widgets.  More and more
> applications draw their own controls these days rather than use win32
> widgets, which wouldn't be usable for that kind of modification.
>
> As far as modifying a running GUI to add functionality, the answer to
> that is probably "very difficult" to "impossible."  If the GUI itself is
> just a frontend for command-line tools or even libraries that interact
> with the hardware, then you probably could develop your own GUI from
> scratch.
>
> This is one reason why free and open source software wins. It's just
> that much more flexible to manipulate and make to do cool new things.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Dataframe with two groups of cols.

2019-06-13 Thread Paulo da Silva
Hi!

How do I create a pandas dataframe with two (or more) groups of cols.?

Ex.:

G1   G2
C1 C2 C3 C1 C2 C3
Rows of values ...

I then should be able to access for example
df['G2']['C3'][]


Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list