Anonymous avatar Anonymous committed 0949073

project: fixed reading compressed data files

Comments (0)

Files changed (1)

rope/base/project.py

     def read_data(self, name, compress=False, import_=False):
         if self.project.ropefolder is None:
             return None
+        compress = compress and self._can_compress()
         opener = self._get_opener(compress)
-        compress = opener != open
         file = self._get_file(name, compress)
         if not compress and import_:
             self._import_old_files(name)
                 input.close()
 
     def write_data(self, name, data, compress=False):
-        if self.project.ropefolder:
+        if self.project.ropefolder is not None:
+            compress = compress and self._can_compress()
             file = self._get_file(name, compress)
             opener = self._get_opener(compress)
-            compress = opener != open
             output = opener(file.real_path, 'wb')
             try:
                 pickle.dump(data, output, 2)
         for hook in self.hooks:
             hook()
 
+    def _can_compress(self):
+        try:
+            import gzip
+            return True
+        except ImportError:
+            return False
+
     def _import_old_files(self, name):
         old = self._get_file(name + '.pickle', False)
         new = self._get_file(name, False)
     def _get_file(self, name, compress):
         path = self.project.ropefolder.path + '/' + name
         if compress:
-            name += '.gz'
+            path += '.gz'
         return self.project.get_file(path)
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.