示例#1
0
文件: buffers.py 项目: betsegaw/peppy
 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)
示例#2
0
 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)
示例#3
0
 def test_simple(self):
     vfs.make_folder(self.root + 'tmp')
     file = vfs.make_file(self.root + 'tmp/blah.txt')
     file.write("BLAH!!!")
     file.close()
     
     # Probably too loose of a test, but the modification time has a 10
     # second window for correctness
     mtime = vfs.get_mtime(self.root + 'tmp/blah.txt')
     current = datetime.now()
     assert abs(mtime - current) < timedelta(10)
     
     file = vfs.open(self.root + 'tmp/blah.txt')
     self.assertEqual(file.read(), 'BLAH!!!')
     assert vfs.exists(self.root + 'tmp')
     
     names = vfs.get_names(self.root)
     assert "tmp" in names
     names = vfs.get_names(self.root + 'tmp')
     assert "blah.txt" in names
     
     vfs.remove(self.root + 'tmp')
     assert not vfs.exists(self.root + 'tmp')
     assert not vfs.exists(self.root + 'tmp/blah.txt')
示例#4
0
    def test_simple(self):
        vfs.make_folder(self.root + "tmp")
        file = vfs.make_file(self.root + "tmp/blah.txt")
        file.write("BLAH!!!")
        file.close()

        # Probably too loose of a test, but the modification time has a 10
        # second window for correctness
        mtime = vfs.get_mtime(self.root + "tmp/blah.txt")
        current = datetime.now()
        assert abs(mtime - current) < timedelta(10)

        file = vfs.open(self.root + "tmp/blah.txt")
        self.assertEqual(file.read(), "BLAH!!!")
        assert vfs.exists(self.root + "tmp")

        names = vfs.get_names(self.root)
        assert "tmp" in names
        names = vfs.get_names(self.root + "tmp")
        assert "blah.txt" in names

        vfs.remove(self.root + "tmp")
        assert not vfs.exists(self.root + "tmp")
        assert not vfs.exists(self.root + "tmp/blah.txt")
示例#5
0
文件: test_vfs.py 项目: zendbit/peppy
 def test09_mtime(self):
     mtime = vfs.get_mtime('vfs/file')
     self.assertEqual(mtime.year, datetime.now().year)
示例#6
0
 def test09_mtime(self):
     mtime = vfs.get_mtime('vfs/file')
     self.assertEqual(mtime.year, datetime.now().year)
示例#7
0
 def isTimestampChanged(self):
     if self.last_mtime is not None and self.url.scheme == 'file':
         mtime = vfs.get_mtime(self.url)
         #dprint("current=%s saved=%s" % (mtime, self.last_mtime))
         return mtime != self.last_mtime
     return False
示例#8
0
 def saveTimestamp(self):
     if self.url.scheme == 'file':
         try:
             self.last_mtime = vfs.get_mtime(self.url)
         except OSError:
             self.last_mtime = None
示例#9
0
文件: dired.py 项目: zendbit/peppy
 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
示例#10
0
文件: buffers.py 项目: betsegaw/peppy
 def isTimestampChanged(self):
     if self.last_mtime is not None and self.url.scheme == 'file':
         mtime = vfs.get_mtime(self.url)
         #dprint("current=%s saved=%s" % (mtime, self.last_mtime))
         return mtime != self.last_mtime
     return False
示例#11
0
文件: buffers.py 项目: betsegaw/peppy
 def saveTimestamp(self):
     if self.url.scheme == 'file':
         try:
             self.last_mtime = vfs.get_mtime(self.url)
         except OSError:
             self.last_mtime = None