def _extract_pathogen_repos(repo_contents): """Extracts Pathogen plugin repos from a GitHub dotfiles repository. This currently just extracts plugins if they are checked in as submodules, because it's easy to extract repo URLs from the .gitmodules file but difficult to determine the repo URL of a plugin that's just cloned in. Arguments: repo_contents: API response from GitHub of a directory or repo's contents. Returns: A list of tuples (owner, repo_name) referencing GitHub repos. """ gitmodules = filter( lambda f: f['type'] == 'file' and f['name'].lower() == '.gitmodules', repo_contents) if not gitmodules: return [] _, file_contents = get_api_page(gitmodules[0]['url']) contents_decoded = base64.b64decode(file_contents.get('content', '')) contents_unicode = unicode(contents_decoded, 'utf-8', errors='ignore') parser = configparser.ConfigParser(interpolation=None) try: parser.read_string(unicode(contents_unicode)) except configparser.Error: logging.exception( colored( 'Could not parse the .gitmodules file of %s.' % file_contents['url'], 'red')) return [] plugin_repos = [] for section, config in parser.items(): if not _SUBMODULE_IS_BUNDLE_REGEX.search(section): continue if not config.get('url'): continue # The parser sometimes over-parses the value url = config['url'].split('\n')[0] match = _BUNDLE_OWNER_REPO_REGEX.search(url) if match and len(match.groups()) == 2 and match.group(1): owner, repo = match.groups() plugin_repos.append((owner, repo)) else: logging.error( colored('Failed to extract owner/repo from "%s"' % url, 'red')) return plugin_repos
def _extract_pathogen_repos(repo_contents): """Extracts Pathogen plugin repos from a GitHub dotfiles repository. This currently just extracts plugins if they are checked in as submodules, because it's easy to extract repo URLs from the .gitmodules file but difficult to determine the repo URL of a plugin that's just cloned in. Arguments: repo_contents: API response from GitHub of a directory or repo's contents. Returns: A list of tuples (owner, repo_name) referencing GitHub repos. """ gitmodules = filter(lambda f: f['type'] == 'file' and f['name'].lower() == '.gitmodules', repo_contents) if not gitmodules: return [] _, file_contents = get_api_page(gitmodules[0]['url']) contents_decoded = base64.b64decode(file_contents.get('content', '')) contents_unicode = unicode(contents_decoded, 'utf-8', errors='ignore') parser = configparser.ConfigParser(interpolation=None) try: parser.read_string(unicode(contents_unicode)) except configparser.Error: logging.exception(colored( 'Could not parse the .gitmodules file of %s.' % file_contents['url'], 'red')) return [] plugin_repos = [] for section, config in parser.items(): if not _SUBMODULE_IS_BUNDLE_REGEX.search(section): continue if not config.get('url'): continue # The parser sometimes over-parses the value url = config['url'].split('\n')[0] match = _BUNDLE_OWNER_REPO_REGEX.search(url) if match and len(match.groups()) == 2 and match.group(1): owner, repo = match.groups() plugin_repos.append((owner, repo)) else: logging.error(colored( 'Failed to extract owner/repo from "%s"' % url, 'red')) return plugin_repos
def config(section='postgresql', filename='database.ini'): parser = ConfigParser() parser.read(filename) arguments = {} if parser.has_section(section): params = parser.items(section) for param in params: arguments[param[0]] = param[1] else: raise Exception(f'Section {section} not found in the {filename} file') return arguments
def load_config(): try: parser = SafeConfigParser() parser.read('config.ini') items = parser.items('pindown') config = {} for item in items: config[item[0]] = item[1] log.debug("Config loaded") return config except Exception as e: log.error(e.message) return False
def parse_config(filename): """ Parse input file into config dictionary. For each section in the input file it will create a key with the value being a dictionary of key value pairs of options from that section. """ if not os.path.exists(filename): raise ConfigError('Config file does not exist.') parser = ConfigParser.RawConfigParser() parser.read(filename) cfg = {} for section in parser.sections(): cfg[section] = dict(parser.items(section)) return cfg
def init(): ''' method to parse global conf return Configdictionary ''' confname = os.path.join(os.getcwd(), '..', 'global.conf') cDict = {} parser = SafeConfigParser() parser.read(confname) for section_name in parser.sections(): for name, value in parser.items(section_name): cDict[name] = value logger.info('\033[31m Global Configuration %s \033[0m \n' % (cDict)) return cDict
def __init_config(self, blog, config): parser = ConfigParser() parser.read(config) if not parser.has_section(blog): raise Exception('blog "%s" not in config "%s"' % (blog, config)) self.__cfg = dict(parser.items(blog))