示例#1
0
    def _parse_siteconf(self, siteconf):
        if not siteconf:
            return

        if not os.path.exists(siteconf):
            msger.warning("cannot read config file: %s" % siteconf)
            return

        parser = ConfigParser.SafeConfigParser()
        parser.read(siteconf)

        for section in parser.sections():
            if section in self.DEFAULTS:
                getattr(self, section).update(dict(parser.items(section)))

        # append common section items to other sections
        for section in self.DEFAULTS.keys():
            if section != "common" and not section.startswith('bootstrap'):
                getattr(self, section).update(self.common)

        # check and normalize the scheme of proxy url
        if self.create['proxy']:
            m = re.match('^(\w+)://.*', self.create['proxy'])
            if m:
                scheme = m.group(1)
                if scheme not in ('http', 'https', 'ftp', 'socks'):
                    msger.error("%s: proxy scheme is incorrect" % siteconf)
            else:
                msger.warning("%s: proxy url w/o scheme, use http as default"
                              % siteconf)
                self.create['proxy'] = "http://" + self.create['proxy']

        proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])

        for section in parser.sections():
            if section.startswith('bootstrap'):
                name = section
                repostr = {}
                for option in parser.options(section):
                    if option == 'name':
                        name = parser.get(section, 'name')
                        continue

                    val = parser.get(section, option)
                    if '_' in option:
                        (reponame, repoopt) = option.split('_')
                        if repostr.has_key(reponame):
                            repostr[reponame] += "%s:%s," % (repoopt, val)
                        else:
                            repostr[reponame] = "%s:%s," % (repoopt, val)
                        continue

                    if val.split(':')[0] in ('file', 'http', 'https', 'ftp'):
                        if repostr.has_key(option):
                            repostr[option] += "name:%s,baseurl:%s," % (option, val)
                        else:
                            repostr[option]  = "name:%s,baseurl:%s," % (option, val)
                        continue

                self.bootstraps[name] = repostr
示例#2
0
文件: conf.py 项目: saukko/mic
    def _parse_siteconf(self, siteconf):
        if not siteconf:
            return

        if not os.path.exists(siteconf):
            raise errors.ConfigError("Failed to find config file: %s" % siteconf)

        parser = ConfigParser.SafeConfigParser()
        parser.read(siteconf)

        for section in parser.sections():
            if section in self.DEFAULTS:
                getattr(self, section).update(dict(parser.items(section)))

        # append common section items to other sections
        for section in self.DEFAULTS.keys():
            if section != "common" and not section.startswith("bootstrap"):
                getattr(self, section).update(self.common)

        if self.create["proxy"]:
            urlptn = re.compile("://")
            m = urlptn.search(self.create["proxy"])
            if m:
                scheme = self.create["proxy"].split(":")[0]
                if scheme not in ("http", "https", "ftp", "socks"):
                    msger.error("%s: proxy scheme is incorrect" % siteconf)
            else:
                msger.warning("%s: proxy set without scheme, use http default" % siteconf)
                self.create["proxy"] = "http://%s" % self.create["proxy"]
        proxy.set_proxies(self.create["proxy"], self.create["no_proxy"])

        for section in parser.sections():
            if section.startswith("bootstrap"):
                name = section
                repostr = {}
                for option in parser.options(section):
                    if option == "name":
                        name = parser.get(section, "name")
                        continue

                    val = parser.get(section, option)
                    if "_" in option:
                        (reponame, repoopt) = option.split("_")
                        if repostr.has_key(reponame):
                            repostr[reponame] += "%s:%s," % (repoopt, val)
                        else:
                            repostr[reponame] = "%s:%s," % (repoopt, val)
                        continue

                    if val.split(":")[0] in ("file", "http", "https", "ftp"):
                        if repostr.has_key(option):
                            repostr[option] += "name:%s,baseurl:%s," % (option, val)
                        else:
                            repostr[option] = "name:%s,baseurl:%s," % (option, val)
                        continue

                self.bootstraps[name] = repostr
示例#3
0
文件: plugin.py 项目: xiaoqiang0/mic
    def _add_plugindir(self, path):
        path = os.path.abspath(os.path.expanduser(path))

        if not os.path.isdir(path):
            msger.warning("Plugin dir is not a directory or does not exist: %s" % path)
            return

        if path not in self.plugin_dirs:
            self.plugin_dirs[path] = False
示例#4
0
    def _add_plugindir(self, path):
        path = os.path.abspath(os.path.expanduser(path))

        if not os.path.isdir(path):
            msger.warning("Plugin dir is not a directory or does not exist: %s"\
                          % path)
            return

        if path not in self.plugin_dirs:
            self.plugin_dirs[path] = False
示例#5
0
    def _parse_siteconf(self, siteconf):
        if not siteconf:
            return

        if not os.path.exists(siteconf):
            msger.warning("cannot read config file: %s" % siteconf)
            return

        parser = ConfigParser.SafeConfigParser()
        parser.read(siteconf)

        for section in parser.sections():
            if section in self.DEFAULTS:
                getattr(self, section).update(dict(parser.items(section)))

        # append common section items to other sections
        for section in self.DEFAULTS.keys():
            if section != "common":
                getattr(self, section).update(self.common)

        # check and normalize the scheme of proxy url
        if self.create['proxy']:
            m = re.match('^(\w+)://.*', self.create['proxy'])
            if m:
                scheme = m.group(1)
                if scheme not in ('http', 'https', 'ftp', 'socks'):
                    msger.error("%s: proxy scheme is incorrect" % siteconf)
            else:
                msger.warning("%s: proxy url w/o scheme, use http as default"
                              % siteconf)
                self.create['proxy'] = "http://" + self.create['proxy']

        proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])

        # bootstrap option handling
        self.set_runtime(self.create['runtime'])
        if isinstance(self.bootstrap['packages'], basestring):
            packages = self.bootstrap['packages'].replace('\n', ' ')
            if packages.find(',') != -1:
                packages = packages.split(',')
            else:
                packages = packages.split()
            self.bootstrap['packages'] = packages
示例#6
0
文件: plugin.py 项目: xiaoqiang0/mic
    def _load_all(self):
        for (pdir, loaded) in self.plugin_dirs.iteritems():
            if loaded: continue

            sys.path.insert(0, pdir)
            for mod in [x[:-3] for x in os.listdir(pdir) if x.endswith(".py")]:
                if mod and mod != '__init__':
                    if mod in sys.modules:
                        #self.plugin_dirs[pdir] = True
                        msger.warning("Module %s already exists, skip" % mod)
                    else:
                        try:
                            pymod = __import__(mod)
                            self.plugin_dirs[pdir] = True
                            msger.debug("Plugin module %s:%s imported" % (mod, pymod.__file__))
                        except ImportError, e:
                            msger.warning('%s, skip plugin %s/%s' %(str(e), os.path.basename(pdir), mod))

            del(sys.path[0])
示例#7
0
    def _load_all(self):
        for (pdir, loaded) in self.plugin_dirs.iteritems():
            if loaded: continue

            sys.path.insert(0, pdir)
            for mod in [x[:-3] for x in os.listdir(pdir) if x.endswith(".py")]:
                if mod and mod != '__init__':
                    if mod in sys.modules:
                        #self.plugin_dirs[pdir] = True
                        msger.warning("Module %s already exists, skip" % mod)
                    else:
                        try:
                            pymod = __import__(mod)
                            self.plugin_dirs[pdir] = True
                            msger.debug("Plugin module %s:%s imported"\
                                        % (mod, pymod.__file__))
                        except ImportError, e:
                            msger.warning('Loading failed, skip plugin %s/%s'\
                                          % (os.path.basename(pdir), mod))

            del (sys.path[0])
示例#8
0
    def _parse_siteconf(self, siteconf):
        if not siteconf:
            return

        if not os.path.exists(siteconf):
            raise errors.ConfigError("Failed to find config file: %s" \
                                     % siteconf)

        parser = ConfigParser.SafeConfigParser()
        parser.read(siteconf)

        for section in parser.sections():
            if section in self.DEFAULTS:
                getattr(self, section).update(dict(parser.items(section)))

        # append common section items to other sections
        for section in self.DEFAULTS.keys():
            if section != "common" and not section.startswith('bootstrap'):
                getattr(self, section).update(self.common)

        if self.create['proxy']:
            urlptn = re.compile('://')
            m = urlptn.search(self.create['proxy'])
            if m:
                scheme = self.create['proxy'].split(':')[0]
                if scheme not in ('http', 'https', 'ftp', 'socks'):
                    msger.error("%s: proxy scheme is incorrect" % siteconf)
            else:
                msger.warning(
                    "%s: proxy set without scheme, use http default" %
                    siteconf)
                self.create['proxy'] = "http://%s" % self.create['proxy']
        proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])

        for section in parser.sections():
            if section.startswith('bootstrap'):
                name = section
                repostr = {}
                for option in parser.options(section):
                    if option == 'name':
                        name = parser.get(section, 'name')
                        continue

                    val = parser.get(section, option)
                    if '_' in option:
                        (reponame, repoopt) = option.split('_')
                        if repostr.has_key(reponame):
                            repostr[reponame] += "%s:%s," % (repoopt, val)
                        else:
                            repostr[reponame] = "%s:%s," % (repoopt, val)
                        continue

                    if val.split(':')[0] in ('file', 'http', 'https', 'ftp'):
                        if repostr.has_key(option):
                            repostr[option] += "name:%s,baseurl:%s," % (option,
                                                                        val)
                        else:
                            repostr[option] = "name:%s,baseurl:%s," % (option,
                                                                       val)
                        continue

                self.bootstraps[name] = repostr
示例#9
0
文件: conf.py 项目: sledges/mic
    def _parse_siteconf(self, siteconf):
        if not siteconf:
            return

        if not os.path.exists(siteconf):
            msger.warning("cannot read config file: %s" % siteconf)
            return

        parser = ConfigParser.SafeConfigParser()
        parser.read(siteconf)

        for section in parser.sections():
            if section in self.DEFAULTS:
                getattr(self, section).update(dict(parser.items(section)))

        # append common section items to other sections
        for section in self.DEFAULTS.keys():
            if section != "common" and not section.startswith('bootstrap'):
                getattr(self, section).update(self.common)

        # check and normalize the scheme of proxy url
        if self.create['proxy']:
            m = re.match('^(\w+)://.*', self.create['proxy'])
            if m:
                scheme = m.group(1)
                if scheme not in ('http', 'https', 'ftp', 'socks'):
                    msger.error("%s: proxy scheme is incorrect" % siteconf)
            else:
                msger.warning("%s: proxy url w/o scheme, use http as default" %
                              siteconf)
                self.create['proxy'] = "http://" + self.create['proxy']

        proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])

        for section in parser.sections():
            if section.startswith('bootstrap'):
                name = section
                repostr = {}
                for option in parser.options(section):
                    if option == 'name':
                        name = parser.get(section, 'name')
                        continue

                    val = parser.get(section, option)
                    if '_' in option:
                        (reponame, repoopt) = option.split('_')
                        if repostr.has_key(reponame):
                            repostr[reponame] += "%s:%s," % (repoopt, val)
                        else:
                            repostr[reponame] = "%s:%s," % (repoopt, val)
                        continue

                    if val.split(':')[0] in ('file', 'http', 'https', 'ftp'):
                        if repostr.has_key(option):
                            repostr[option] += "name:%s,baseurl:%s," % \
                                                (option, val)
                        else:
                            repostr[option]  = "name:%s,baseurl:%s," % \
                                                (option, val)
                        continue

                self.bootstraps[name] = repostr