def SaveToFile(self, document, filename, fileformat=None, compressed='', compressed_file=''): sysname = filename try: if not document.meta.backup_created: try: if compressed_file: fs.make_backup(compressed_file) else: fs.make_backup(sysname) except fs.BackupError, value: backupfile = value.filename strerror = value.strerror msg = (_("\nCannot create backup file %(filename)s:\n" "%(message)s\n\n" "Choose `continue' to try saving anyway,\n" "or `cancel' to cancel saving.") % { 'filename': ` backupfile `, 'message': strerror }) cancel = _("Cancel") result = msgDialog(self.mw.root, title=_("Save To File"), message=msg, buttons=(_("Continue"), cancel)) if result == cancel: return document.meta.backup_created = 1 if fileformat is None: fileformat = filters.NativeFormat try: saver = filters.find_export_plugin(fileformat) if compressed: # XXX there should be a plugin interface for this kind # of post-processing if compressed == "gzip": cmd = 'gzip -c -9 > ' + utils.sh_quote(compressed_file) elif compressed == "bzip2": cmd = 'bzip2 > ' + utils.sh_quote(compressed_file) file = os.popen(cmd, 'w') saver(document, filename, file=file) else: saver(document, sysname) finally: saver.UnloadPlugin()
def render_preview(filename, startx, starty, width, height, resolution=None): import tempfile temp = tempfile.mktemp() try: # quote the filename so that it can have spaces and to avoid a # security hole filename = sh_quote(filename) if resolution is None: resolution = config.preferences.eps_preview_resolution factor = resolution / 72.0 width = int(math.ceil(width * factor)) height = int(math.ceil(height * factor)) offx = -startx offy = -starty os.system(gs_command % locals()) image = Image.open(temp) image.load() return image finally: try: os.unlink(temp) except: pass
def render_preview(filename, startx, starty, width, height, resolution = None): import tempfile temp = tempfile.mktemp() try: # quote the filename so that it can have spaces and to avoid a # security hole filename = sh_quote(filename) if resolution is None: resolution = config.preferences.eps_preview_resolution factor = resolution / 72.0 width = int(math.ceil(width * factor)) height = int(math.ceil(height * factor)) offx = -startx offy = -starty os.system(gs_command % locals()) image = Image.open(temp) image.load() return image finally: try: os.unlink(temp) except: pass
def SaveToFile(self, document, filename, fileformat=None, compressed="", compressed_file=""): sysname = filename try: if not document.meta.backup_created: try: if compressed_file: fs.make_backup(compressed_file) else: fs.make_backup(sysname) except fs.BackupError, value: backupfile = value.filename strerror = value.strerror msg = _( "\nCannot create backup file %(filename)s:\n" "%(message)s\n\n" "Choose `continue' to try saving anyway,\n" "or `cancel' to cancel saving." ) % {"filename": ` backupfile `, "message": strerror} cancel = _("Cancel") result = msgDialog( self.mw.root, title=_("Save To File"), message=msg, buttons=(_("Continue"), cancel) ) if result == cancel: return document.meta.backup_created = 1 if fileformat is None: fileformat = filters.NativeFormat try: saver = filters.find_export_plugin(fileformat) if compressed: # XXX there should be a plugin interface for this kind # of post-processing if compressed == "gzip": cmd = "gzip -c -9 > " + utils.sh_quote(compressed_file) elif compressed == "bzip2": cmd = "bzip2 > " + utils.sh_quote(compressed_file) file = os.popen(cmd, "w") saver(document, filename, file=file) else: saver(document, sysname) finally: saver.UnloadPlugin()
def Load(self): basename, ext = os.path.splitext(self.filename) if ext != '.bz2': basename = self.filename stream = os.popen('bzip2 -d -c ' + sh_quote(self.filename)) doc = load.load_drawing_from_file(stream, basename, doc_class=self.doc_class) if doc: doc.meta.compressed = "bzip2" doc.meta.compressed_file = self.filename self.messages = doc.meta.load_messages return doc
def Load(self): if self.filename: basename, ext = os.path.splitext(self.filename) if ext != '.gz': basename = self.filename stream = os.popen('gzip -d -c ' + sh_quote(self.filename)) doc = load.load_drawing_from_file(stream, basename, doc_class=self.doc_class) if doc: doc.meta.compressed = "gzip" doc.meta.compressed_file = self.filename self.messages = doc.meta.load_messages return doc raise SketchLoadError('gziploader must be instantiated with filename')