Edit detail for FTP revision 1 of 1

1
Editor: edreamleo
Time: 2006/10/12 04:07:55 GMT+0
Note: Scripting for 4.4.2

changed:
-
This code may be used as a start for editing on remote machines.

Put this in an @button FTP-ls node::

    from ftplib import FTP

    def ftp_get(line):
        bodyLines.append(line)

    directory = p
    x=FTP('host', 'user_name', 'password')

    x.cwd(directory.headString())
    for filename in x.nlst():
        p = directory.insertAsLastChild()
        p.initHeadString(filename)
        bodyLines=[]
        x.retrlines('RETR ' + filename, ftp_get)
        p.setTnodeText('\n'.join(bodyLines)) # use p.setBodyStringOrPane('\n'.join(bodyLines)) for Leo4.4.1.1
        
    x.quit()

    c.redraw_now()

Create a node having a header string that is the name of a directory on your remote FTP-host.
While this node is selected, press the FTP-ls button to obtain a subtree in which every node represents a subdirectory or file.

Since I'm using this on a configuration where there are no subdirectories, I have no problem filling the body panes with the contents of files in the directory. I don't know what will happen in the **retrlines** function when *filename* is a subdirectory.

I use this button for analyzing remote code mainly. I think to make changes to the remote code would involve writing a local file and subsequently upload it.

From edreamleo Thu Oct 12 04:04:53 -0700 2006
From: edreamleo
Date: Thu, 12 Oct 2006 04:04:53 -0700
Subject: Scripting for 4.4.2
Message-ID: <20061012040453-0700@leo.zwiki.org>

As the result of 'the big reorg' (making positions, vnodes and tnodes independent of Leo, especially c) the proper way to set headline and body text are::

    c.setBodyString(p,body) # set body text of p to body.
    c.setHeadString(p,head) # set headline text of p to head.

You can prevent c.setBodyString from redrawing the body pane more than once using the standard pattern::

    c.beginUpdate()
    try:
        << code that might redraw the body our outline panes >>
    finally:
        c.endUpdate()


This code may be used as a start for editing on remote machines.

Put this in an @button FTP-ls node:

from ftplib import FTP

def ftp_get(line):
    bodyLines.append(line)

directory = p
x=FTP('host', 'user_name', 'password')

x.cwd(directory.headString())
for filename in x.nlst():
    p = directory.insertAsLastChild()
    p.initHeadString(filename)
    bodyLines=[]
    x.retrlines('RETR ' + filename, ftp_get)
    p.setTnodeText('\n'.join(bodyLines)) # use p.setBodyStringOrPane('\n'.join(bodyLines)) for Leo4.4.1.1

x.quit()

c.redraw_now()

Create a node having a header string that is the name of a directory on your remote FTP-host. While this node is selected, press the FTP-ls button to obtain a subtree in which every node represents a subdirectory or file.

Since I'm using this on a configuration where there are no subdirectories, I have no problem filling the body panes with the contents of files in the directory. I don't know what will happen in the retrlines function when filename is a subdirectory.

I use this button for analyzing remote code mainly. I think to make changes to the remote code would involve writing a local file and subsequently upload it.

Scripting for 4.4.2 --edreamleo, Thu, 12 Oct 2006 04:04:53 -0700 reply

As the result of 'the big reorg' (making positions, vnodes and tnodes independent of Leo, especially c) the proper way to set headline and body text are:

c.setBodyString(p,body) # set body text of p to body.
c.setHeadString(p,head) # set headline text of p to head.

You can prevent c.setBodyString from redrawing the body pane more than once using the standard pattern:

c.beginUpdate()
try:
    << code that might redraw the body our outline panes >>
finally:
    c.endUpdate()