예제 #1
0
    def readconfig(self, fn, root=None):
        if isinstance(fn, basestring):
            fn = [fn]
        for f in fn:
            try:
                fp = open(f)
            except IOError:
                continue
            cdata = self.cdata
            trusted = self._is_trusted(fp, f)
            if not trusted:
                if self.ucdata is None:
                    self.ucdata = dupconfig(self.cdata)
                cdata = self.ucdata
            elif self.ucdata is not None:
                # use a separate configparser, so that we don't accidentally
                # override ucdata settings later on.
                cdata = util.configparser()

            try:
                cdata.readfp(fp, f)
            except ConfigParser.ParsingError, inst:
                msg = _("Failed to parse %s\n%s") % (f, inst)
                if trusted:
                    raise util.Abort(msg)
                self.warn(_("Ignored: %s\n") % msg)

            if trusted:
                if cdata != self.cdata:
                    updateconfig(cdata, self.cdata)
                if self.ucdata is not None:
                    updateconfig(cdata, self.ucdata)
예제 #2
0
파일: ui.py 프로젝트: carlgao/lenga
    def readconfig(self, fn, root=None):
        if isinstance(fn, basestring):
            fn = [fn]
        for f in fn:
            try:
                fp = open(f)
            except IOError:
                continue
            cdata = self.cdata
            trusted = self._is_trusted(fp, f)
            if not trusted:
                if self.ucdata is None:
                    self.ucdata = dupconfig(self.cdata)
                cdata = self.ucdata
            elif self.ucdata is not None:
                # use a separate configparser, so that we don't accidentally
                # override ucdata settings later on.
                cdata = util.configparser()

            try:
                cdata.readfp(fp, f)
            except ConfigParser.ParsingError, inst:
                msg = _("Failed to parse %s\n%s") % (f, inst)
                if trusted:
                    raise util.Abort(msg)
                self.warn(_("Ignored: %s\n") % msg)

            if trusted:
                if cdata != self.cdata:
                    updateconfig(cdata, self.cdata)
                if self.ucdata is not None:
                    updateconfig(cdata, self.ucdata)
예제 #3
0
 def __init__(
     self,
     verbose=False,
     debug=False,
     quiet=False,
     interactive=True,
     traceback=False,
     report_untrusted=True,
     parentui=None,
 ):
     self.overlay = None
     self.buffers = []
     if parentui is None:
         # this is the parent of all ui children
         self.parentui = None
         self.quiet = quiet
         self.verbose = verbose
         self.debugflag = debug
         self.interactive = interactive
         self.traceback = traceback
         self.report_untrusted = report_untrusted
         self.trusted_users = {}
         self.trusted_groups = {}
         # if ucdata is not None, its keys must be a superset of cdata's
         self.cdata = util.configparser()
         self.ucdata = None
         # we always trust global config files
         self.check_trusted = False
         self.readconfig(util.rcpath())
         self.check_trusted = True
         self.updateopts(verbose, debug, quiet, interactive)
     else:
         # parentui may point to an ui object which is already a child
         self.parentui = parentui.parentui or parentui
         self.trusted_users = parentui.trusted_users.copy()
         self.trusted_groups = parentui.trusted_groups.copy()
         self.cdata = dupconfig(self.parentui.cdata)
         if self.parentui.ucdata:
             self.ucdata = dupconfig(self.parentui.ucdata)
         if self.parentui.overlay:
             self.overlay = dupconfig(self.parentui.overlay)
         if self.parentui is not parentui and parentui.overlay is not None:
             if self.overlay is None:
                 self.overlay = util.configparser()
             updateconfig(parentui.overlay, self.overlay)
         self.buffers = parentui.buffers
예제 #4
0
파일: ui.py 프로젝트: carlgao/lenga
 def setconfig(self, section, name, value):
     if not self.overlay:
         self.overlay = util.configparser()
     for cdata in (self.overlay, self.cdata, self.ucdata):
         if not cdata: continue
         if not cdata.has_section(section):
             cdata.add_section(section)
         cdata.set(section, name, value)
     self.fixconfig(section, name, value)
예제 #5
0
 def setconfig(self, section, name, value):
     if not self.overlay:
         self.overlay = util.configparser()
     for cdata in (self.overlay, self.cdata, self.ucdata):
         if not cdata: continue
         if not cdata.has_section(section):
             cdata.add_section(section)
         cdata.set(section, name, value)
     self.fixconfig(section, name, value)
예제 #6
0
 def __init__(self, verbose=False, debug=False, quiet=False,
              interactive=True, traceback=False, report_untrusted=True,
              parentui=None):
     self.overlay = None
     self.buffers = []
     if parentui is None:
         # this is the parent of all ui children
         self.parentui = None
         self.quiet = quiet
         self.verbose = verbose
         self.debugflag = debug
         self.interactive = interactive
         self.traceback = traceback
         self.report_untrusted = report_untrusted
         self.trusted_users = {}
         self.trusted_groups = {}
         # if ucdata is not None, its keys must be a superset of cdata's
         self.cdata = util.configparser()
         self.ucdata = None
         # we always trust global config files
         self.check_trusted = False
         self.readconfig(util.rcpath())
         self.check_trusted = True
         self.updateopts(verbose, debug, quiet, interactive)
     else:
         # parentui may point to an ui object which is already a child
         self.parentui = parentui.parentui or parentui
         self.trusted_users = parentui.trusted_users.copy()
         self.trusted_groups = parentui.trusted_groups.copy()
         self.cdata = dupconfig(self.parentui.cdata)
         if self.parentui.ucdata:
             self.ucdata = dupconfig(self.parentui.ucdata)
         if self.parentui.overlay:
             self.overlay = dupconfig(self.parentui.overlay)
         if self.parentui is not parentui and parentui.overlay is not None:
             if self.overlay is None:
                 self.overlay = util.configparser()
             updateconfig(parentui.overlay, self.overlay)
         self.buffers = parentui.buffers
예제 #7
0
    def readsections(self, filename, *sections):
        """Read filename and add only the specified sections to the config data

        The settings are added to the trusted config data.
        """
        if not sections:
            return

        cdata = util.configparser()
        try:
            try:
                fp = open(filename)
            except IOError, inst:
                raise util.Abort(_("unable to open %s: %s") % (filename, getattr(inst, "strerror", inst)))
            try:
                cdata.readfp(fp, filename)
            finally:
                fp.close()
예제 #8
0
    def readsections(self, filename, *sections):
        """Read filename and add only the specified sections to the config data

        The settings are added to the trusted config data.
        """
        if not sections:
            return

        cdata = util.configparser()
        try:
            try:
                fp = open(filename)
            except IOError, inst:
                raise util.Abort(_("unable to open %s: %s") %
                                 (filename, getattr(inst, "strerror", inst)))
            try:
                cdata.readfp(fp, filename)
            finally:
                fp.close()
예제 #9
0
파일: ui.py 프로젝트: carlgao/lenga
def dupconfig(orig):
    new = util.configparser(orig.defaults())
    updateconfig(orig, new)
    return new
예제 #10
0
def dupconfig(orig):
    new = util.configparser(orig.defaults())
    updateconfig(orig, new)
    return new