Beispiel #1
0
 def test22_copy_folder(self):
     vfs.copy('vfs', 'mem:/tmp/folder-copy')
     with vfs.open('mem:/tmp/folder-copy/hello.txt') as file:
         self.assertEqual(file.read(), 'hello world\n')
     vfs.make_folder('mem:/tmp/folder-dest')
     vfs.copy('vfs', 'mem:/tmp/folder-dest')
     with vfs.open('mem:/tmp/folder-dest/vfs/hello.txt') as file:
         self.assertEqual(file.read(), 'hello world\n')
Beispiel #2
0
 def test22_copy_folder(self):
     vfs.copy('vfs', 'mem:/tmp/folder-copy')
     with vfs.open('mem:/tmp/folder-copy/hello.txt') as file:
         self.assertEqual(file.read(), 'hello world\n')
     vfs.make_folder('mem:/tmp/folder-dest')
     vfs.copy('vfs', 'mem:/tmp/folder-dest')
     with vfs.open('mem:/tmp/folder-dest/vfs/hello.txt') as file:
         self.assertEqual(file.read(), 'hello world\n')
Beispiel #3
0
 def test21_copy_file(self):
     url = self.root + 'tmp/dir/'
     vfs.make_folder(url)
     vfs.copy(self.root + 'tmp/blah.txt', url)
     file = vfs.open(url + 'blah.txt')
     self.assertEqual(file.read(), 'BLAH!!!')
     vfs.copy(self.root + 'tmp/blah.txt', url + 'blah2.txt')
     file = vfs.open(url + 'blah2.txt')
     self.assertEqual(file.read(), 'BLAH!!!')
Beispiel #4
0
 def test21_copy_file(self):
     url = self.root + "tmp/dir/"
     vfs.make_folder(url)
     vfs.copy(self.root + "tmp/blah.txt", url)
     file = vfs.open(url + "blah.txt")
     self.assertEqual(file.read(), "BLAH!!!")
     vfs.copy(self.root + "tmp/blah.txt", url + "blah2.txt")
     file = vfs.open(url + "blah2.txt")
     self.assertEqual(file.read(), "BLAH!!!")
Beispiel #5
0
 def test21_copy_file(self):
     url = self.root + 'tmp/dir/'
     vfs.make_folder(url)
     vfs.copy(self.root + 'tmp/blah.txt', url)
     file = vfs.open(url + 'blah.txt')
     self.assertEqual(file.read(), 'BLAH!!!')
     vfs.copy(self.root + 'tmp/blah.txt', url + 'blah2.txt')
     file = vfs.open(url + 'blah2.txt')
     self.assertEqual(file.read(), 'BLAH!!!')
Beispiel #6
0
 def test12_append(self):
     file = vfs.open('mem:testfile.txt', vfs.APPEND)
     file.write("two\n")
     file.close()
     file = vfs.open('mem:testfile.txt')
     self.assertEqual(file.read(), 'one\ntwo\n')
     file = vfs.open('mem:testfile.txt', vfs.WRITE)
     file.write("three\n")
     file.close()
     file = vfs.open('mem:testfile.txt')
     self.assertEqual(file.read(), 'three\n')
Beispiel #7
0
 def test12_append(self):
     file = vfs.open('mem:testfile.txt', vfs.APPEND)
     file.write("two\n")
     file.close()
     file = vfs.open('mem:testfile.txt')
     self.assertEqual(file.read(), 'one\ntwo\n')
     file = vfs.open('mem:testfile.txt', vfs.WRITE)
     file.write("three\n")
     file.close()
     file = vfs.open('mem:testfile.txt')
     self.assertEqual(file.read(), 'three\n')
Beispiel #8
0
 def test12_append(self):
     file = vfs.make_file(self.root + "testfile.txt")
     file.write("one\n")
     file.close()
     file = vfs.open(self.root + "testfile.txt", vfs.APPEND)
     file.write("two\n")
     file.close()
     file = vfs.open(self.root + "testfile.txt")
     self.assertEqual(file.read(), "one\ntwo\n")
     file = vfs.open(self.root + "testfile.txt", vfs.WRITE)
     file.write("three\n")
     file.close()
     file = vfs.open(self.root + "testfile.txt")
     self.assertEqual(file.read(), "three\n")
Beispiel #9
0
 def getFilePair(cls, url):
     fh = vfs.open(url)
     line = fh.read(4)
     if line == 'ENVI':
         # need to open the cube, not the header
         return (url, None)
     fh.close()
     headers = findHeaders(url)
     for header in headers:
         fh = vfs.open(header)
         line = fh.read(4)
         if line == 'ENVI':
             return (header, url)
         fh.close()
     return None
Beispiel #10
0
 def getFilePair(cls, url):
     fh = vfs.open(url)
     line=fh.read(4)
     if line=='ENVI':
         # need to open the cube, not the header
         return (url, None)
     fh.close()
     headers = findHeaders(url)
     for header in headers:
         fh = vfs.open(header)
         line=fh.read(4)
         if line=='ENVI':
             return (header, url)
         fh.close()
     return None
Beispiel #11
0
    def applyProjectSettings(cls, msg):
        """Publish/subscribe callback to load project view settings.
        
        This is called by the major mode loading process to set the default
        view parameters based on per-project defaults.
        """
        mode = msg.data
        if not mode.project_info:
            return

        cls.dprint("Applying settings for %s" % mode)
        # Add 'project' keyword to Buffer object if the file belongs to a
        # project
        settings = cls.findProjectConfigObject(mode, cls.classprefs.settings_directory)
        if not settings:
            # Try the global settings
            cls.dprint("Trying default settings for project %s" % mode.project_info.project_name)
            base = mode.project_info.getSettingsRelativeURL()
            url = base.resolve2(ProjectPlugin.classprefs.default_settings_file_name)
            if vfs.exists(url):
                fh = vfs.open(url)
                settings = pickle.load(fh)
                fh.close()
        if settings and isinstance(settings, dict):
            # dprint(settings)
            # mode.applyFileLocalComments(settings)
            mode.classprefsUpdateLocals(settings)
            mode.applyDefaultSettings()
Beispiel #12
0
 def getConfigFileHandle(cls, confdir, mode, url):
     """Get a file handle to data in the project's configuration directory.
     
     Files within the configuration directory should be based on the major
     mode name, and optionally for added specificity can append a filename
     extension.
     
     For instance, the template system used for projects uses the
     "$PROJROOT/.peppy- project/templates" directory by default, where
     $PROJROOT is the root directory of the project.  Within that templates
     directory, the file "Python" is the default for python files, but
     "Python.pyx" could be used as a default for pyrex files.
     
     @param confdir: pathname of configuration directory
     @param mode: major mode instance
     @param url: url of file that is being created
     
     @return: file-like object to read the data, or None if not found
     """
     filename = vfs.get_filename(url)
     names = []
     if "." in filename:
         ext = filename.split(".")[-1]
         names.append(confdir.resolve2("%s.%s" % (mode.keyword, ext)))
     names.append(confdir.resolve2(mode.keyword))
     for configname in names:
         try:
             cls.dprint("Trying to load file %s" % configname)
             fh = vfs.open(configname)
             return fh
         except:
             pass
     return None
Beispiel #13
0
 def identify(cls, url, filename=None):
     fh = vfs.open(url)
     line=fh.read(160)
     cls.dprint(repr(line))
     if line[0:30] =='SIMPLE  =                    T' and line[80:90] == 'BITPIX  = ':
         return True
     return False
Beispiel #14
0
 def test20_move_file(self):
     vfs.copy(self.root + 'tmp/blah.txt', self.root + 'tmp/blah.txt.bak')
     vfs.move(self.root + 'tmp/blah.txt.bak',
              self.root + 'tmp/blah.txt.old')
     file = vfs.open(self.root + 'tmp/blah.txt.old')
     self.assertEqual(file.read(), 'BLAH!!!')
     self.assertEqual(vfs.exists(self.root + 'tmp/blah.txt.bak'), False)
Beispiel #15
0
    def applyProjectSettings(cls, msg):
        """Publish/subscribe callback to load project view settings.
        
        This is called by the major mode loading process to set the default
        view parameters based on per-project defaults.
        """
        mode = msg.data
        if not mode.project_info:
            return

        cls.dprint("Applying settings for %s" % mode)
        # Add 'project' keyword to Buffer object if the file belongs to a
        # project
        settings = cls.findProjectConfigObject(
            mode, cls.classprefs.settings_directory)
        if not settings:
            # Try the global settings
            cls.dprint("Trying default settings for project %s" %
                       mode.project_info.project_name)
            base = mode.project_info.getSettingsRelativeURL()
            url = base.resolve2(
                ProjectPlugin.classprefs.default_settings_file_name)
            if vfs.exists(url):
                fh = vfs.open(url)
                settings = pickle.load(fh)
                fh.close()
        if settings and isinstance(settings, dict):
            #dprint(settings)
            #mode.applyFileLocalComments(settings)
            mode.classprefsUpdateLocals(settings)
            mode.applyDefaultSettings()
Beispiel #16
0
 def getConfigFileHandle(cls, confdir, mode, url):
     """Get a file handle to data in the project's configuration directory.
     
     Files within the configuration directory should be based on the major
     mode name, and optionally for added specificity can append a filename
     extension.
     
     For instance, the template system used for projects uses the
     "$PROJROOT/.peppy- project/templates" directory by default, where
     $PROJROOT is the root directory of the project.  Within that templates
     directory, the file "Python" is the default for python files, but
     "Python.pyx" could be used as a default for pyrex files.
     
     @param confdir: pathname of configuration directory
     @param mode: major mode instance
     @param url: url of file that is being created
     
     @return: file-like object to read the data, or None if not found
     """
     filename = vfs.get_filename(url)
     names = []
     if '.' in filename:
         ext = filename.split('.')[-1]
         names.append(confdir.resolve2("%s.%s" % (mode.keyword, ext)))
     names.append(confdir.resolve2(mode.keyword))
     for configname in names:
         try:
             cls.dprint("Trying to load file %s" % configname)
             fh = vfs.open(configname)
             return fh
         except:
             pass
     return None
Beispiel #17
0
 def identify(cls, url, filename=None):
     fh = vfs.open(url)
     line = fh.read(160)
     cls.dprint(repr(line))
     if line[0:30] == 'SIMPLE  =                    T' and line[
             80:90] == 'BITPIX  = ':
         return True
     return False
Beispiel #18
0
 def save(self, filename=None):
     if filename:
         fh = vfs.open(filename, vfs.WRITE)
         if fh:
             self.parser.write(fh)
             fh.close()
             self.setURL(filename)
         else:
             eprint("Couldn't save %s\n" % filename)
Beispiel #19
0
 def getBufferedReader(self, size=1024):
     assert self.dprint(u"opening %s as %s" % (self.url, self.defaultmode))
     if self.bfh is None:
         if vfs.exists(self.url):
             fh = vfs.open(self.url)
             self.bfh = BufferedReader(fh, size)
     if self.bfh:
         self.bfh.seek(0)
     return self.bfh
Beispiel #20
0
 def save(self,filename=None):
     if filename:
         fh = vfs.open(filename, vfs.WRITE)
         if fh:
             self.parser.write(fh)
             fh.close()
             self.setURL(filename)
         else:
             eprint("Couldn't save %s\n" % filename)
Beispiel #21
0
 def open(self,filename=None):
     """Open the header file, and if successful parse it."""
     if self.headerurl:
         fh = vfs.open(self.headerurl)
         if fh:
             self.read(fh)
             fh.close()
         else:
             eprint("Couldn't open %s for reading.\n" % self.headerurl)
Beispiel #22
0
 def getBufferedReader(self, size=1024):
     assert self.dprint(u"opening %s as %s" % (self.url, self.defaultmode))
     if self.bfh is None:
         if vfs.exists(self.url):
             fh = vfs.open(self.url)
             self.bfh = BufferedReader(fh, size)
     if self.bfh:
         self.bfh.seek(0)
     return self.bfh
Beispiel #23
0
 def open(self, filename=None):
     """Open the header file, and if successful parse it."""
     if self.headerurl:
         fh = vfs.open(self.headerurl)
         if fh:
             self.read(fh)
             fh.close()
         else:
             eprint("Couldn't open %s for reading.\n" % self.headerurl)
Beispiel #24
0
 def test20_append(self):
     # Initialize
     with vfs.make_file('vfs/toto.txt') as file:
         file.write('hello\n')
     # Test
     with vfs.open('vfs/toto.txt', vfs.APPEND) as file:
         file.write('bye\n')
     self.assertEqual(open('vfs/toto.txt').read(), 'hello\nbye\n')
     # Remove temporary file
     vfs.remove('vfs/toto.txt')
Beispiel #25
0
 def test20_append(self):
     # Initialize
     with vfs.make_file('vfs/toto.txt') as file:
         file.write('hello\n')
     # Test
     with vfs.open('vfs/toto.txt', vfs.APPEND) as file:
         file.write('bye\n')
     self.assertEqual(open('vfs/toto.txt').read(), 'hello\nbye\n')
     # Remove temporary file
     vfs.remove('vfs/toto.txt')
Beispiel #26
0
 def test21_write(self):
     # Initialize
     with vfs.make_file('vfs/truncate.txt') as file:
         file.write('hello there\n')
     # Test
     with vfs.open('vfs/truncate.txt', vfs.WRITE) as file:
         file.write('bye\n')
     self.assertEqual(open('vfs/truncate.txt').read(), 'bye\n')
     # Remove temporary file
     vfs.remove('vfs/truncate.txt')
Beispiel #27
0
 def test21_write(self):
     # Initialize
     with vfs.make_file('vfs/truncate.txt') as file:
         file.write('hello there\n')
     # Test
     with vfs.open('vfs/truncate.txt', vfs.WRITE) as file:
         file.write('bye\n')
     self.assertEqual(open('vfs/truncate.txt').read(), 'bye\n')
     # Remove temporary file
     vfs.remove('vfs/truncate.txt')
Beispiel #28
0
 def identify(cls, url):
     fh = vfs.open(url)
     assert cls.dprint("checking for cube handler: %s" % dir(fh))
     if fh and hasattr(fh, 'metadata') and hasattr(fh.metadata, 'getCube'):
         return fh.metadata
         
     url = vfs.normalize(url)
     matches = cls.identifyall(url)
     if len(matches)>0:
         return matches[0]
     return None
Beispiel #29
0
    def identify(cls, url):
        fh = vfs.open(url)
        assert cls.dprint("checking for cube handler: %s" % dir(fh))
        if fh and hasattr(fh, 'metadata') and hasattr(fh.metadata, 'getCube'):
            return fh.metadata

        url = vfs.normalize(url)
        matches = cls.identifyall(url)
        if len(matches) > 0:
            return matches[0]
        return None
Beispiel #30
0
    def open(self, url=None):
        """Open the header file, and if successful parse it."""
        if url:
            self.setURL(url)

        if self.url:
            #fh=self.url.getReader()
            fh = vfs.open(self.url)
            if fh:
                self.read(fh)
                fh.close()
Beispiel #31
0
    def open(self, url=None):
        """Open the header file, and if successful parse it."""
        if url:
            self.setURL(url)

        if self.url:
            #fh=self.url.getReader()
            fh = vfs.open(self.url)
            if fh:
                self.read(fh)
                fh.close()
Beispiel #32
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)
Beispiel #33
0
 def loadPrefs(self):
     self.project_config = self.project_settings_dir.resolve2(ProjectPlugin.classprefs.project_file)
     try:
         fh = vfs.open(self.project_config)
         if fh:
             self.readConfig(fh)
         for param in self.iterPrefs():
             self.dprint("%s = %s" % (param.keyword, getattr(self, param.keyword)))
         self.dprint(self.configToText())
     except LookupError:
         self.dprint("Project file not found -- using defaults.")
         self.setDefaultPrefs()
Beispiel #34
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)
Beispiel #35
0
    def action(self, index=-1, multiplier=1):
        stylesheet = wx.GetApp().fonts.getStyleFile()
        dlg = PeppyStyleEditor(self.frame, -1)
        self.setSampleText(dlg)
        retval = dlg.ShowModal()
        if retval == wx.ID_OK:
            # Find style name from controls within the dialog
            ctrl = dlg.FindWindowById(style_editor.ed_glob.ID_PREF_SYNTHEME)
            tag = ctrl.GetStringSelection()
            ctrl = dlg.FindWindowById(wx.ID_NEW)
            if ctrl.GetValue():
                tag = "untitled"
            dlg2 = wx.TextEntryDialog(
                self.frame,
                caption="Save Style Sheet",
                message=
                "Enter name for style sheet.\n\nThis style sheet must be saved in your personal\nconfiguration directory before it can be used.\n\nIf you cancel, the style sheet changes will be lost.",
                defaultValue=tag,
                style=wx.OK | wx.CANCEL)
            retval = dlg2.ShowModal()
            tag = dlg2.GetValue()
            if not tag:
                tag = "untitled"
            dlg2.Destroy()

            if retval == wx.ID_OK:
                #dprint("Saving style to %s" % tag)
                filename = wx.GetApp().fonts.getStylePath(tag)

                styles = ed_style.MergeStyles(
                    dlg.preview.BlankStyleDictionary(), dlg.styles_new)
                dlg.preview.SetStyles(filename, styles, True)
                EditraSTCMixin.global_style_set = filename
                sheet = dlg.GenerateStyleSheet()
                #dprint(sheet)
                fh = open(filename, 'wb')
                fh.write(sheet)
                wx.GetApp().fonts.classprefs.editra_style_theme = tag
                Publisher().sendMessage('peppy.preferences.changed')
        elif retval == wx.ID_SAVE:
            dprint("Save!")
            sheet = dlg.GenerateStyleSheet()
            dprint(sheet)
            self.export_count += 1
            url = "mem:///style-sheet-%d.ess" % self.export_count
            fh = vfs.make_file(url)
            fh.write(sheet)
            fh.close()
            fh = vfs.open(url)
            dprint(fh.read())
            self.frame.open(url)
        dlg.Destroy()
Beispiel #36
0
 def loadPrefs(self):
     self.project_config = self.project_settings_dir.resolve2(
         ProjectPlugin.classprefs.project_file)
     try:
         fh = vfs.open(self.project_config)
         if fh:
             self.readConfig(fh)
         for param in self.iterPrefs():
             self.dprint("%s = %s" %
                         (param.keyword, getattr(self, param.keyword)))
         self.dprint(self.configToText())
     except LookupError:
         self.dprint("Project file not found -- using defaults.")
         self.setDefaultPrefs()
Beispiel #37
0
    def action(self, index=-1, multiplier=1):
        stylesheet = wx.GetApp().fonts.getStyleFile()
        dlg = PeppyStyleEditor(self.frame, -1)
        self.setSampleText(dlg)
        retval = dlg.ShowModal()
        if retval == wx.ID_OK:
            # Find style name from controls within the dialog
            ctrl = dlg.FindWindowById(style_editor.ed_glob.ID_PREF_SYNTHEME)
            tag = ctrl.GetStringSelection()
            ctrl = dlg.FindWindowById(wx.ID_NEW)
            if ctrl.GetValue():
                tag = "untitled"
            dlg2 = wx.TextEntryDialog(
                self.frame, caption="Save Style Sheet", message="Enter name for style sheet.\n\nThis style sheet must be saved in your personal\nconfiguration directory before it can be used.\n\nIf you cancel, the style sheet changes will be lost.", defaultValue=tag,
                style=wx.OK|wx.CANCEL)
            retval = dlg2.ShowModal()
            tag = dlg2.GetValue()
            if not tag:
                tag = "untitled"
            dlg2.Destroy()
            
            if retval == wx.ID_OK:
                #dprint("Saving style to %s" % tag)
                filename = wx.GetApp().fonts.getStylePath(tag)

                styles = ed_style.MergeStyles(dlg.preview.BlankStyleDictionary(), dlg.styles_new)
                dlg.preview.SetStyles(filename, styles, True)
                EditraSTCMixin.global_style_set = filename
                sheet = dlg.GenerateStyleSheet()
                #dprint(sheet)
                fh = open(filename, 'wb')
                fh.write(sheet)
                wx.GetApp().fonts.classprefs.editra_style_theme = tag
                Publisher().sendMessage('peppy.preferences.changed')
        elif retval == wx.ID_SAVE:
            dprint("Save!")
            sheet = dlg.GenerateStyleSheet()
            dprint(sheet)
            self.export_count += 1
            url = "mem:///style-sheet-%d.ess" % self.export_count
            fh = vfs.make_file(url)
            fh.write(sheet)
            fh.close()
            fh = vfs.open(url)
            dprint(fh.read())
            self.frame.open(url)
        dlg.Destroy()
Beispiel #38
0
 def revertEncoding(self,
                    buffer,
                    url=None,
                    message=None,
                    encoding=None,
                    allow_undo=False):
     if url is None:
         url = buffer.url
     fh = vfs.open(url)
     if allow_undo:
         self.BeginUndoAction()
     self.ClearAll()
     self.readThreaded(fh, buffer, message)
     self.openSuccess(buffer, encoding=encoding)
     if allow_undo:
         self.EndUndoAction()
     else:
         self.EmptyUndoBuffer()
Beispiel #39
0
 def load(cls, url):
     import cPickle as pickle
     
     # Note: because plugins are loaded using the execfile command, pickle
     # can't find classes that are in the global namespace.  Have to supply
     # PythonScriptableMacro into the builtin namespace to get around this.
     import __builtin__
     __builtin__.PythonScriptableMacro = PythonScriptableMacro
     
     if not vfs.exists(url):
         return
     
     fh = vfs.open(url)
     bytes = fh.read()
     fh.close()
     if bytes:
         version, data = pickle.loads(bytes)
         if version == 1:
             cls.unpackVersion1(data)
         else:
             raise RuntimeError("Unknown version of MacroSaveData in %s" % url)
Beispiel #40
0
 def load(cls, url, bad=None, progress=None):
     """Find an HSI dataset instance corresponding to the url
     
     @param url: url to load
     
     @param bad: subclass of HSI.MetadataMixin that should be avoided.  This
     is used to select a different dataset reader if an error occurs with
     the one specified here.
     
     @param progress: (optional) progress bar callback
     
     @return: instance of HSI.MetadataMixin that can read the file, or None
     if nothing is found.
     """
     cls.discover()
     url = vfs.normalize(url)
     
     if bad:
         cls.dprint("EXCLUDING %s" % bad)
     
     # Check to see if there's a specific handler provided in the vfs
     fh = vfs.open(url)
     cls.dprint("checking for cube handler: %s" % dir(fh))
     if fh and hasattr(fh, 'metadata') and hasattr(fh.metadata, 'getCube'):
         dataset = fh.metadata
         # Only return the dataset if it's not the same class we're trying
         # to avoid
         if dataset.__class__ != bad:
             return dataset
     
     # OK, that didn't return a result, so see if there's a HSI handler 
     matches = cls.identifyall(url)
     for format in matches:
         if format == bad:
             cls.dprint("Skipping format %s" % format.format_name)
             continue
         cls.dprint("Loading %s format cube" % format.format_name)
         dataset = format(url, progress=progress)
         return dataset
     return None
Beispiel #41
0
    def load(cls, url, bad=None, progress=None):
        """Find an HSI dataset instance corresponding to the url
        
        @param url: url to load
        
        @param bad: subclass of HSI.MetadataMixin that should be avoided.  This
        is used to select a different dataset reader if an error occurs with
        the one specified here.
        
        @param progress: (optional) progress bar callback
        
        @return: instance of HSI.MetadataMixin that can read the file, or None
        if nothing is found.
        """
        cls.discover()
        url = vfs.normalize(url)

        if bad:
            cls.dprint("EXCLUDING %s" % bad)

        # Check to see if there's a specific handler provided in the vfs
        fh = vfs.open(url)
        cls.dprint("checking for cube handler: %s" % dir(fh))
        if fh and hasattr(fh, 'metadata') and hasattr(fh.metadata, 'getCube'):
            dataset = fh.metadata
            # Only return the dataset if it's not the same class we're trying
            # to avoid
            if dataset.__class__ != bad:
                return dataset

        # OK, that didn't return a result, so see if there's a HSI handler
        matches = cls.identifyall(url)
        for format in matches:
            if format == bad:
                cls.dprint("Skipping format %s" % format.format_name)
                continue
            cls.dprint("Loading %s format cube" % format.format_name)
            dataset = format(url, progress=progress)
            return dataset
        return None
Beispiel #42
0
    def load(cls, urlinfo):
        fh = vfs.open(urlinfo)
        group = ENVITextROI(urlinfo)
        current = None
        index = -1
        for line in fh:
            if line.startswith(';'):
                if line.startswith('; ROI '):
                    name, val = line[6:].split(':')
                    name = name.strip()
                    val = val.strip()
                    dprint("name=%s val=%s" % (name, val))
                    if name == 'name':
                        current = ROI(val)
                        group.addROI(current)
                    elif name == 'npts':
                        current.number = int(val)
                    elif name == 'rgb value':
                        current.setColor(val)
                    else:
                        dprint(current)
                        current = None
                elif line.startswith('; ID'):
                    index = 0
                    current = group.getROI(index)
            else:
                vals = line.split()
                if len(vals) > 0:
                    # ENVI roi coordinates start from 1, not zero
                    dprint(vals)
                    current.addPoint(int(vals[0]),
                                     int(vals[1]) - 1,
                                     int(vals[2]) - 1)
                else:
                    index += 1
                    current = group.getROI(index)

        dprint(group)
        return group
Beispiel #43
0
 def parseCtags(self, filename):
     self.tags = {}
     tagre = re.compile('(.+)\t(.+)\t(.+);"\t(.+)')
     try:
         fh = vfs.open(filename)
         for line in fh:
             match = tagre.match(line)
             if match:
                 tag = match.group(1)
                 file = match.group(2)
                 addr = match.group(3)
                 fields = match.group(4)
                 self.dprint("tag=%s file=%s addr=%s field=%s" % (tag, file, addr, str(fields)))
                 if tag not in self.tags:
                     self.tags[tag] = []
                 self.tags[tag].append((file, addr, fields))
                 #dprint(self.tags[tag])
             else:
                 self.dprint(line)
     except LookupError, e:
         self.dprint("Tag file %s not found" % filename)
         pass
Beispiel #44
0
 def parseCtags(self, filename):
     self.tags = {}
     tagre = re.compile('(.+)\t(.+)\t(.+);"\t(.+)')
     try:
         fh = vfs.open(filename)
         for line in fh:
             match = tagre.match(line)
             if match:
                 tag = match.group(1)
                 file = match.group(2)
                 addr = match.group(3)
                 fields = match.group(4)
                 self.dprint("tag=%s file=%s addr=%s field=%s" %
                             (tag, file, addr, str(fields)))
                 if tag not in self.tags:
                     self.tags[tag] = []
                 self.tags[tag].append((file, addr, fields))
                 #dprint(self.tags[tag])
             else:
                 self.dprint(line)
     except LookupError, e:
         self.dprint("Tag file %s not found" % filename)
         pass
Beispiel #45
0
    def load(cls, urlinfo):
        fh = vfs.open(urlinfo)
        group = ENVITextROI(urlinfo)
        current = None
        index = -1
        for line in fh:
            if line.startswith(';'):
                if line.startswith('; ROI '):
                    name, val = line[6:].split(':')
                    name = name.strip()
                    val = val.strip()
                    dprint("name=%s val=%s" % (name, val))
                    if name == 'name':
                        current = ROI(val)
                        group.addROI(current)
                    elif name == 'npts':
                        current.number = int(val)
                    elif name == 'rgb value':
                        current.setColor(val)
                    else:
                        dprint(current)
                        current = None
                elif line.startswith('; ID'):
                    index = 0
                    current = group.getROI(index)
            else:
                vals = line.split()
                if len(vals)>0:
                    # ENVI roi coordinates start from 1, not zero
                    dprint(vals)
                    current.addPoint(int(vals[0]), int(vals[1])-1, int(vals[2])-1)
                else:
                    index += 1
                    current = group.getROI(index)

        dprint(group)
        return group
Beispiel #46
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')
Beispiel #47
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")
Beispiel #48
0
 def test11_reading(self):
     file = vfs.make_file(self.root + 'testfile.txt')
     file.write("one\n")
     file.close()        
     file = vfs.open(self.root + 'testfile.txt')
     self.assertEqual(file.read(), 'one\n')
Beispiel #49
0
 def test17_move_file(self):
     vfs.copy('vfs/hello.txt', 'vfs/hello.txt.bak')
     vfs.move('vfs/hello.txt.bak', 'vfs/hello.txt.old')
     file = vfs.open('vfs/hello.txt.old')
     self.assertEqual(file.read(), 'hello world\n')
     self.assertEqual(vfs.exists('vfs/hello.txt.bak'), False)
Beispiel #50
0
 def open(self, buffer, progress_message):
     """Save the file handle, which is really the mpd connection"""
     self.pipe = vfs.open(buffer.url)
     self.readThreaded(self.pipe, buffer)
Beispiel #51
0
 def test_copy_file(self):
     vfs.copy('vfs/hello.txt', 'vfs-tmp/hello.txt.bak')
     with vfs.open('vfs-tmp/hello.txt.bak') as file:
         self.assertEqual(file.read(), 'hello world\n')
Beispiel #52
0
 def setUp(self):
     self.tests = vfs.open('vfs/')
Beispiel #53
0
 def test_open(self):
     file = vfs.open('http://www.google.com')
     data = file.read()
     file.close()
     self.assertEqual('<html>' in data, True)
Beispiel #54
0
 def test15_open_file(self):
     file = vfs.open('vfs/hello.txt')
     self.assertEqual(file.read(), 'hello world\n')
Beispiel #55
0
 def test_copy_folder_to_folder(self):
     vfs.copy('vfs', 'vfs-tmp')
     with vfs.open('vfs-tmp/vfs/hello.txt') as file:
         self.assertEqual(file.read(), 'hello world\n')
Beispiel #56
0
 def test_copy_file(self):
     vfs.copy('vfs/hello.txt', 'vfs-tmp/hello.txt.bak')
     with vfs.open('vfs-tmp/hello.txt.bak') as file:
         self.assertEqual(file.read(), 'hello world\n')
Beispiel #57
0
 def setUp(self):
     self.tests = vfs.open('vfs/')
Beispiel #58
0
 def test_copy_folder_to_folder(self):
     vfs.copy('vfs', 'vfs-tmp')
     with vfs.open('vfs-tmp/vfs/hello.txt') as file:
         self.assertEqual(file.read(), 'hello world\n')
Beispiel #59
0
 def test_open(self):
     file = vfs.open('http://www.google.com')
     data = file.read()
     file.close()
     self.assertEqual('<html>' in data, True)