2 new revisions:

Revision: 104b49e39ba5
Branch:   default
Author:   Mikko Korpela <mikko.korp...@gmail.com>
Date:     Wed Jan 29 08:47:54 2014 UTC
Log: OperatingSystem: Move/Copy Files: support backslash always in source, ...
http://code.google.com/p/robotframework/source/detail?r=104b49e39ba5

Revision: 81abfcc96768
Branch:   default
Author:   Mikko Korpela <mikko.korp...@gmail.com>
Date:     Wed Jan 29 08:48:20 2014 UTC
Log:      merge
http://code.google.com/p/robotframework/source/detail?r=81abfcc96768

==============================================================================
Revision: 104b49e39ba5
Branch:   default
Author:   Mikko Korpela <mikko.korp...@gmail.com>
Date:     Wed Jan 29 08:47:54 2014 UTC
Log: OperatingSystem: Move/Copy Files: support backslash always in source, Ignore non-existing sources
http://code.google.com/p/robotframework/source/detail?r=104b49e39ba5

Modified:
/atest/robot/standard_libraries/operating_system/file_and_dir_moving_and_copying.txt /atest/testdata/standard_libraries/operating_system/file_and_dir_moving_and_copying.txt
 /src/robot/libraries/OperatingSystem.py

=======================================
--- /atest/robot/standard_libraries/operating_system/file_and_dir_moving_and_copying.txt Tue Jan 28 13:10:41 2014 UTC +++ /atest/robot/standard_libraries/operating_system/file_and_dir_moving_and_copying.txt Wed Jan 29 08:47:54 2014 UTC
@@ -81,7 +81,7 @@
 Move List of Files with Patterns
     Check testcase  ${TESTNAME}

-Moving Non-existing Files Fails
+Moving Non-existing Files
     Check testcase  ${TESTNAME}

 # Test cases for Copy Files keyword
@@ -109,5 +109,8 @@
 Copy List of Files with Patterns
     Check testcase  ${TESTNAME}

-Copying Non-existing Files Fails
+Copying Non-existing Files
+    Check testcase  ${TESTNAME}
+
+Copying And Moving With backslash in glob pattern
     Check testcase  ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/operating_system/file_and_dir_moving_and_copying.txt Tue Jan 28 13:10:41 2014 UTC +++ /atest/testdata/standard_libraries/operating_system/file_and_dir_moving_and_copying.txt Wed Jan 29 08:47:54 2014 UTC
@@ -203,11 +203,10 @@
     ...    movecopy_list_pattern2-4.txt
        Directory Should Have Items    ${SOURCE}    @{source_files}

-Moving Non-existing Files Fails
+Moving Non-existing Files
     [Setup]    Create Test Files For Multifile Operations
     [Teardown]    Remove Test Files For Multifile Operations
-    Run Keyword And Expect Error    No existing source files*
- ... Move Files ${SOURCE}non_existing.txt ${SOURCE}non_existing_pattern*.txt ${DEST} + Move Files ${SOURCE}non_existing.txt ${SOURCE}non_existing_pattern*.txt ${DEST}
     Directory Should Be Empty    ${DEST}
        Directory Should Have Items    ${SOURCE}    @{source_files}

@@ -233,13 +232,13 @@
 Copy Files destination can not be an existing file
     [Setup]    Create Test Files For Multifile Operations
     [Teardown]    Remove Test Files For Multifile Operations
- Run Keyword And Expect Error Destination can not be an existing file* + Run Keyword And Expect Error Destination '*' exists and is not a directory ... Copy Files ${SOURCE}movecopy_list-2.txt ${SOURCE}movecopy_list-1.txt

 Move Files destination can not be an existing file
     [Setup]    Create Test Files For Multifile Operations
     [Teardown]    Remove Test Files For Multifile Operations
- Run Keyword And Expect Error Destination can not be an existing file* + Run Keyword And Expect Error Destination '*' exists and is not a directory ... Move Files ${SOURCE}movecopy_list-2.txt ${SOURCE}movecopy_list-1.txt

 Copy Files directory will be created if it does not exist
@@ -307,13 +306,23 @@
     ...    movecopy_list_pattern2-4.txt
        Directory Should Have Items    ${SOURCE}    @{source_files}

-Copying Non-existing Files Fails
+Copying Non-existing Files
     [Setup]    Create Test Files For Multifile Operations
     [Teardown]    Remove Test Files For Multifile Operations
-    Run Keyword And Expect Error    No existing source files*    Copy Files
- ... ${SOURCE}non_existing.txt ${SOURCE}non_existing_pattern*.txt ${DEST} + Copy Files ${SOURCE}non_existing.txt ${SOURCE}non_existing_pattern*.txt ${DEST}
     Directory Should Be Empty    ${DEST}
        Directory Should Have Items    ${SOURCE}    @{source_files}
+
+Copying And Moving With backslash in glob pattern
+    [Setup]    Create Test Files For Multifile Operations
+    [Teardown]    Remove Test Files For Multifile Operations
+    Copy Files    ${BASE}move_from//movecopy_list_pattern-*.txt   ${DEST}
+    Move Files    ${BASE}move_from//movecopy_list_pattern2-*.txt  ${DEST}
+    Directory Should Have Items    ${DEST}
+    ...    movecopy_list_pattern-1.txt
+    ...    movecopy_list_pattern-2.txt
+    ...    movecopy_list_pattern2-3.txt
+    ...    movecopy_list_pattern2-4.txt

 ***Keywords***
 Remove Just Name Dirs
=======================================
--- /src/robot/libraries/OperatingSystem.py     Tue Jan 28 13:10:41 2014 UTC
+++ /src/robot/libraries/OperatingSystem.py     Wed Jan 29 08:47:54 2014 UTC
@@ -756,14 +756,9 @@

         Last argument is the destination directory.
         """
- sources, destination = self._parse_sources_and_destination(sources_and_destination) - source_files = self._prepare_list_of_source_files(destination, *sources)
-
-        if len(source_files) < 1:
- raise RuntimeError("No existing source files matching given list of files or patterns: %s" % ", ".join(sources))
-
+ source_files, dest_dir = self._parse_sources_and_destination(sources_and_destination)
         for source in source_files:
-            self.copy_file(source, destination)
+            self.copy_file(source, dest_dir)

     def move_files(self, *sources_and_destination):
         """Moves or renames list of source files.
@@ -773,19 +768,16 @@

         Last argument is the destination directory.
         """
- sources, destination = self._parse_sources_and_destination(sources_and_destination) - source_files = self._prepare_list_of_source_files(destination, *sources)
-
-        if len(source_files) < 1:
- raise RuntimeError("No existing source files matching given list of files or patterns: %s" % ", ".join(sources))
-
+ source_files, dest_dir = self._parse_sources_and_destination(sources_and_destination)
         for source in source_files:
-            self.move_file(source, destination)
+            self.move_file(source, dest_dir)

-    def _parse_sources_and_destination(self, sources_and_destination):
-        if len(sources_and_destination) < 2:
+    def _parse_sources_and_destination(self, items):
+        if len(items) < 2:
raise RuntimeError("Must contain destination and at least one source")
-        return sources_and_destination[:-1], sources_and_destination[-1]
+        sources, destination = items[:-1], items[-1]
+        self._ensure_destination_directory(destination)
+        return self._glob_files(sources), destination

     def _normalize_dest(self, dest):
         dest = dest.replace('/', os.sep)
@@ -793,16 +785,18 @@
         dest = self._absnorm(dest)
         return dest, dest_is_dir

-    def _prepare_list_of_source_files(self, destination, *sources):
-        destination, dest_is_dir = self._normalize_dest(destination)
-        if not dest_is_dir and os.path.isfile(destination):
- raise RuntimeError("Destination can not be an existing file '%s'" % destination)
-        if not os.path.isdir(destination):
+    def _ensure_destination_directory(self, destination):
+        destination, _ = self._normalize_dest(destination)
+        if not os.path.exists(destination):
             os.makedirs(destination)
-        source_files = []
-        for source in sources:
-            source_files.extend(glob.glob(source))
-        return source_files
+        elif not os.path.isdir(destination):
+ raise RuntimeError("Destination '%s' exists and is not a directory" % destination)
+
+    def _glob_files(self, patterns):
+        files = []
+        for pattern in patterns:
+            files.extend(glob.glob(self._absnorm(pattern)))
+        return files

     def _prepare_for_move_or_copy(self, source, dest):
source, dest, dest_is_dir = self._normalize_source_and_dest(source, dest)

==============================================================================
Revision: 81abfcc96768
Branch:   default
Author:   Mikko Korpela <mikko.korp...@gmail.com>
Date:     Wed Jan 29 08:48:20 2014 UTC
Log:      merge
http://code.google.com/p/robotframework/source/detail?r=81abfcc96768


--

--- 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