2 new revisions:

Revision: a23a42449130
Author:   Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date:     Thu Jul 25 06:27:40 2013
Log:      Removed unused import
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=a23a42449130

Revision: 043407ace281
Author:   Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date:     Thu Jul 25 07:09:43 2013
Log:      Initial implementation of Get Dir Keyword
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=043407ace281

==============================================================================
Revision: a23a42449130
Author:   Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date:     Thu Jul 25 06:27:40 2013
Log:      Removed unused import

http://code.google.com/p/robotframework-sshlibrary/source/detail?r=a23a42449130

Modified:
 /src/SSHLibrary/abstractclient.py

=======================================
--- /src/SSHLibrary/abstractclient.py   Wed Jul 24 03:55:31 2013
+++ /src/SSHLibrary/abstractclient.py   Thu Jul 25 06:27:40 2013
@@ -20,8 +20,6 @@
 import time
 import glob

-from robot import utils
-
 from .config import (Configuration, StringEntry, TimeEntry, IntegerEntry,
         NewlineEntry)


==============================================================================
Revision: 043407ace281
Author:   Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date:     Thu Jul 25 07:09:43 2013
Log:      Initial implementation of Get Dir Keyword

http://code.google.com/p/robotframework-sshlibrary/source/detail?r=043407ace281

Added:
 /atest/get_dir.txt
Modified:
 /src/SSHLibrary/abstractclient.py
 /src/SSHLibrary/javaclient.py
 /src/SSHLibrary/library.py
 /src/SSHLibrary/pythonclient.py

=======================================
--- /dev/null
+++ /atest/get_dir.txt  Thu Jul 25 07:09:43 2013
@@ -0,0 +1,43 @@
+*** Settings ***
+Force Tags      pybot   jybot
+Suite Setup     Login and Move Test Files
+Suite Teardown  Remove Test Files and Close Connections
+Test Setup      Create Directory  robot-tmpdir
+Test Teardown   Remove Directory  robot-tmpdir  True
+Resource        resources/ssh_library_resources.txt
+Library         Collections
+
+*** Test Cases ***
+Get Dir Using Absolute Source
+    Get Dir And Verify Content  ${USER HOME}/test_root  robot-tmpdir
+
+Get Dir Using Relative Source
+    Get Dir And Verify Content  test_root  robot-tmpdir
+
+Get Dir Using Different Name
+    Get Dir And Verify Content  ${USER HOME}/test_root  robot-tmpdir/foo
+
+
+*** Keywords ***
+Get Dir And Verify Content
+    [Arguments]  ${source}  ${destination}
+    SSHLibrary.Get Dir  ${source}  ${destination}
+    ${target_path} =  List Directory  ${destination}
+    ${expected} =  Create List  test_root
+    Lists Should Be Equal  ${target_path}  ${expected}
+    ${test_root} =  List Directory  ${destination}/test_root
+ ${expected} = Create List subdir ${TEST SCRIPT NAME} ${REPEAT TEST SCRIPT NAME}
+    Lists Should Be Equal  ${test_root}  ${expected}
+    ${sub_dir} =  List Directory  ${destination}/test_root/subdir
+    ${expected} =  Create List  ${INTERACTIVE TEST SCRIPT NAME}
+    Lists Should Be Equal  ${sub_dir}  ${expected}
+
+Login And Move Test Files
+    Login As Valid User
+    Put File  ${TEST SCRIPT}  ${USER HOME}/test_root/
+    Put File  ${INTERACTIVE TEST SCRIPT}  ${USER HOME}/test_root/subdir/
+    Put File  ${REPEAT TEST SCRIPT}  ${USER HOME}/test_root/
+
+Remove Test Files and Close Connections
+    Execute Command  rm -rf ${USER HOME}/test_root
+    Close All Connections
=======================================
--- /src/SSHLibrary/abstractclient.py   Thu Jul 25 06:27:40 2013
+++ /src/SSHLibrary/abstractclient.py   Thu Jul 25 07:09:43 2013
@@ -283,11 +283,18 @@
             Must be defined if the remote machine runs Windows.
         """
         sftp_client = self._create_sftp_client()
-        sources, destinations = sftp_client.get_file(
-                source, destination, path_separator)
+        sources, destinations = sftp_client.get_file(source, destination,
+                                                     path_separator)
         sftp_client.close()
         return sources, destinations

+    def get_dir(self, source, destination='.', path_separator='/'):
+        sftp_client = self._create_sftp_client()
+        sources, destinations = sftp_client.get_dir(source, destination,
+                                                    path_separator)
+        sftp_client.close()
+        return sources, destinations
+

 class AbstractSFTPClient(object):

@@ -298,13 +305,27 @@
     def close(self):
         self._client.close()

-    def get_file(self, sources, destination, path_separator='/'):
-        remotefiles = self._get_get_file_sources(sources, path_separator)
+    def get_file(self, source, destination, path_separator='/'):
+        remotefiles = self._get_get_file_sources(source, path_separator)
localfiles = self._get_get_file_destinations(remotefiles, destination)
         for src, dst in zip(remotefiles, localfiles):
             self._get_file(src, dst)
         return remotefiles, localfiles

+    def get_dir(self, source, destination, path_separator='/'):
+        remotefiles = []
+        localfiles = []
+        subdirs = [os.path.split(source)[1]]
+        for path in subdirs:
+            [subdirs.append(os.path.join(path, subdir_name))
+             for subdir_name in self._listdirs(path)]
+            remote_path = path + path_separator + "*"
+            local_path = os.path.join(destination, path) + path_separator
+            r, l = self.get_file(remote_path, local_path, path_separator)
+            remotefiles.extend(r)
+            localfiles.extend(l)
+        return remotefiles, localfiles
+
     def _get_get_file_sources(self, source, path_separator):
         if path_separator in source:
             path, pattern = source.rsplit(path_separator, 1)
=======================================
--- /src/SSHLibrary/javaclient.py       Mon Jul 22 01:57:46 2013
+++ /src/SSHLibrary/javaclient.py       Thu Jul 25 07:09:43 2013
@@ -128,13 +128,18 @@

     def _listfiles(self, path):
         return [finfo.filename for finfo in self._client.ls(path)
- if finfo.attributes.getOctalPermissions().startswith('0100')]
+                if finfo.attributes.isRegularFile()]

-    def _get_file(self, source, dest):
-        localfile = FileOutputStream(dest)
-        tempstats = self._client.stat(source)
+    def _listdirs(self, path):
+        return [finfo.filename for finfo in self._client.ls(path)
+                if finfo.attributes.isDirectory() and
+                finfo.filename not in ('.', '..')]
+
+    def _get_file(self, remotepath, localpath):
+        localfile = FileOutputStream(localpath)
+        tempstats = self._client.stat(remotepath)
         remotefilesize = tempstats.size
-        remotefile = self._client.openFileRO(source)
+        remotefile = self._client.openFileRO(remotepath)
         size = 0
         arraysize = 4096
         data = jarray.zeros(arraysize, 'b')
=======================================
--- /src/SSHLibrary/library.py  Wed Jul 24 03:55:52 2013
+++ /src/SSHLibrary/library.py  Thu Jul 25 07:09:43 2013
@@ -608,6 +608,10 @@
         return self._run_sftp_command(self.ssh_client.get_file, source,
                                       destination, path_separator)

+    def get_dir(self, source, destination='.', path_separator='/'):
+        return self._run_sftp_command(self.ssh_client.get_dir, source,
+                                      destination, path_separator)
+
     def put_file(self, source, destination='.', mode='0744',
                  newline='default', path_separator='/'):
         """Uploads file(s) from the local host to the remote host.
@@ -651,8 +655,14 @@
| Put File | /path_to_local_files/*.txt | /path_to_remote_files/ | # multiple files with wild cards | | | Put File | /path_to_local_files/*.txt | /path_to_remote_files/ | 0777 | CRLF | # file permissions and forcing Windows newlines |
         """
-        cmd = self.ssh_client.put_file
- return self._run_sftp_command(cmd, source, destination, mode, newline,
+        return self._run_sftp_command(self.ssh_client.put_file, source,
+                                      destination, mode, newline,
+                                      path_separator)
+
+    def put_dir(self, source, destination='.', mode='0744',
+                newline='default', path_separator='/'):
+        return self._run_sftp_command(self.ssh_client.put_dir, source,
+                                      destination, mode, newline,
                                       path_separator)

     def _run_sftp_command(self, command, *args):
=======================================
--- /src/SSHLibrary/pythonclient.py     Mon Jul 22 01:57:46 2013
+++ /src/SSHLibrary/pythonclient.py     Thu Jul 25 07:09:43 2013
@@ -14,6 +14,7 @@

 import stat
 import posixpath
+
 try:
     import paramiko
 except ImportError:
@@ -111,8 +112,8 @@
     def _resolve_homedir(self):
         return self._client.normalize('.') + '/'

-    def _get_file(self, source, dest):
-        self._client.get(source, dest)
+    def _get_file(self, remotepath, localpath):
+        self._client.get(remotepath, localpath)

     def _write_to_remote_file(self, remotefile, data, position):
         remotefile.write(data)
@@ -142,8 +143,12 @@
     def _listfiles(self, path):
         return [getattr(fileinfo, 'filename', '?') for fileinfo
                 in self._client.listdir_attr(path)
-                if stat.S_ISREG(fileinfo.st_mode) or
-                   stat.S_IFMT(fileinfo.st_mode) == 0]
+                if stat.S_ISREG(fileinfo.st_mode)]
+
+    def _listdirs(self, path):
+        return [getattr(fileinfo, 'filename', '?') for fileinfo
+                in self._client.listdir_attr(path)
+                if stat.S_ISDIR(fileinfo.st_mode)]


 class RemoteCommand(AbstractCommand):

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to