Commits

Ali Gholami Rudi  committed 0949073

project: fixed reading compressed data files

  • Participants
  • Parent commits 84533b5

Comments (0)

Files changed (1)

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