Пример #1
0
    def findProjectURL(cls, url):
        # Check to see if we already know what the path is, and if we think we
        # do, make sure the project path still exists
        if url in cls.buffer_url_to_project_dir:
            path = cls.buffer_url_to_project_dir[url]
            if vfs.is_folder(path):
                return path
            del cls.buffer_url_to_project_dir[url]

        # Look for a new project path starting from the specified URL.
        if vfs.is_folder(url):
            last = vfs.normalize(url)
        else:
            last = vfs.normalize(vfs.get_dirname(url))
        cls.dprint(str(last.path))
        while not last.path.is_relative() and True:
            path = last.resolve2("%s" % (cls.classprefs.project_directory))
            cls.dprint(path.path)
            if vfs.is_folder(path):
                cls.buffer_url_to_project_dir[url] = path
                return path
            path = vfs.get_dirname(path.resolve2(".."))
            if path == last:
                cls.dprint("Done!")
                break
            last = path
        return None
Пример #2
0
    def completePath(self, text, uri, path):
        paths = []
        if "/" in path:
            if path.endswith("/"):
                # It's already a directory
                uridir = uri
                pattern = ""
            else:
                # The stuff after the last slash is the pattern to match
                uridir, pattern = path.rsplit("/", 1)
                uridir = vfs.get_dirname(uri)
        elif path == ".":
            # Needed to handle protocols that don't use leading slashes
            uridir = uri
            pattern = ""
        else:
            uridir = vfs.get_dirname(uri)
            pattern = path

        self.dprint("dir=%s pattern=%s" % (uridir, pattern))
        try:
            for name in vfs.get_names(uridir):
                if not name.startswith(pattern):
                    self.dprint("skipping %s because it doesn't start with %s" % (name, pattern))
                    continue
                uri = uridir.resolve2(name)
                path = str(uri)
                if vfs.is_folder(uri) and not path.endswith("/"):
                    path += "/"
                self.dprint(path)
                paths.append(path)
        except vfs.AuthenticationCancelled:
            pass
        return paths
Пример #3
0
    def findProjectURL(cls, url):
        # Check to see if we already know what the path is, and if we think we
        # do, make sure the project path still exists
        if url in cls.buffer_url_to_project_dir:
            path = cls.buffer_url_to_project_dir[url]
            if vfs.is_folder(path):
                return path
            del cls.buffer_url_to_project_dir[url]

        # Look for a new project path starting from the specified URL.
        if vfs.is_folder(url):
            last = vfs.normalize(url)
        else:
            last = vfs.normalize(vfs.get_dirname(url))
        cls.dprint(str(last.path))
        while not last.path.is_relative() and True:
            path = last.resolve2("%s" % (cls.classprefs.project_directory))
            cls.dprint(path.path)
            if vfs.is_folder(path):
                cls.buffer_url_to_project_dir[url] = path
                return path
            path = vfs.get_dirname(path.resolve2('..'))
            if path == last:
                cls.dprint("Done!")
                break
            last = path
        return None
Пример #4
0
 def __init__(self, url):
     self.project_settings_dir = url
     self.project_top_dir = vfs.get_dirname(url)
     self.project_config = None
     self.loadPrefs()
     self.loadTags()
     self.process = None
Пример #5
0
    def cwd(self, use_vfs=False):
        """Find the current working directory of the buffer.
        
        Can be used in two ways based on use_vfs:
        
        use_vfs == True: uses the vfs to return the directory in the same
        scheme as the buffer
        
        use_vfs == False (the default): find the current working directory
        on the local filesystem.  Some schemes, like tar, for instance, are
        overlays on the current filesystem and the cwd of those schemes with
        this sense of use_vfs will report the overlayed directory.
        """
        if self.pending_url is not None:
            url = self.pending_url
        else:
            url = self.url
        if use_vfs:
            if vfs.is_folder(url):
                path = vfs.normalize(url)
            else:
                path = vfs.get_dirname(url)
            return path
        else:
            path = self._cwd(url)
            if (not path or path == '/') and self.created_from_url:
                path = self._cwd(self.created_from_url)

        if path == '/':
            path = wx.StandardPaths.Get().GetDocumentsDir()
        return path
Пример #6
0
 def __init__(self, url):
     self.project_settings_dir = url
     self.project_top_dir = vfs.get_dirname(url)
     self.project_config = None
     self.loadPrefs()
     self.loadTags()
     self.process = None
Пример #7
0
 def cwd(self, use_vfs=False):
     """Find the current working directory of the buffer.
     
     Can be used in two ways based on use_vfs:
     
     use_vfs == True: uses the vfs to return the directory in the same
     scheme as the buffer
     
     use_vfs == False (the default): find the current working directory
     on the local filesystem.  Some schemes, like tar, for instance, are
     overlays on the current filesystem and the cwd of those schemes with
     this sense of use_vfs will report the overlayed directory.
     """
     if self.pending_url is not None:
         url = self.pending_url
     else:
         url = self.url
     if use_vfs:
         if vfs.is_folder(url):
             path = vfs.normalize(url)
         else:
             path = vfs.get_dirname(url)
         return path
     else:
         path = self._cwd(url)
         if (not path or path == '/') and self.created_from_url:
             path = self._cwd(self.created_from_url)
     
     if path == '/':
         path = wx.StandardPaths.Get().GetDocumentsDir()
     return path
Пример #8
0
    def completePath(self, text, uri, path):
        paths = []
        if '/' in path:
            if path.endswith('/'):
                # It's already a directory
                uridir = uri
                pattern = ''
            else:
                # The stuff after the last slash is the pattern to match
                uridir, pattern = path.rsplit('/', 1)
                uridir = vfs.get_dirname(uri)
        elif path == '.':
            # Needed to handle protocols that don't use leading slashes
            uridir = uri
            pattern = ''
        else:
            uridir = vfs.get_dirname(uri)
            pattern = path

        self.dprint('dir=%s pattern=%s' % (uridir, pattern))
        try:
            for name in vfs.get_names(uridir):
                if not name.startswith(pattern):
                    self.dprint(
                        "skipping %s because it doesn't start with %s" %
                        (name, pattern))
                    continue
                uri = uridir.resolve2(name)
                path = str(uri)
                if vfs.is_folder(uri) and not path.endswith('/'):
                    path += '/'
                self.dprint(path)
                paths.append(path)
        except vfs.AuthenticationCancelled:
            pass
        return paths
Пример #9
0
 def test_dirname(self):
     base = vfs.get_reference('stuff/blah')
     uri = vfs.get_dirname(base)
     self.assertEqual('stuff/', uri.path)
     uri = vfs.get_dirname(uri)
     print "path=%s" % uri.path
     self.assertEqual('./', uri.path)
     base = vfs.get_reference('/stuff/blah/')
     uri = vfs.get_dirname(base)
     self.assertEqual('/stuff/', uri.path)
     uri = vfs.get_dirname(uri)
     print "path=%s" % uri.path
     self.assertEqual('/', uri.path)
     base = vfs.get_reference('file:///stuff/blah/')
     uri = vfs.get_dirname(base)
     print "path=%s" % uri.path
     self.assertEqual('/stuff/', uri.path)
     uri = vfs.get_dirname(uri)
     print "path=%s" % uri.path
     self.assertEqual('/', uri.path)
Пример #10
0
 def test_dirname(self):
     base = vfs.get_reference('stuff/blah')
     uri = vfs.get_dirname(base)
     self.assertEqual('stuff/', uri.path)
     uri = vfs.get_dirname(uri)
     print "path=%s" % uri.path
     self.assertEqual('./', uri.path)
     base = vfs.get_reference('/stuff/blah/')
     uri = vfs.get_dirname(base)
     self.assertEqual('/stuff/', uri.path)
     uri = vfs.get_dirname(uri)
     print "path=%s" % uri.path
     self.assertEqual('/', uri.path)
     base = vfs.get_reference('file:///stuff/blah/')
     uri = vfs.get_dirname(base)
     print "path=%s" % uri.path
     self.assertEqual('/stuff/', uri.path)
     uri = vfs.get_dirname(uri)
     print "path=%s" % uri.path
     self.assertEqual('/', uri.path)
Пример #11
0
 def calculateFilename(self, url):
     dirname = vfs.get_dirname(url)
     filename = vfs.get_filename(url)
     filename = "%s~" % filename
     return dirname.resolve2(filename)
Пример #12
0
 def getFilename(self, original_url):
     if self.classprefs.use_autosave and self.isFilesystemSchemeAllowed(original_url):
         dirname = vfs.get_dirname(original_url)
         filename = vfs.get_filename(original_url)
         filename = "%%23%s%%23" % filename
         return dirname.resolve2(filename)
Пример #13
0
 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