def start(self): length = vfs.get_size(self.url) assert self.dprint("Loading %d bytes" % length) chunk = 65536 if length/chunk > 100: chunk *= 4 self.readFrom(chunk=chunk, length=length)
def start(self): length = vfs.get_size(self.url) assert self.dprint("Loading %d bytes" % length) chunk = 65536 if length / chunk > 100: chunk *= 4 self.readFrom(chunk=chunk, length=length)
def readThreaded(self, fh, buffer, message=None): self.refstc.tempstore = StringIO() if fh: # if the file exists, read the contents. length = vfs.get_size(buffer.url) assert self.dprint("Loading %d bytes" % length) chunk = 65536 if length / chunk > 100: chunk *= 4 self.readFrom(fh, chunk=chunk, length=length, message=message) buffer.setInitialStateIsUnmodified() else: # if the file doesn't exist, the user has asked to create a new # file. Peppy needs to reflect that it hasn't been saved by # setting its initial state to be 'modified' buffer.setInitialStateIsModified()
def restoreFromAutosaveIfExists(self): temp_url = self.stc.getAutosaveTemporaryFilename(self) if temp_url and vfs.exists(temp_url): # If the original URL no longer exists, the autosave file will be # removed without prompting. if vfs.exists( self.url) and vfs.get_mtime(temp_url) >= vfs.get_mtime( self.url) and vfs.get_size(temp_url) > 0: # backup file is newer than saved file. dlg = CustomOkDialog( wx.GetApp().GetTopWindow(), u"Autosave file for %s\nis newer than last saved version.\n\nRestore from autosave file?" % self.url, "Restore from Autosave", "Ignore Autosave") retval = dlg.ShowModal() dlg.Destroy() if retval == wx.ID_OK: self.dprint(u"Recovering from autosave file %s" % temp_url) self.revert(temp_url, allow_undo=True) self.modified = True wx.CallAfter(self.showModifiedAll) else: vfs.remove(temp_url)
def GetLength(self): return vfs.get_size(self.url)
def handleFileDrop(self, x, y, filenames): self.dprint("%d file(s) dropped at %d,%d:" % (len(filenames), x, y)) srcdir = None tocopy = [] for src in filenames: filename = os.path.basename(src) if not srcdir: srcdir = os.path.dirname(src) srcdir += os.pathsep if os.path.isdir(src): self.dprint("dir: %s" % src) for root, dirs, files in os.walk(src): for file in files: child = os.path.join(root, file) self.dprint(" file: %s" % child) tocopy.append(child) elif os.path.isfile(src): self.dprint("file: %s" % src) tocopy.append(src) else: self.dprint("not file or dir: %s NOT COPYING" % src) self.status_info.startProgress("Copying...", len(tocopy), delay=1.0) count = 0 skipped = 0 errors = [] for src in tocopy: try: srcref = vfs.get_file_reference(src) relsrc = src[len(srcdir):] relref = vfs.get_file_reference(relsrc) dest = self.url.resolve2(relref) self.dprint("srcref=%s, relref=%s, dest=%s" % (srcref, relref, dest)) self.dprint("copying: '%s' -> '%s'" % (src, dest)) self.status_info.updateProgress(count, "Copying to %s" % str(dest)) destdir = vfs.get_dirname(dest) if not vfs.exists(destdir): # Need to recursively make directories dirs = [] parent = destdir maxdepth = len(parent.path) while not vfs.exists(parent) and maxdepth > 0: dirs.append(parent) parent = vfs.get_dirname(parent) maxdepth -= 1 dirs.reverse() for dir in dirs: self.dprint("Creating dir: %s" % dir) vfs.make_folder(dir) copy = True self.dprint("src path: %s" % srcref.path) self.dprint("dest path: %s" % dest.path) if vfs.exists(dest): self.dprint("exists: %s" % str(dest)) if vfs.is_folder(dest): errors.append("Not copying folder %s; shouldn't be specified from %s" % (dest, src)) copy = False else: dlg = CustomOkDialog(self.frame, u"File exists! Replace\n\n%s, %s, %s\n\nwith:\n\n%s, %s, %s" % (dest, vfs.get_mtime(dest), vfs.get_size(dest), src, os.path.getmtime(src), os.path.getsize(src)), "Replace", "Skip") retval=dlg.ShowModal() dlg.Destroy() copy = retval==wx.ID_OK if copy: self.dprint("Removing %s" % dest) vfs.remove(dest) if copy: vfs.copy(srcref, dest) else: skipped += 1 except Exception, e: errors.append("%s: %s" % (src, e)) count += 1
def restoreFromAutosaveIfExists(self): temp_url = self.stc.getAutosaveTemporaryFilename(self) if temp_url and vfs.exists(temp_url): # If the original URL no longer exists, the autosave file will be # removed without prompting. if vfs.exists(self.url) and vfs.get_mtime(temp_url) >= vfs.get_mtime(self.url) and vfs.get_size(temp_url) > 0: # backup file is newer than saved file. dlg = CustomOkDialog(wx.GetApp().GetTopWindow(), u"Autosave file for %s\nis newer than last saved version.\n\nRestore from autosave file?" % self.url, "Restore from Autosave", "Ignore Autosave") retval=dlg.ShowModal() dlg.Destroy() if retval==wx.ID_OK: self.dprint(u"Recovering from autosave file %s" % temp_url) self.revert(temp_url, allow_undo=True) self.modified = True wx.CallAfter(self.showModifiedAll) else: vfs.remove(temp_url)