Ejemplo n.º 1
0
def UpdateProfileLoader():
    """Updates Loader File
    @precondition: MYPROFILE has been set
    @postcondition: on disk profile loader is updated
    @return: 0 if no error, non zero for error condition

    """
    writer = util.GetFileWriter(GetLoader())
    if writer == -1:
        return 1

    prof_name = Profile_Get('MYPROFILE')
    if not prof_name or not os.path.isabs(prof_name):
        prof_name = CONFIG['PROFILE_DIR'] + 'default.ppb'

    if not os.path.exists(prof_name):
        prof_name = os.path.join(CONFIG['CONFIG_DIR'],
                                 os.path.basename(prof_name))
        Profile_Set('MYPROFILE', prof_name)

    # Use just the relative profile name for local(portable) config paths
    prof_name = os.path.basename(prof_name)

    writer.write(prof_name)
    writer.write(u"\nVERSION\t" + VERSION)
    writer.close()
    return 0
Ejemplo n.º 2
0
    def LoadBook(self, book):
        """Loads a set of records from an on disk dictionary
        the entries are formated as key=value with one entry
        per line in the file.
        @return: whether book was loaded or not
        @rtype: boolean

        """
        # If file does not exist create it and return
        if not os.path.exists(book):
            try:
                tfile = util.GetFileWriter(book)
                tfile.close()
            except (IOError, OSError):
                util.Log("[docpositionmgr] failed to load book")
                return False

        reader = util.GetFileReader(book)
        lines = reader.readlines()
        reader.close()
        for line in lines:
            line = line.strip()
            vals = line.split(u'=')
            if len(vals) != 2 or not os.path.exists(vals[0]):
                continue

            try:
                vals[1] = int(vals[1])
            except (TypeError, ValueError), msg:
                util.Log("[docpositionmgr] %s" % str(msg))
                continue
            else:
                self.AddRecord(vals)
Ejemplo n.º 3
0
    def Save(self):
        """Writes the config out to disk"""
        file_h = util.GetFileWriter(self._base)
        if file_h == -1:
            return False

        for label in self._pmarks:
            file_h.write(u"%s=%s\n" % (label, self._pmarks[label]))
        file_h.close()
        return True
Ejemplo n.º 4
0
 def save(self):
     """ Write the data out to disk """
     #print repr(self)
     try:
         filename = ed_glob.CONFIG['CACHE_DIR'] + 'Projects.config'
         conf = util.GetFileWriter(filename)
         if conf != -1:
             conf.write(repr(self))
             conf.close()
         os.chmod(filename, stat.S_IRUSR|stat.S_IWUSR)
     except OSError:
         pass
Ejemplo n.º 5
0
    def WriteBook(self):
        """Writes the collection of files=pos to the config file
        @postcondtion: in memory doc data is written out to disk

        """
        writer = util.GetFileWriter(self.GetBook())
        try:
            for key in self._records:
                writer.write(u"%s=%d\n" % (key, self._records[key]))
            writer.close()
        except (IOError, AttributeError), msg:
            util.Log("[docpositionmgr] %s" % str(msg))
Ejemplo n.º 6
0
    def WriteStyleSheet(self, path):
        """Write the current style data to the given path
        @param path: string
        @return: bool

        """
        bOk = True
        try:
            writer = util.GetFileWriter(path)
            writer.write(self.Window.GenerateStyleSheet())
            writer.close()
        except (AttributeError, IOError), msg:
            util.Log('[style_editor][err] Failed to export style sheet')
            util.Log('[style_editor][err] %s' % msg)
            bOk = False
Ejemplo n.º 7
0
    def LoadBook(self, book):
        """Loads a set of records from an on disk dictionary
        the entries are formated as key=value with one entry
        per line in the file.
        @param book: path to saved file
        @return: whether book was loaded or not

        """
        # If file does not exist create it and return
        if not os.path.exists(book):
            try:
                tfile = util.GetFileWriter(book)
                tfile.close()
            except (IOError, OSError):
                util.Log("[docpositionmgr][err] failed to load book: %s" %
                         book)
                return False
            except AttributeError:
                util.Log("[docpositionmgr][err] Failed to create: %s" % book)
                return False

        reader = util.GetFileReader(book, sys.getfilesystemencoding())
        if reader != -1:
            lines = list()
            try:
                lines = reader.readlines()
            except:
                reader.close()
                return False
            else:
                reader.close()

            for line in lines:
                line = line.strip()
                vals = line.rsplit(u'=', 1)
                if len(vals) != 2 or not os.path.exists(vals[0]):
                    continue

                try:
                    vals[1] = int(vals[1])
                except (TypeError, ValueError), msg:
                    util.Log("[docpositionmgr][err] %s" % str(msg))
                    continue
                else:
                    self._records[vals[0]] = vals[1]

            util.Log("[docpositionmgr][info] successfully loaded book")
            return True
Ejemplo n.º 8
0
    def WriteBook(self):
        """Writes the collection of files=pos to the config file
        @postcondition: in memory doc data is written out to disk

        """
        writer = util.GetFileWriter(self.GetBook(), sys.getfilesystemencoding())
        if writer != -1:
            try:
                for key, val in self._records.iteritems():
                    try:
                        writer.write(u"%s=%d\n" % (key, val))
                    except UnicodeDecodeError:
                        continue
                writer.close()
            except IOError, msg:
                util.Log("[docpositionmgr][err] %s" % str(msg))
Ejemplo n.º 9
0
    def WritePluginConfig(self):
        """Writes out the plugin config.
        @postcondition: the configuration data is saved to disk

        """
        writer = util.GetFileWriter(os.path.join(ed_glob.CONFIG['CONFIG_DIR'],
                                                 PLUGIN_CONFIG))
        if writer == -1:
            self.LOG("[plugin_mgr][exception] Failed to write plugin config")
            return
        writer.write("# Editra %s Plugin Config\n#\n" % ed_glob.VERSION)
        for item in self._config:
            writer.write("%s=%s\n" % (item, str(self._config[item])))
        writer.write("\n# EOF\n")
        writer.close()
        return
Ejemplo n.º 10
0
 def SaveKeyProfile(self):
     """Save the current key profile to disk"""
     if KeyBinder.cprofile is None:
         util.Log("[keybinder][warn] No keyprofile is set, cant save")
     else:
         ppath = self.GetProfilePath(KeyBinder.cprofile)
         writer = util.GetFileWriter(ppath)
         if writer != -1:
             itemlst = list()
             for item in KeyBinder.keyprofile.keys():
                 itemlst.append(u"%s=%s%s" % (_FindStringRep(item),
                                             self.GetBinding(item).lstrip(),
                                             os.linesep))
             writer.writelines(sorted(itemlst))
             writer.close()
         else:
             util.Log("[keybinder][err] Failed to open %s for writing" % ppath)
Ejemplo n.º 11
0
def UpdateProfileLoader():
    """Updates Loader File
    @postcondition: on disk profile loader is updated
    @return: 0 if no error, non zero for error condition

    """
    writer = util.GetFileWriter(GetLoader())
    if writer == -1:
        return 1

    prof_name = Profile_Get('MYPROFILE')
    if not prof_name:
        prof_name = CONFIG['PROFILE_DIR'] + 'default.ppb'

    prof_name = prof_name.encode(sys.getfilesystemencoding())
    writer.write(prof_name)
    writer.write(u"\nVERSION\t" + VERSION)
    writer.close()
    return 0
Ejemplo n.º 12
0
    def SavePerspectives(self):
        """Writes the perspectives out to disk. Returns True if all data was 
        written and False if there was an error.
        @return: whether save was successful

        """
        writer = util.GetFileWriter(self._base)
        if writer == -1:
            util.Log("[perspective][err] Failed to save %s" % self._base)
            return False

        try:
            self._viewset[LAST_KEY] = self._currview
            for perspect in self._viewset:
                writer.write(u"%s=%s\n" % (perspect, self._viewset[perspect]))
            del self._viewset[LAST_KEY]
        except (IOError, OSError):
            util.Log("[perspective][err] Write error: %s" % self._base)
            return False
        else:
            return True
Ejemplo n.º 13
0
def UpdateProfileLoader():
    """Updates Loader File
    @postcondition: on disk profile loader is updated
    @return: 0 if no error, non zero for error condition

    """
    writer = util.GetFileWriter(GetLoader())
    if writer == -1:
        return 1

    prof_name = Profile_Get('MYPROFILE')
    if not prof_name:
        prof_name = CONFIG['PROFILE_DIR'] + 'default.ppb'

    if not os.path.exists(prof_name):
        prof_name = os.path.join(CONFIG['CONFIG_DIR'],
                                 os.path.basename(prof_name))
        Profile_Set('MYPROFILE', prof_name)

    writer.write(prof_name)
    writer.write(u"\nVERSION\t" + VERSION)
    writer.close()
    return 0