Example #1
0
 def test10_creation(self):
     file = vfs.make_file(self.root + 'testfile.txt')
     file.write("one\n")
     file.close()
     self.assertEqual(vfs.is_file(self.root + 'testfile.txt'), True)
     
     url = self.root + 'tmp/dir'
     vfs.make_folder(url)
     self.assertEqual(vfs.is_folder(url), True)
     
     url = self.root + 'tmp/dir/file1'
     fh = vfs.make_file(url)
     fh.write("this is file1")
     fh.close()
     self.assertEqual(vfs.is_file(url), True)
     
     url = self.root + 'tmp/dir/zero'
     fh = vfs.make_file(url)
     fh.close()
     self.assertEqual(vfs.is_file(url), True)
     
     # this should raise an OSError because it's trying to make a file out
     # of an existing folder
     url = self.root + 'tmp/dir'
     self.assertRaises(OSError, vfs.make_file, url)
     
     # this should raise an OSError because it's trying to make a file in
     # another file
     url = self.root + 'tmp/dir/file1/file2'
     self.assertRaises(OSError, vfs.make_file, url)
Example #2
0
 def test10_creation(self):
     file = vfs.make_file(self.root + 'testfile.txt')
     file.write("one\n")
     file.close()
     self.assertEqual(vfs.is_file(self.root + 'testfile.txt'), True)
     
     url = self.root + 'tmp/dir'
     vfs.make_folder(url)
     self.assertEqual(vfs.is_folder(url), True)
     
     url = self.root + 'tmp/dir/file1'
     fh = vfs.make_file(url)
     fh.write("this is file1")
     fh.close()
     self.assertEqual(vfs.is_file(url), True)
     
     url = self.root + 'tmp/dir/zero'
     fh = vfs.make_file(url)
     fh.close()
     self.assertEqual(vfs.is_file(url), True)
     
     # this should raise an OSError because it's trying to make a file out
     # of an existing folder
     url = self.root + 'tmp/dir'
     self.assertRaises(OSError, vfs.make_file, url)
     
     # this should raise an OSError because it's trying to make a file in
     # another file
     url = self.root + 'tmp/dir/file1/file2'
     self.assertRaises(OSError, vfs.make_file, url)
Example #3
0
 def test01_type_checking(self):
     is_file = vfs.is_file(self.root + 'README')
     self.assertEqual(is_file, True)
     is_file = vfs.is_file(self.root)
     self.assertEqual(is_file, False)
     is_folder = vfs.is_folder(self.root)
     self.assertEqual(is_folder, True)
     is_folder = vfs.is_folder(self.root + 'README')
     self.assertEqual(is_folder, False)
Example #4
0
 def test01_type_checking(self):
     is_file = vfs.is_file(self.root + 'README')
     self.assertEqual(is_file, True)
     is_file = vfs.is_file(self.root)
     self.assertEqual(is_file, False)
     is_folder = vfs.is_folder(self.root)
     self.assertEqual(is_folder, True)
     is_folder = vfs.is_folder(self.root + 'README')
     self.assertEqual(is_folder, False)
Example #5
0
 def test01_type_checking(self):
     self.assertEqual(True, vfs.is_file('file:vfs/sample.tar.bz2'))
     self.assertEqual(False, vfs.is_file('tar:vfs/sample.tar.bz2'))
     self.assertEqual(True, vfs.is_folder('tar:vfs/sample.tar.bz2'))
     self.assertEqual(True, vfs.is_folder('tar:vfs/sample.tar.bz2/'))
     self.assertEqual(True, vfs.is_file('tar:vfs/sample.tar.bz2/small.py'))
     self.assertEqual(True, vfs.is_folder('tar:vfs/sample.tar.bz2/dir1/'))
     self.assertEqual(True, vfs.is_file('tar:vfs/sample.tar.bz2/dir1/hello1.txt'))
     self.assertEqual(True, vfs.is_file('tar:vfs/sample.tar.gz/dir1/hello1.txt'))
     self.assertEqual(True, vfs.is_folder('tar:vfs/sample.tar.bz2/dir1/dir2'))
Example #6
0
 def test01_type_checking(self):
     is_file = vfs.is_file('mem:tmp/blah.txt')
     self.assertEqual(is_file, True)
     is_file = vfs.is_file('mem:tmp')
     self.assertEqual(is_file, False)
     is_folder = vfs.is_folder('mem:tmp')
     self.assertEqual(is_folder, True)
     is_folder = vfs.is_folder('mem:tmp/blah.txt')
     self.assertEqual(is_folder, False)
     mimetype = vfs.get_mimetype('mem:tmp/blah.txt')
     self.assertEqual(mimetype, 'text/plain')
Example #7
0
 def test01_type_checking(self):
     is_file = vfs.is_file(self.root + 'tmp/blah.txt')
     self.assertEqual(is_file, True)
     is_file = vfs.is_file(self.root + 'tmp')
     self.assertEqual(is_file, False)
     is_folder = vfs.is_folder(self.root + 'tmp')
     self.assertEqual(is_folder, True)
     is_folder = vfs.is_folder(self.root + 'tmp/blah.txt')
     self.assertEqual(is_folder, False)
     mimetype = vfs.get_mimetype(self.root + 'tmp/blah.txt')
     self.assertEqual(mimetype, 'text/plain')
Example #8
0
 def test01_type_checking(self):
     is_file = vfs.is_file(self.root + "tmp/blah.txt")
     self.assertEqual(is_file, True)
     is_file = vfs.is_file(self.root + "tmp")
     self.assertEqual(is_file, False)
     is_folder = vfs.is_folder(self.root + "tmp")
     self.assertEqual(is_folder, True)
     is_folder = vfs.is_folder(self.root + "tmp/blah.txt")
     self.assertEqual(is_folder, False)
     mimetype = vfs.get_mimetype(self.root + "tmp/blah.txt")
     self.assertEqual(mimetype, "text/plain")
Example #9
0
 def getMacroNamesFromMajorModeClass(cls, modecls):
     """Get the list of macro names available for the specified major mode
     class.
     
     This is roughly equivalent to using C{vfs.get_names("macro:%s" %
     mode.keyword)} except that it also handles the case of universal
     macros linked to the abstract L{MajorMode} that are in the macro
     directory "".
     
     @param modecls: major mode class
     
     @returns: tuple containing the path in the macro: filesystem and the
     list of all macros in that path
     """
     keyword = modecls.keyword
     if keyword == "Abstract_Major_Mode":
         path = ""
     else:
         path = keyword
     try:
         all_names = vfs.get_names("macro:%s" % path)
     except OSError:
         all_names = []
     
     # Check to see that all the names are macro names and not directories
     macro_names = []
     for name in all_names:
         url = "macro:" + path + "/" + name
         if vfs.is_file(url):
             macro_names.append(name)
     return path, macro_names
Example #10
0
 def identifyall(cls, url):
     cls.discover()
     
     cls.dprint("handlers: %s" % cls.handlers)
     matches = []
     if vfs.is_file(url):
         for format in cls.handlers:
             cls.dprint("checking %s for %s format" % (url, format.format_name))
             if format.identify(url):
                 cls.dprint("Possible match for %s format" % format.format_name)
                 matches.append(format)
     order = []
     for match in matches:
         # It is possible that the file can be loaded as more than
         # one format.  For instance, GDAL supports a bunch of
         # formats, but custom classes can be written to be more
         # efficient than GDAL.  So, loop through the matches and
         # see if there is a specific class that should be used
         # instead of a generic one.
         cls.dprint("Checking %s for specific support of %s" % (match, url))
         name, ext = os.path.splitext(url.path.get_name())
         ext.lower()
         if ext in match.extensions:
             cls.dprint("Found specific support for %s in %s" % (ext, match))
             order.append(match)
             matches.remove(match)
     if len(matches)>0:
         order.extend(matches)
     return order
Example #11
0
    def identifyall(cls, url):
        cls.discover()

        cls.dprint("handlers: %s" % cls.handlers)
        matches = []
        if vfs.is_file(url):
            for format in cls.handlers:
                cls.dprint("checking %s for %s format" %
                           (url, format.format_name))
                if format.identify(url):
                    cls.dprint("Possible match for %s format" %
                               format.format_name)
                    matches.append(format)
        order = []
        for match in matches:
            # It is possible that the file can be loaded as more than
            # one format.  For instance, GDAL supports a bunch of
            # formats, but custom classes can be written to be more
            # efficient than GDAL.  So, loop through the matches and
            # see if there is a specific class that should be used
            # instead of a generic one.
            cls.dprint("Checking %s for specific support of %s" % (match, url))
            name, ext = os.path.splitext(url.path.get_name())
            ext.lower()
            if ext in match.extensions:
                cls.dprint("Found specific support for %s in %s" %
                           (ext, match))
                order.append(match)
                matches.remove(match)
        if len(matches) > 0:
            order.extend(matches)
        return order
Example #12
0
 def isEnabled(self):
     # As long as at least one item in the list is a macro, this can be
     # enabled.
     macros = self.popup_options['macros']
     for path in self.popup_options['macros']:
         if vfs.is_file(path):
             return True
     return False
Example #13
0
 def save(self,filename=None):
     if filename:
         url = vfs.normalize(filename)
         if vfs.is_file(url):
             fh = vfs.open(url, vfs.WRITE)
         else:
             fh = vfs.make_file(url)
         if fh:
             fh.write(str(self))
             fh.close()
         else:
             eprint("Couldn't open %s for writing.\n" % filename)
Example #14
0
 def save(self, filename=None):
     if filename:
         url = vfs.normalize(filename)
         if vfs.is_file(url):
             fh = vfs.open(url, vfs.WRITE)
         else:
             fh = vfs.make_file(url)
         if fh:
             fh.write(str(self))
             fh.close()
         else:
             eprint("Couldn't open %s for writing.\n" % filename)
Example #15
0
 def appendItems(self, wxParent, path, names):
     """Append the macro names to the specified item
     
     For the initial item highlighing, uses the current_line instance
     attribute to determine the line number.
     """
     names.sort()
     for name in names:
         if path:
             fullpath = path + "/" + name
         else:
             fullpath = name
         url = "macro:" + fullpath
         if vfs.is_file(url):
             text = self.getTextForMacroName(fullpath, name)
             wxItem = self.AppendItem(wxParent, text)
             self.SetPyData(wxItem, fullpath)
Example #16
0
 def addMacro(cls, macro, dirname=None):
     if dirname:
         if not dirname.endswith("/"):
             dirname += "/"
         
         # Make sure the directory exists
         url = vfs.normalize("macro:%s" % dirname)
         needs_mkdir = False
         if vfs.exists(url):
             if vfs.is_file(url):
                 # we have a macro that is the same name as the directory
                 # name.  Rename the file and create the directory.
                 components = dirname.strip('/').split('/')
                 filename = components.pop()
                 parent_dirname = "/".join(components)
                 dum, new_filename = cls.findAlternateName(parent_dirname, filename)
                 #dprint("parent=%s filename=%s: New filename: %s" % (parent_dirname, filename, new_filename))
                 parent, existing, name = cls._find(parent_dirname)
                 #dprint("existing=%s" % existing)
                 existing[new_filename] = existing[filename]
                 del existing[filename]
                 #dprint("existing after=%s" % existing)
                 needs_mkdir = True
         else:
             needs_mkdir = True
         if needs_mkdir:
             #dprint("Making folder %s" % url)
             vfs.make_folder(url)
     else:
         dirname = ""
     fullpath, basename = cls.findAlternateName(dirname, macro.name)
     
     parent, existing, name = cls._find(dirname)
     #dprint("name=%s: parent=%s, existing=%s" % (basename, parent, existing))
     macro.setName(fullpath)
     existing[basename] = macro
Example #17
0
 def test02_is_file(self):
     is_file = vfs.is_file('vfs/hello.txt')
     self.assertEqual(is_file, True)
Example #18
0
 def isEnabled(self):
     macros = self.popup_options['macros']
     return len(macros) == 1 and vfs.is_file(macros[0])
Example #19
0
 def test02_test_url(self):
     is_file = vfs.is_file('mem:tmp/blah.txt#fragment')
     self.assertEqual(is_file, True)
     is_file = vfs.is_file('mem:tmp/blah.txt?fragment')
     self.assertEqual(is_file, True)
Example #20
0
 def test03_is_not_file(self):
     is_file = vfs.is_file('vfs')
     self.assertEqual(is_file, False)
Example #21
0
 def test06_make_file(self):
     vfs.make_file('vfs/file')
     self.assertEqual(vfs.is_file('vfs/file'), True)
Example #22
0
 def test02_is_file(self):
     is_file = vfs.is_file('vfs/hello.txt')
     self.assertEqual(is_file, True)
Example #23
0
 def isEnabled(self):
     macros = self.popup_options['macros']
     for path in self.popup_options['macros']:
         if vfs.is_file(path):
             return True
     return False
Example #24
0
 def test06_make_file(self):
     vfs.make_file('vfs/file')
     self.assertEqual(vfs.is_file('vfs/file'), True)
Example #25
0
 def test03_is_not_file(self):
     is_file = vfs.is_file('vfs')
     self.assertEqual(is_file, False)
Example #26
0
 def test02_test_url(self):
     is_file = vfs.is_file('mem:tmp/blah.txt#fragment')
     self.assertEqual(is_file, True)
     is_file = vfs.is_file('mem:tmp/blah.txt?fragment')
     self.assertEqual(is_file, True)