3 new revisions:
Revision: 9bdf4fd9391e
Author: Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date: Thu Aug 1 05:10:34 2013
Log: Correct Put Directory behaviour when remote path exists
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=9bdf4fd9391e
Revision: 107fed37bf29
Author: Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date: Thu Aug 1 05:45:01 2013
Log: Handling relative paths correctly
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=107fed37bf29
Revision: 4a8725a7d3c2
Author: Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date: Thu Aug 1 05:55:37 2013
Log: Tidied up teardown
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=4a8725a7d3c2
==============================================================================
Revision: 9bdf4fd9391e
Author: Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date: Thu Aug 1 05:10:34 2013
Log: Correct Put Directory behaviour when remote path exists
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=9bdf4fd9391e
Modified:
/atest/put_directory.txt
/src/SSHLibrary/abstractclient.py
/src/SSHLibrary/javaclient.py
/src/SSHLibrary/pythonclient.py
=======================================
--- /atest/put_directory.txt Thu Aug 1 03:06:59 2013
+++ /atest/put_directory.txt Thu Aug 1 05:10:34 2013
@@ -2,60 +2,81 @@
Force Tags pybot jybot
Suite Setup Login As Valid User
Suite Teardown Close All Connections
-Test Teardown Execute Command rm -rf ${target}
+Test Teardown Remove Remote Files ${target}
Resource resources/ssh_library_resources.txt
*** Test Cases ***
-Put Directory To Absolute Destination
- ${target} = Set Variable ${USER HOME}/new_dir/
- Remote Directory Should Not Exist ${target}
+Put Directory To Existing Absolute Destination
+ ${target} = Set Variable ${USER HOME}
+ Verify Remote Directory Exists ${target}
Put Directory ${TEXTFILES} ${target}
Remote Directory Should Exist With Content ${target}/textfiles
-Put Directory To Relative Destination
- ${target} = Set Variable new_dir/
- Remote Directory Should Not Exist ${target}
+Put Directory To Non-Existing Absolute Destination
+ ${target} = Set Variable ${USER HOME}/new_dir
+ Verify Remote Directory Does Not Exists ${target}
+ Put Directory ${TEXTFILES} ${target}
+ Remote Directory Should Exist With Content ${target}
+
+Put Directory To Non-Existing Relative Destination
+ ${target} = Set Variable new_dir
+ Verify Remote Directory Does Not Exists ${target}
Put Directory ${TEXTFILES} ${target}
+ Remote Directory Should Exist With Content ${target}
+
+Put Directory To Current Remote Destination
+ ${target} = Set Variable ./
+ Verify Remote Directory Exists ${target}
+ Put Directory ${TEXTFILES} ${target}
Remote Directory Should Exist With Content ${target}/textfiles
-
-Put Directory To Home Directory
- ${target} = Set Variable ./textfiles
- Remote Directory Should Not Exist ${target}
- Put Directory ${TEXTFILES} ./
- Remote Directory Should Exist With Content ${target}
Put Directory To Different Name
${target} = Set Variable ${USER HOME}/another_dir_name
- Remote Directory Should Not Exist ${target}
+ Verify Remote Directory Does Not Exists ${target}
Put Directory ${TEXTFILES} ${target}
Remote Directory Should Exist With Content ${target}
Put Directory Including Subdirectories
- ${target} = Set Variable ${USER HOME}/new_dir/
- Remote Directory Should Not Exist ${target}
+ ${target} = Set Variable ${USER HOME}/new_dir
+ Verify Remote Directory Does Not Exists ${target}
Put Directory ${TEXTFILES} ${target} recursive=True
- Remote Directory Should Exist With Subdirectories ${target}/textfiles
+ Remote Directory Should Exist With Subdirectories ${target}
*** Keywords ***
-Remote Directory Should Not Exist
- [Arguments] ${expected}
- ${rc} = Execute Command test -d ${expected} return_stdout=${false}
return_rc=${true}
+Verify Remote Directory Exists
+ [Arguments] ${destination}
+ ${rc} = Execute Command test -d ${destination}
return_stdout=${false} return_rc=${true}
+ Should Be Equal As Integers ${rc} 0
+
+Verify Remote Directory Does Not Exists
+ [Arguments] ${destination}
+ ${rc} = Execute Command test -d ${destination}
return_stdout=${false} return_rc=${true}
Should Be Equal As Integers ${rc} 1
Remote Directory Should Exist With Content
- [Arguments] ${expected}
- ${stdout} = Execute Command ls ${expected}
+ [Arguments] ${destination}
+ ${stdout} = Execute Command ls ${destination}
Should Contain ${stdout} ${TEST FILE NAME}
Should Contain ${stdout} ${TEST FILE 2 NAME}
Should Contain ${stdout} ${FILE WITH NEWLINES NAME}
Should Not Contain ${stdout} special
Remote Directory Should Exist With Subdirectories
- [Arguments] ${expected}
- ${stdout} = Execute Command ls ${expected}
+ [Arguments] ${destination}
+ ${stdout} = Execute Command ls ${destination}
Should Contain ${stdout} ${TEST FILE NAME}
Should Contain ${stdout} ${TEST FILE 2 NAME}
Should Contain ${stdout} ${FILE WITH NEWLINES NAME}
Should Contain ${stdout} special
- ${stdout} = Execute Command ls ${expected}/special
+ ${stdout} = Execute Command ls ${destination}/special
Should Contain ${stdout} ${FILE WITH SPECIAL CHARS NAME}
+
+Remove Remote Files
+ [Arguments] ${destination}
+ Execute Command rm ${USER HOME}${/}${TEST FILE NAME}
+ Execute Command rm ${USER HOME}${/}${TEST FILE 2 NAME}
+ Execute Command rm ${USER HOME}${/}${FILE WITH NEWLINES NAME}
+ Execute Command rm -rf ${USER HOME}${/}textfiles
+ Execute Command rm -rf ${USER HOME}${/}special
+ Execute Command rm -rf ${USER HOME}${/}another_dir_name
+ Execute Command rm -rf ${USER HOME}${/}new_dir
=======================================
--- /src/SSHLibrary/abstractclient.py Thu Aug 1 03:06:59 2013
+++ /src/SSHLibrary/abstractclient.py Thu Aug 1 05:10:34 2013
@@ -328,7 +328,7 @@
for path in subdirs:
if recursive:
[subdirs.append(path_separator.join([path, subdir_name]))
- for subdir_name in self._listdirs(path)]
+ for subdir_name in self.listdirs(path)]
remote_path = path + path_separator + "*"
local_path = os.path.join(destination, path) + path_separator
if not local_target_exists:
@@ -353,7 +353,7 @@
if not path:
path = '.'
sourcefiles = []
- for filename in self._listfiles(path):
+ for filename in self.listfiles(path):
if fnmatchcase(filename, pattern):
if path:
filename = path_separator.join([path, filename])
@@ -385,24 +385,22 @@
def put_directory(self, source, destination, mode, newline,
path_separator='/', recursive=False):
+ localfiles = []
+ remotefiles = []
os.chdir(os.path.dirname(source))
parent = os.path.basename(source)
- localfiles = []
- remotefiles = []
+ if destination.endswith(path_separator):
+ destination = destination[:-1]
+ remote_target_exists = True if self.exists(destination) else False
for dirpath, _, filenames in os.walk(parent):
for filename in filenames:
local_path = os.path.join(dirpath, filename)
- if destination.endswith('.' + os.path.sep):
+ if destination.endswith('.'):
remote_path = path_separator.join([dirpath, filename])
- elif destination.endswith(os.path.sep):
- remote_path = path_separator.join([destination[:-1],
- dirpath,
- filename])
else:
- path_without_parent = dirpath.replace(parent, '')
- remote_path = path_separator.join([destination,
- path_without_parent,
- filename])
+ remote_path = path_separator.join([destination,
dirpath, filename])
+ if not remote_target_exists:
+ remote_path = remote_path.replace(parent +
path_separator, '')
l, r = self.put_file(local_path, remote_path, mode,
newline,
path_separator)
localfiles.extend(l)
=======================================
--- /src/SSHLibrary/javaclient.py Thu Jul 25 07:09:43 2013
+++ /src/SSHLibrary/javaclient.py Thu Aug 1 05:10:34 2013
@@ -91,6 +91,23 @@
class SFTPClient(AbstractSFTPClient):
+ def exists(self, path):
+ try:
+ self._client.stat(path)
+ except SFTPException:
+ return False
+ else:
+ return True
+
+ def listfiles(self, path):
+ return [finfo.filename for finfo in self._client.ls(path)
+ if finfo.attributes.isRegularFile()]
+
+ def listdirs(self, path):
+ return [finfo.filename for finfo in self._client.ls(path)
+ if finfo.attributes.isDirectory() and
+ finfo.filename not in ('.', '..')]
+
def _create_client(self, ssh_client):
return SFTPv3Client(ssh_client)
@@ -126,15 +143,6 @@
def _close_remote_file(self, remotefile):
self._client.closeFile(remotefile)
- def _listfiles(self, path):
- return [finfo.filename for finfo in self._client.ls(path)
- if finfo.attributes.isRegularFile()]
-
- 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)
=======================================
--- /src/SSHLibrary/pythonclient.py Thu Jul 25 07:09:43 2013
+++ /src/SSHLibrary/pythonclient.py Thu Aug 1 05:10:34 2013
@@ -106,6 +106,26 @@
class SFTPClient(AbstractSFTPClient):
+ def exists(self, path):
+ try:
+ self._client.stat(path)
+ except IOError, e:
+ if e[0] == 2:
+ return False
+ raise
+ else:
+ return True
+
+ def listfiles(self, path):
+ return [getattr(fileinfo, 'filename', '?') for fileinfo
+ in self._client.listdir_attr(path)
+ 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)]
+
def _create_client(self, ssh_client):
return ssh_client.open_sftp()
@@ -140,16 +160,6 @@
self._client.chmod(dest, mode)
return remotfile
- def _listfiles(self, path):
- return [getattr(fileinfo, 'filename', '?') for fileinfo
- in self._client.listdir_attr(path)
- 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):
==============================================================================
Revision: 107fed37bf29
Author: Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date: Thu Aug 1 05:45:01 2013
Log: Handling relative paths correctly
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=107fed37bf29
Modified:
/atest/get_directory.txt
/atest/put_directory.txt
/src/SSHLibrary/abstractclient.py
=======================================
--- /atest/get_directory.txt Thu Aug 1 03:06:59 2013
+++ /atest/get_directory.txt Thu Aug 1 05:45:01 2013
@@ -11,48 +11,29 @@
[Setup] Create Directory ${LOCAL TMPDIR}
${target} = Set Variable ${LOCAL TMPDIR}
Directory Should Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root ${target}
- Directory Should Exist With Content ${target}/test_root
-
-Get Directory With Ending Slash To Existing Local Path
- [Setup] Create Directory ${LOCAL TMPDIR}
- ${target} = Set Variable ${LOCAL TMPDIR}
- Directory Should Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root/ ${target}
- Directory Should Exist With Content ${target}/test_root
+ SSHLibrary.Get Directory ${USER HOME}${/}test_root ${target}
+ Directory Should Exist With Content ${target}${/}test_root
Get Directory To Non-Existing Local Path
- ${target} = Set Variable ${LOCAL TMPDIR}
+ ${target} = Set Variable tmpdir
Directory Should Not Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root ${target}
+ SSHLibrary.Get Directory ${USER HOME}${/}test_root${/} ${target}
Directory Should Exist With Content ${target}
-Get Directory With Ending Slash To Non-Existing Local Path
- ${target} = Set Variable ${LOCAL TMPDIR}
- Directory Should Not Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root/ ${target}
- Directory Should Exist With Content ${target}
-
-Get Directory Including Subdirectories To Existing Local Destination
+Get Directory Including Subdirectories To Existing Local Path
[Setup] Create Directory ${LOCAL TMPDIR}
${target} = Set Variable ${LOCAL TMPDIR}
Directory Should Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root ${target}
recursive=True
- Directory Should Exist Including Subdirectories ${target}/test_root
+ SSHLibrary.Get Directory ${USER HOME}${/}test_root ${target}
recursive=True
+ Directory Should Exist Including Subdirectories ${target}${/}test_root
-Get Directory Including Subdirectories To Non Existing Local Destination
- ${target} = Set Variable ${LOCAL TMPDIR}
+Get Directory Including Subdirectories To Non-Existing Local Path
+ ${target} = Set Variable tmpdir
Directory Should Not Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root ${target}
recursive=True
+ SSHLibrary.Get Directory ${USER HOME}${/}test_root ${target}
recursive=True
Directory Should Exist Including Subdirectories ${target}
-Get Directory To Non-Existing Relative Local Path
- ${target} = Set Variable tmpdir
- Directory Should Not Exist ${target}
- SSHLibrary.Get Directory ${USER HOME}/test_root ${target}
- Directory Should Exist With Content ${target}
-
-Get Directory To Current Local Destination
+Get Directory To Current Local Path
${target} = Set Variable .${/}test_root
Directory Should Not Exist ${target}
SSHLibrary.Get Directory ${USER HOME}${/}test_root .
@@ -67,23 +48,23 @@
*** Keywords ***
Directory Should Exist With Content
[Arguments] ${destination}
- File Should Exist ${destination}/${TEST SCRIPT NAME}
- File Should Exist ${destination}/${REPEAT TEST SCRIPT NAME}
- Directory Should Not Exist ${destination}/subdir
+ File Should Exist ${destination}${/}${TEST SCRIPT NAME}
+ File Should Exist ${destination}${/}${REPEAT TEST SCRIPT NAME}
+ Directory Should Not Exist ${destination}${/}subdir
Directory Should Exist Including Subdirectories
[Arguments] ${destination}
- File Should Exist ${destination}/${TEST SCRIPT NAME}
- File Should Exist ${destination}/${REPEAT TEST SCRIPT NAME}
- Directory Should Exist ${destination}/subdir
- File Should Exist ${destination}/subdir/${INTERACTIVE TEST SCRIPT
NAME}
+ File Should Exist ${destination}${/}${TEST SCRIPT NAME}
+ File Should Exist ${destination}${/}${REPEAT TEST SCRIPT NAME}
+ Directory Should Exist ${destination}${/}subdir
+ File Should Exist ${destination}${/}subdir/${INTERACTIVE TEST SCRIPT
NAME}
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/
+ 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
+ Execute Command rm -rf ${USER HOME}${/}test_root
Close All Connections
=======================================
--- /atest/put_directory.txt Thu Aug 1 05:10:34 2013
+++ /atest/put_directory.txt Thu Aug 1 05:45:01 2013
@@ -6,41 +6,41 @@
Resource resources/ssh_library_resources.txt
*** Test Cases ***
-Put Directory To Existing Absolute Destination
+Put Directory To Existing Remote Path
${target} = Set Variable ${USER HOME}
Verify Remote Directory Exists ${target}
Put Directory ${TEXTFILES} ${target}
- Remote Directory Should Exist With Content ${target}/textfiles
+ Remote Directory Should Exist With Content ${target}${/}textfiles
-Put Directory To Non-Existing Absolute Destination
- ${target} = Set Variable ${USER HOME}/new_dir
+Put Directory To Non-Existing Remote Path
+ ${target} = Set Variable another_dir_name
Verify Remote Directory Does Not Exists ${target}
Put Directory ${TEXTFILES} ${target}
Remote Directory Should Exist With Content ${target}
-Put Directory To Non-Existing Relative Destination
- ${target} = Set Variable new_dir
- Verify Remote Directory Does Not Exists ${target}
- Put Directory ${TEXTFILES} ${target}
- Remote Directory Should Exist With Content ${target}
-
-Put Directory To Current Remote Destination
- ${target} = Set Variable ./
+Put Directory Including Subdirectories To Existing Remote Path
+ ${target} = Set Variable ${USER HOME}
Verify Remote Directory Exists ${target}
- Put Directory ${TEXTFILES} ${target}
- Remote Directory Should Exist With Content ${target}/textfiles
-
-Put Directory To Different Name
- ${target} = Set Variable ${USER HOME}/another_dir_name
- Verify Remote Directory Does Not Exists ${target}
- Put Directory ${TEXTFILES} ${target}
- Remote Directory Should Exist With Content ${target}
+ Put Directory ${TEXTFILES} ${target} recursive=True
+ Remote Directory Should Exist With Subdirectories
${target}${/}textfiles
-Put Directory Including Subdirectories
- ${target} = Set Variable ${USER HOME}/new_dir
+Put Directory Including Subdirectories To Non-Existing Remote Path
+ ${target} = Set Variable another_dir_name
Verify Remote Directory Does Not Exists ${target}
Put Directory ${TEXTFILES} ${target} recursive=True
Remote Directory Should Exist With Subdirectories ${target}
+
+Put Directory To Current Remote Path
+ ${target} = Set Variable .
+ Verify Remote Directory Exists ${target}
+ Put Directory ${TEXTFILES} ${target}
+ Remote Directory Should Exist With Content ${target}${/}textfiles
+
+Put Directory Using Relative Source
+ ${target} = Set Variable ${USER HOME}
+ Verify Remote Directory Exists ${target}
+ Put Directory textfiles ${target}
+ Remote Directory Should Exist With Content ${target}${/}textfiles
*** Keywords ***
Verify Remote Directory Exists
@@ -68,7 +68,7 @@
Should Contain ${stdout} ${TEST FILE 2 NAME}
Should Contain ${stdout} ${FILE WITH NEWLINES NAME}
Should Contain ${stdout} special
- ${stdout} = Execute Command ls ${destination}/special
+ ${stdout} = Execute Command ls ${destination}${/}special
Should Contain ${stdout} ${FILE WITH SPECIAL CHARS NAME}
Remove Remote Files
=======================================
--- /src/SSHLibrary/abstractclient.py Thu Aug 1 05:10:34 2013
+++ /src/SSHLibrary/abstractclient.py Thu Aug 1 05:45:01 2013
@@ -387,7 +387,7 @@
path_separator='/', recursive=False):
localfiles = []
remotefiles = []
- os.chdir(os.path.dirname(source))
+ os.chdir(os.path.dirname(os.path.abspath(source)))
parent = os.path.basename(source)
if destination.endswith(path_separator):
destination = destination[:-1]
==============================================================================
Revision: 4a8725a7d3c2
Author: Anssi Syrjäsalo <anssi.syrjas...@eficode.com>
Date: Thu Aug 1 05:55:37 2013
Log: Tidied up teardown
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=4a8725a7d3c2
Modified:
/atest/put_directory.txt
/src/SSHLibrary/abstractclient.py
=======================================
--- /atest/put_directory.txt Thu Aug 1 05:45:01 2013
+++ /atest/put_directory.txt Thu Aug 1 05:55:37 2013
@@ -10,7 +10,8 @@
${target} = Set Variable ${USER HOME}
Verify Remote Directory Exists ${target}
Put Directory ${TEXTFILES} ${target}
- Remote Directory Should Exist With Content ${target}${/}textfiles
+ ${target} = Set Variable ${target}${/}textfiles
+ Remote Directory Should Exist With Content ${target}
Put Directory To Non-Existing Remote Path
${target} = Set Variable another_dir_name
@@ -22,7 +23,8 @@
${target} = Set Variable ${USER HOME}
Verify Remote Directory Exists ${target}
Put Directory ${TEXTFILES} ${target} recursive=True
- Remote Directory Should Exist With Subdirectories
${target}${/}textfiles
+ ${target} = Set Variable ${target}${/}textfiles
+ Remote Directory Should Exist With Subdirectories ${target}
Put Directory Including Subdirectories To Non-Existing Remote Path
${target} = Set Variable another_dir_name
@@ -34,13 +36,15 @@
${target} = Set Variable .
Verify Remote Directory Exists ${target}
Put Directory ${TEXTFILES} ${target}
- Remote Directory Should Exist With Content ${target}${/}textfiles
+ ${target} = Set Variable ${target}${/}textfiles
+ Remote Directory Should Exist With Content ${target}
Put Directory Using Relative Source
${target} = Set Variable ${USER HOME}
Verify Remote Directory Exists ${target}
Put Directory textfiles ${target}
- Remote Directory Should Exist With Content ${target}${/}textfiles
+ ${target} = Set Variable ${target}${/}textfiles
+ Remote Directory Should Exist With Content ${target}
*** Keywords ***
Verify Remote Directory Exists
@@ -73,10 +77,4 @@
Remove Remote Files
[Arguments] ${destination}
- Execute Command rm ${USER HOME}${/}${TEST FILE NAME}
- Execute Command rm ${USER HOME}${/}${TEST FILE 2 NAME}
- Execute Command rm ${USER HOME}${/}${FILE WITH NEWLINES NAME}
- Execute Command rm -rf ${USER HOME}${/}textfiles
- Execute Command rm -rf ${USER HOME}${/}special
- Execute Command rm -rf ${USER HOME}${/}another_dir_name
- Execute Command rm -rf ${USER HOME}${/}new_dir
+ Execute Command rm -rf ${destination}
=======================================
--- /src/SSHLibrary/abstractclient.py Thu Aug 1 05:45:01 2013
+++ /src/SSHLibrary/abstractclient.py Thu Aug 1 05:55:37 2013
@@ -387,7 +387,8 @@
path_separator='/', recursive=False):
localfiles = []
remotefiles = []
- os.chdir(os.path.dirname(os.path.abspath(source)))
+ source = os.path.abspath(source)
+ os.chdir(os.path.dirname(source))
parent = os.path.basename(source)
if destination.endswith(path_separator):
destination = destination[:-1]
--
---
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.