Example #1
0
 def __getitem__(self, fileName):
     if self._data[fileName]["data"] is None:
         path = self.font.path
         reader = UFOReader(path)
         path = os.path.join("data", fileName)
         data = reader.readBytesFromPath(path)
         onDiskModTime = reader.getFileModificationTime(path)
         self._data[fileName] = _dataDict(data=data, onDisk=True, onDiskModTime=onDiskModTime)
     return self._data[fileName]["data"]
Example #2
0
 def __getitem__(self, fileName):
     if self._data[fileName]["data"] is None:
         path = self.font.path
         reader = UFOReader(path, validate=False)
         path = os.path.join("data", fileName)
         data = reader.readBytesFromPath(path)
         onDiskModTime = reader.getFileModificationTime(path)
         self._data[fileName] = _dataDict(data=data, onDisk=True, onDiskModTime=onDiskModTime)
     return self._data[fileName]["data"]
Example #3
0
 def __getitem__(self, fileName):
     d = self._data[fileName]
     if d["data"] is None:
         path = self.font.path
         reader = UFOReader(path)
         data = reader.readImage(fileName)
         d["data"] = data
         d["digest"] = _makeDigest(data)
         d["onDisk"] = True
         d["onDiskModTime"] = reader.getFileModificationTime(os.path.join("images", fileName))
     return d["data"]
Example #4
0
 def __getitem__(self, fileName):
     d = self._data[fileName]
     if d["data"] is None:
         path = self.font.path
         reader = UFOReader(path)
         data = reader.readImage(fileName)
         d["data"] = data
         d["digest"] = _makeDigest(data)
         d["onDisk"] = True
         d["onDiskModTime"] = reader.getFileModificationTime(
             os.path.join("images", fileName))
     return d["data"]
Example #5
0
 def save(self,
          writer,
          removeUnreferencedImages=False,
          saveAs=False,
          progressBar=None):
     """
     Save images. This method should not be called externally.
     Subclasses may override this method to implement custom saving behavior.
     """
     if removeUnreferencedImages:
         self.disableNotifications()
         for fileName in self.unreferencedFileNames:
             del self[fileName]
         self.enableNotifications()
     if saveAs:
         font = self.font
         if font is not None and font.path is not None and os.path.exists(
                 font.path):
             reader = UFOReader(font.path)
             readerImageNames = reader.getImageDirectoryListing()
             for fileName, data in self._data.items():
                 if data["data"] is not None or fileName not in readerImageNames:
                     continue
                 writer.copyImageFromReader(reader, fileName, fileName)
     for fileName in self._scheduledForDeletion:
         try:
             writer.removeImage(fileName)
         except UFOLibError:
             # this will be raised if the file doesn't exist.
             # instead of trying to maintain a list of in UFO
             # vs. in memory, simply fail and move on when
             # something can't be deleted because it isn't
             # in the UFO.
             pass
     self._scheduledForDeletion.clear()
     reader = UFOReader(writer.path)
     for fileName, data in self._data.items():
         if not data["dirty"]:
             continue
         writer.writeImage(fileName, data["data"])
         data["dirty"] = False
         data["onDisk"] = True
         data["onDiskModTime"] = reader.getFileModificationTime(
             os.path.join("images", fileName))
     self.dirty = False
Example #6
0
 def save(self, writer, removeUnreferencedImages=False, saveAs=False, progressBar=None):
     """
     Save images. This method should not be called externally.
     Subclasses may override this method to implement custom saving behavior.
     """
     if removeUnreferencedImages:
         self.disableNotifications()
         for fileName in self.unreferencedFileNames:
             del self[fileName]
         self.enableNotifications()
     if saveAs:
         font = self.font
         if font is not None and font.path is not None and os.path.exists(font.path):
             reader = UFOReader(font.path)
             readerImageNames = reader.getImageDirectoryListing()
             for fileName, data in self._data.items():
                 if data["data"] is not None or fileName not in readerImageNames:
                     continue
                 writer.copyImageFromReader(reader, fileName, fileName)
     for fileName in self._scheduledForDeletion:
         try:
             writer.removeImage(fileName)
         except UFOLibError:
             # this will be raised if the file doesn't exist.
             # instead of trying to maintain a list of in UFO
             # vs. in memory, simply fail and move on when
             # something can't be deleted because it isn't
             # in the UFO.
             pass
     self._scheduledForDeletion.clear()
     reader = UFOReader(writer.path)
     for fileName, data in self._data.items():
         if not data["dirty"]:
             continue
         writer.writeImage(fileName, data["data"])
         data["dirty"] = False
         data["onDisk"] = True
         data["onDiskModTime"] = reader.getFileModificationTime(os.path.join("images", fileName))
     self.dirty = False
Example #7
0
 def save(self, writer, saveAs=False, progressBar=None):
     """
     Save data. This method should not be called externally.
     Subclasses may override this method to implement custom saving behavior.
     """
     if saveAs:
         font = self.font
         if font is not None and font.path is not None and os.path.exists(
                 font.path):
             reader = UFOReader(font.path)
             readerDataDirectoryListing = reader.getDataDirectoryListing()
             for fileName, data in list(self._data.items()):
                 path = os.path.join("data", fileName)
                 if data["data"] is not None or fileName not in readerDataDirectoryListing:
                     continue
                 writer.copyFromReader(reader, path, path)
     for fileName in self._scheduledForDeletion:
         try:
             path = os.path.join("data", fileName)
             writer.removeFileForPath(path)
         except UFOLibError:
             # this will be raised if the file doesn't exist.
             # instead of trying to maintain a list of in UFO
             # vs. in memory, simply fail and move on when
             # something can't be deleted because it isn't
             # in the UFO.
             pass
     self._scheduledForDeletion.clear()
     reader = UFOReader(writer.path)
     for fileName, data in list(self._data.items()):
         if not data["dirty"]:
             continue
         path = os.path.join("data", fileName)
         writer.writeBytesToPath(path, data["data"])
         data["dirty"] = False
         data["onDisk"] = True
         data["onDiskModTime"] = reader.getFileModificationTime(
             os.path.join("data", fileName))
     self.dirty = False
Example #8
0
 def save(self, writer, saveAs=False, progressBar=None):
     """
     Save data. This method should not be called externally.
     Subclasses may override this method to implement custom saving behavior.
     """
     if saveAs:
         font = self.font
         if font is not None and font.path is not None and os.path.exists(
                 font.path):
             reader = UFOReader(font.path)
             readerDataDirectoryListing = reader.getDataDirectoryListing()
             for fileName, data in self._data.items():
                 path = os.path.join("data", fileName)
                 if data["data"] is not None or fileName not in readerDataDirectoryListing:
                     continue
                 writer.copyFromReader(reader, path, path)
     for fileName in self._scheduledForDeletion:
         try:
             path = os.path.join("data", fileName)
             writer.removeFileForPath(path)
         except UFOLibError:
             # this will be raised if the file doesn't exist.
             # instead of trying to maintain a list of in UFO
             # vs. in memory, simply fail and move on when
             # something can't be deleted because it isn't
             # in the UFO.
             pass
     self._scheduledForDeletion.clear()
     reader = UFOReader(writer.path)
     for fileName, data in self._data.items():
         if not data["dirty"]:
             continue
         path = os.path.join("data", fileName)
         writer.writeBytesToPath(path, data["data"])
         data["dirty"] = False
         data["onDisk"] = True
         data["onDiskModTime"] = reader.getFileModificationTime(
             os.path.join("data", fileName))
     self.dirty = False