コード例 #1
0
ファイル: profiler.py プロジェクト: wangdyna/wxPython
def ProfileVersionStr():
    """Checks the Loader for the profile version string and
    returns the version string. If there is an error or the
    string is not found it returns a zero version string.
    @return: the version string value from the profile loader file

    """
    loader = GetLoader()
    reader = util.GetFileReader(loader, sys.getfilesystemencoding())
    if reader == -1:
        return "0.0.0"

    ret_val = "0.0.0"
    count = 0
    while True:
        count += 1
        value = reader.readline()
        value = value.split()
        if len(value) > 0:
            if value[0] == u'VERSION':
                ret_val = value[1]
                break
        # Give up after 20 lines if version string not found
        if count > 20:
            break
    reader.close()

    return ret_val
コード例 #2
0
    def LoadStyleSheet(self, style_sheet, force=False):
        """Loads a custom style sheet and returns True on success
        @param style_sheet: path to style sheet to load
        @keyword force: Force re-parse of style sheet, default is to use cached
                        data when available
        @return: whether style sheet was loaded or not

        """
        if isinstance(style_sheet, basestring) and \
           os.path.exists(style_sheet) and \
           ((force or style_sheet not in StyleMgr.STYLES) or \
             style_sheet != self.style_set):
            reader = util.GetFileReader(style_sheet)
            if reader == -1:
                self.LOG("[ed_style][err] Failed to open style sheet: %s" %
                         style_sheet)
                return False
            style_data = None
            try:
                style_data = self.ParseStyleData(reader.read())
            except Exception, msg:
                self.LOG("[ed_style][err] Failed to parse style data for %s:" %
                         style_sheet)
                return False
            ret_val = self.SetStyles(style_sheet, style_data)
            reader.close()
            return ret_val
コード例 #3
0
ファイル: plugin.py プロジェクト: wangdyna/wxPython
    def LoadPluginConfig(self):
        """Loads the plugin config file for the current user if
        it exists. The configuration file contains which plugins
        are active and which ones are not.
        @return: configuration dictionary

        """
        config = dict()
        reader = util.GetFileReader(os.path.join(ed_glob.CONFIG['CONFIG_DIR'],
                                                 PLUGIN_CONFIG))
        if reader == -1:
            self.LOG("[pluginmgr][err] Failed to read plugin config file")
            return config

        reading = True
        for line in reader.readlines():
            data = line.strip()
            if len(data) and data[0] == u"#":
                continue

            data = data.split(u"=")
            if len(data) == 2:
                config[data[0].strip()] = data[1].strip().lower() == u"true"
            else:
                continue

        reader.close()
        return config
コード例 #4
0
    def LoadStyleSheet(self, style_sheet, force=False):
        """Loads a custom style sheet and returns True on success
        @param style_sheet: path to style sheet to load
        @keyword force: Force reparse of style sheet, default is to use cached
                        data when available
        @return: whether style sheet was loaded or not
        @rtype: bool

        """
        if isinstance(style_sheet, basestring) and \
           os.path.exists(style_sheet) and \
           ((force or not self.STYLES.has_key(style_sheet)) or \
             style_sheet != self.style_set):
            reader = util.GetFileReader(style_sheet)
            if reader == -1:
                self.LOG("[styles][err] Failed to open style sheet: %s" %
                         style_sheet)
                return False
            ret_val = self.SetStyles(style_sheet,
                                     self.ParseStyleData(reader.read()))
            reader.close()
            return ret_val
        elif not self.STYLES.has_key(style_sheet):
            self.LOG("[styles] Style sheet %s does not exists" % style_sheet)
            self.SetStyles('default', DefaultStyleDictionary())
            return False
        else:
            self.LOG("[styles][info] Using cached style data")
            return True
コード例 #5
0
ファイル: doctools.py プロジェクト: CrownBonded/editra
    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)
コード例 #6
0
    def LoadStyleSheet(self, style_sheet, force=False):
        """Loads a custom style sheet and returns True on success
        @param style_sheet: path to style sheet to load
        @keyword force: Force re-parse of style sheet, default is to use cached
                        data when available
        @return: whether style sheet was loaded or not
        @rtype: bool

        """
        if isinstance(style_sheet, basestring) and \
           os.path.exists(style_sheet) and \
           ((force or style_sheet not in StyleMgr.STYLES) or \
             style_sheet != self.style_set):
            reader = util.GetFileReader(style_sheet)
            if reader == -1:
                self.LOG("[ed_style][err] Failed to open style sheet: %s" %
                         style_sheet)
                return False
            ret_val = self.SetStyles(style_sheet,
                                     self.ParseStyleData(reader.read()))
            reader.close()
            return ret_val
        elif style_sheet not in StyleMgr.STYLES:
            self.LOG("[ed_style][warn] Style sheet %s does not exists" %
                     style_sheet)
            # Reset to default style
            if Profile_Get('SYNTHEME') != 'default':
                Profile_Set('SYNTHEME', 'default')
                self.SetStyles('default', DEF_STYLE_DICT)
            return False
        else:
            self.LOG("[ed_style][info] Using cached style data")
            return True
コード例 #7
0
ファイル: perspective.py プロジェクト: wangdyna/wxPython
    def LoadPerspectives(self):
        """Loads the perspectives data into the manager. Returns
        the number of perspectives that were successfully loaded.
        @return: number of perspectives loaded

        """
        reader = util.GetFileReader(self._base)
        if reader == -1:
            util.Log("[perspective][err] Failed to get " +
                     "file reader for %s" % self._base)
            return 0

        try:
            for line in reader.readlines():
                label, val = line.split(u"=", 1)
                label = label.strip()
                if not len(label):
                    continue
                self._viewset[label] = val.strip()
            reader.close()
        finally:
            if LAST_KEY in self._viewset:
                self._currview = self._viewset[LAST_KEY]
                del self._viewset[LAST_KEY]
            return len(self._viewset)
コード例 #8
0
ファイル: ed_menu.py プロジェクト: pombreda/decada
    def LoadKeyProfileFile(self, path):
        """Load a key profile from the given path
        @param path: full path to file

        """
        keydict = dict()
        pname = None
        if path:
            pname = os.path.basename(path)
            pname = pname.rsplit('.', 1)[0]

        if pname is not None and os.path.exists(path):
            reader = util.GetFileReader(path)
            if reader != -1:
                util.Log("[keybinder][info] Loading KeyProfile: %s" % path)
                for line in reader:
                    parts = line.split(u'=', 1)
                    # Check that the line was formatted properly
                    if len(parts) == 2:
                        # Try to find the ID value
                        item_id = _GetValueFromStr(parts[0])
                        if item_id is not None:
                            tmp = [
                                part.strip() for part in parts[1].split(u'+')
                                if len(part.strip())
                            ]

                            # Do some checking if the binding is valid
                            nctrl = len([
                                key for key in tmp
                                if key not in (u'Ctrl', u'Alt', u'Shift')
                            ])
                            if nctrl:
                                if parts[1].strip().endswith(u'++'):
                                    tmp.append(u'+')
                                kb = tuple(tmp)
                                if kb in keydict.values():
                                    for mid, b in keydict.iteritems():
                                        if kb == b:
                                            del keydict[mid]
                                            break
                                keydict[item_id] = tuple(tmp)
                            else:
                                # Invalid key binding
                                continue

                reader.close()
                KeyBinder.keyprofile = keydict
                KeyBinder.cprofile = pname
                return
            else:
                util.Log("[keybinder][err] Couldn't read %s" % path)
        elif pname is not None:
            # Fallback to default keybindings
            util.Log("[keybinder][err] Failed to load bindings from %s" %
                     pname)

        util.Log("[keybinder][info] Loading Default Keybindings")
        KeyBinder.LoadDefaults()
コード例 #9
0
ファイル: ed_menu.py プロジェクト: wangdyna/wxPython
    def LoadKeyProfile(self, pname):
        """Load a key profile into the binder
        @param pname: name of key profile to load

        """
        if pname is None:
            ppath = None
        else:
            ppath = self.GetProfilePath(pname)

        keydict = dict()
        if ppath is not None and os.path.exists(ppath):
            reader = util.GetFileReader(ppath)
            if reader != -1:
                util.Log("[keybinder][info] Loading KeyProfile: %s" % ppath)
                for line in reader:
                    parts = line.split(u'=', 1)
                    # Check that the line was formatted properly
                    if len(parts) == 2:
                        # Try to find the ID value
                        item_id = _GetValueFromStr(parts[0])
                        if item_id is not None:
                            tmp = [
                                part.strip() for part in parts[1].split(u'+')
                                if len(part.strip())
                            ]

                            # Do some checking if the binding is valid
                            nctrl = len([
                                key for key in tmp
                                if key not in (u'Ctrl', u'Alt', u'Shift')
                            ])
                            if nctrl:
                                keydict[item_id] = tmp
                                if parts[1].strip().endswith(u'++'):
                                    keydict[item_id].append(u'+')
                            else:
                                # Invalid key binding
                                continue

                reader.close()
                KeyBinder.keyprofile = keydict
                KeyBinder.cprofile = pname
                return
            else:
                util.Log("[keybinder][err] Couldn't read %s" % ppath)
        elif pname is not None:
            # Fallback to default keybindings
            util.Log("[keybinder][err] Failed to load bindings from %s" %
                     pname)

        util.Log("[keybinder][info] Loading Default Keybindings")
        KeyBinder.LoadDefaults()
コード例 #10
0
def GetLines(fname):
    """Gets all the lines from the given file
    @return: list of lines or -1 on error

    """
    reader = util.GetFileReader(fname)
    if reader != -1:
        try:
            lines = reader.readlines()
        except (AttributeError, IOError, OSError), msg:
            print msg
            return -1
        reader.close()
コード例 #11
0
ファイル: profiler.py プロジェクト: wangdyna/wxPython
def GetProfileStr():
    """Reads the profile string from the loader and returns it.
    The profile string must be the first line in the loader file.
    @return: path of profile used in last session

    """
    reader = util.GetFileReader(GetLoader())
    if reader == -1:
        # So return the default
        return CONFIG['PROFILE_DIR'] + u"default.ppb"

    profile = reader.readline()
    profile = profile.split("\n")[0] # strip newline from end
    reader.close()
    return profile
コード例 #12
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
コード例 #13
0
    def Load(self):
        """Loads the configuration data into the dictionary"""
        file_h = util.GetFileReader(self._base)
        if file_h != -1:
            lines = file_h.readlines()
            file_h.close()
        else:
            return False

        for line in lines:
            vals = line.strip().split(u"=")
            if len(vals) != 2:
                continue
            if os.path.exists(vals[1]):
                self.AddPathMark(vals[0], vals[1])
        return True
コード例 #14
0
def GetProfileStr():
    """Reads the profile string from the loader and returns it.
    The profile string must be the first line in the loader file.
    @return: path of profile used in last session

    """
    reader = util.GetFileReader(GetLoader())
    if reader == -1:
        # So return the default
        return CONFIG['PROFILE_DIR'] + u"default.ppb"

    profile = reader.readline()
    profile = profile.strip()
    reader.close()
    if not os.path.isabs(profile):
        profile = CONFIG['PROFILE_DIR'] + profile
    return profile
コード例 #15
0
    def load(self):
        """ Load the saved configuration data from on disk config file """
        data = {}
        try:
            filename = ed_glob.CONFIG['CACHE_DIR'] + 'Projects.config'
            conf = util.GetFileReader(filename)
            if conf != -1:
                try: 
                    data = eval(conf.read())
                    conf.close()
                except:
                    conf.close()
                    os.remove(filename)
        except OSError:
            pass

        recursiveupdate(self, data)
        self.updateSCSystems()
コード例 #16
0
    def LoadPerspectives(self):
        """Loads the perspectives data into the manager. Returns 
        the number of perspectives that were successfully loaded.
        @return: number of perspectives loaded

        """
        reader = util.GetFileReader(self._base)
        if reader == -1:
            return 0

        try:
            for line in reader.readlines():
                label, val = line.split(u"=", 1)
                if not len(label.strip()):
                    continue
                self._viewset[label.strip()] = val.strip()
            reader.close()
        finally:
            if self._viewset.has_key(LAST_KEY):
                self._currview = self._viewset[LAST_KEY]
                del self._viewset[LAST_KEY]
            return len(self._viewset)
コード例 #17
0
    def LoadKeyProfile(self, pname):
        """Load a key profile into the binder
        @param pname: name of key profile to load

        """
        if pname is None:
            ppath = None
        else:
            ppath = self.GetProfilePath(pname)

        keydict = dict()
        if ppath is not None and os.path.exists(ppath):
            reader = util.GetFileReader(ppath)
            if reader != -1:
                util.Log("[keybinder][info] Loading KeyProfile: %s" % ppath)
                for line in reader:
                    parts = line.split('=', 1)
                    if len(parts) == 2:
                        item_id = _GetValueFromStr(parts[0])
                        if item_id is not None:
                            keydict[item_id] = [
                                part.strip() for part in parts[1].split('+')
                                if len(part.strip())
                            ]
                            if parts[1].strip().endswith('++'):
                                keydict[item_id].append('+')
                reader.close()
                KeyBinder.keyprofile = keydict
                KeyBinder.cprofile = pname
                return
            else:
                util.Log("[keybinder][err] Couldn't read %s" % ppath)
        elif pname is not None:
            # Fallback to default keybindings
            util.Log("[keybinder][err] Failed to load bindings from %s" %
                     pname)

        util.Log("[keybinder][info] Loading Default Keybindings")
        KeyBinder.LoadDefaults()