2 new revisions:

Revision: 9a8e026b2655
Author:   Pekka Klärck
Date:     Wed Jun 15 07:14:06 2011
Log:      cleanup
http://code.google.com/p/robotframework/source/detail?r=9a8e026b2655

Revision: c4fbea418aa5
Author:   Pekka Klärck
Date:     Wed Jun 15 07:51:01 2011
Log: Changed utils.normpath so that it doesn't case-normalize paths by defa...
http://code.google.com/p/robotframework/source/detail?r=c4fbea418aa5

==============================================================================
Revision: 9a8e026b2655
Author:   Pekka Klärck
Date:     Wed Jun 15 07:14:06 2011
Log:      cleanup
http://code.google.com/p/robotframework/source/detail?r=9a8e026b2655

Modified:
 /src/robot/running/importer.py

=======================================
--- /src/robot/running/importer.py      Sun Feb  6 01:24:10 2011
+++ /src/robot/running/importer.py      Wed Jun 15 07:14:06 2011
@@ -24,8 +24,8 @@
 class Importer:

     def __init__(self):
-        self._libraries = _LibraryCache()
-        self._resources = _LibraryCache()
+        self._library_cache = _Cache()
+        self._resource_cache = _Cache()

     def import_library(self, name, args, alias, variables):
         lib = TestLibrary(name, args, variables, create_handlers=False)
@@ -37,21 +37,21 @@
         return lib

     def import_resource(self, path):
-        if self._resources.has_key(path):
+        if path in self._resource_cache:
             LOGGER.info("Found resource file '%s' from cache" % path)
         else:
             resource = ResourceFile(path)
-            self._resources[path] = resource
-        return self._resources[path]
+            self._resource_cache[path] = resource
+        return self._resource_cache[path]

     def _import_library(self, name, positional, named, lib):
         key = (name, positional, named)
-        if self._libraries.has_key(key):
+        if key in self._library_cache:
LOGGER.info("Found test library '%s' with arguments %s from cache"
                         % (name, utils.seq2str2(positional)))
-            return self._libraries[key]
+            return self._library_cache[key]
         lib.create_handlers()
-        self._libraries[key] = lib
+        self._library_cache[key] = lib
         libtype = lib.__class__.__name__.replace('Library', '').lower()[1:]
         LOGGER.info("Imported library '%s' with arguments %s (version %s, "
                     "%s type, %s scope, %d keywords, source %s)"
@@ -73,23 +73,24 @@
         return libcopy


-class _LibraryCache:
- """Cache for libs/resources that doesn't require mutable keys like dicts"""
+class _Cache:
+    """Cache for libraries and resources.
+
+     Unlike dicts, this storage accepts mutable values as keys.
+     """

     def __init__(self):
         self._keys = []
-        self._libs = []
-
-    def __setitem__(self, key, library):
+        self._items = []
+
+    def __setitem__(self, key, item):
         self._keys.append(key)
-        self._libs.append(library)
+        self._items.append(item)

     def __getitem__(self, key):
-        try:
-            return self._libs[self._keys.index(key)]
-        except ValueError:
+        if key not in self._keys:
             raise KeyError
-
-    def has_key(self, key):
+        return self._items[self._keys.index(key)]
+
+    def __contains__(self, key):
         return key in self._keys
-

==============================================================================
Revision: c4fbea418aa5
Author:   Pekka Klärck
Date:     Wed Jun 15 07:51:01 2011
Log: Changed utils.normpath so that it doesn't case-normalize paths by default on Windows. Also changed places where paths were used to check has something already been imported
to do case-normalization when needed.

Update issue 307
Status: Started
Owner: pekka.klarck
This ought to be done now.

I still want to check all places where utils.normpath is
used to verify that the change is OK.
http://code.google.com/p/robotframework/source/detail?r=c4fbea418aa5

Modified:
 /atest/robot/parsing/non_ascii_paths.txt
 /src/robot/running/importer.py
 /src/robot/running/namespace.py
 /src/robot/utils/robotpath.py

=======================================
--- /atest/robot/parsing/non_ascii_paths.txt    Fri Apr 15 12:45:17 2011
+++ /atest/robot/parsing/non_ascii_paths.txt    Wed Jun 15 07:51:01 2011
@@ -30,8 +30,6 @@

 Failures processing files are handled gracefully
   ${path} =  Normalize Path  ${BASEDIR}/Työ/tyhjä.txt
- ${path} = Set Variable If __import__('robot').utils.robotpath._CASE_INSENSITIVE_FILESYSTEM
-  ...  ${path.lower()}  ${path}
Check syslog contains Parsing data source '${path}' failed: File has no test case table.


=======================================
--- /src/robot/running/importer.py      Wed Jun 15 07:14:06 2011
+++ /src/robot/running/importer.py      Wed Jun 15 07:51:01 2011
@@ -12,6 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

+import os.path
 import copy

 from robot.output import LOGGER
@@ -24,8 +25,8 @@
 class Importer:

     def __init__(self):
-        self._library_cache = _Cache()
-        self._resource_cache = _Cache()
+        self._library_cache = ImportCache()
+        self._resource_cache = ImportCache()

     def import_library(self, name, args, alias, variables):
         lib = TestLibrary(name, args, variables, create_handlers=False)
@@ -73,7 +74,7 @@
         return libcopy


-class _Cache:
+class ImportCache:
     """Cache for libraries and resources.

      Unlike dicts, this storage accepts mutable values as keys.
@@ -84,13 +85,24 @@
         self._items = []

     def __setitem__(self, key, item):
-        self._keys.append(key)
+        self._keys.append(self._norm_path_key(key))
         self._items.append(item)

+    def add(self, key):
+        self.__setitem__(key, None)
+
     def __getitem__(self, key):
+        key = self._norm_path_key(key)
         if key not in self._keys:
             raise KeyError
         return self._items[self._keys.index(key)]

     def __contains__(self, key):
-        return key in self._keys
+        return self._norm_path_key(key) in self._keys
+
+    def _norm_path_key(self, key):
+        if isinstance(key, basestring) and os.path.exists(key):
+            return utils.normpath(key, normcase=True)
+        if isinstance(key, (tuple, list)):
+            return [self._norm_path_key(k) for k in key]
+        return key
=======================================
--- /src/robot/running/namespace.py     Wed May 25 03:55:35 2011
+++ /src/robot/running/namespace.py     Wed Jun 15 07:51:01 2011
@@ -25,7 +25,7 @@
 import robot

 from userkeyword import UserLibrary
-from importer import Importer
+from importer import Importer, ImportCache
 from runkwregister import RUN_KW_REGISTER
 from handlers import _XTimesHandler

@@ -51,8 +51,8 @@
         self.library_search_order = []
         self._testlibs = {}
         self._userlibs = []
-        self._imported_resource_files = []
-        self._imported_variable_files = []
+        self._imported_resource_files = ImportCache()
+        self._imported_variable_files = ImportCache()
         self.import_library('BuiltIn')
         self.import_library('Reserved')
         self.import_library('Easter')
@@ -86,7 +86,7 @@
     def _import_resource(self, import_setting, variables=None):
         path = self._resolve_name(import_setting, variables)
         if path not in self._imported_resource_files:
-            self._imported_resource_files.append(path)
+            self._imported_resource_files.add(path)
             resource = IMPORTER.import_resource(path)
             self.variables.set_from_variable_table(resource.variable_table)
self._userlibs.append(UserLibrary(resource.keyword_table.keywords,
@@ -103,7 +103,7 @@
         path = self._resolve_name(import_setting, variables)
         args = self._resolve_args(import_setting, variables)
         if (path, args) not in self._imported_variable_files:
-            self._imported_variable_files.append((path,args))
+            self._imported_variable_files.add((path,args))
             self.variables.set_from_file(path, args, overwrite)
         else:
             msg = "Variable file '%s'" % path
=======================================
--- /src/robot/utils/robotpath.py       Fri Apr 15 14:27:57 2011
+++ /src/robot/utils/robotpath.py       Wed Jun 15 07:51:01 2011
@@ -27,11 +27,11 @@
         _CASE_INSENSITIVE_FILESYSTEM = False


-def normpath(path, normcase=True):
+def normpath(path, normcase=False):
     """Returns path in normalized and absolute format.

-    On case-insensitive file systems the path is also case normalized
-    by default.
+    On case-insensitive file systems the path is also case normalized is
+    `normcase` is True.
     """
     path = abspath(path)
     if normcase and _CASE_INSENSITIVE_FILESYSTEM:

Reply via email to