def __obter_versao_ini(nome_extensao): try: versao_ini = obter_caminho_extensao(nome_extensao + r'\versao.ini') with open(versao_ini, 'r') as vi: config = RawConfigParser() config.read_file(vi) if config.has_section('versaoinfo'): return dict(config.items('versaoinfo')) except Exception as e: print(str(e)) print(f'===> Não foi possível obter a versão do "versao.ini"')
def parse_package_metadata(): """ Read the 'metadata' section of 'setup.cfg' to calculate the package metadata (at least those parts that can be configured staticly). """ try: from ConfigParser import RawConfigParser except ImportError: from configparser import RawConfigParser cfg = RawConfigParser() cfg.optionxform = lambda x: x if sys.version_info.major == 2: with open('setup.cfg') as fp: cfg.readfp(fp) else: with open('setup.cfg') as fp: cfg.read_file(fp) metadata = {} for opt in cfg.options('x-metadata'): val = cfg.get('x-metadata', opt) if opt in ('classifiers',): metadata[opt] = [x for x in val.splitlines() if x] elif opt in ('long_description',): # In python 2.7 empty lines in the long description are handled incorrectly, # therefore setup.cfg uses '$' at the start of empty lines. Remove that # character from the description val = val[1:] val = val.replace('$', '') metadata[opt] = val # Add links to interesting location to the long_description metadata[opt] += "\n\nProject links\n" metadata[opt] += "-------------\n" metadata[opt] += "\n" metadata[opt] += "* `Documentation <https://pyobjc.readthedocs.io/en/latest/>`_\n\n" metadata[opt] += "* `Issue Tracker <https://bitbucket.org/ronaldoussoren/pyobjc/issues?status=new&status=open>`_\n\n" metadata[opt] += "* `Repository <https://bitbucket.org/ronaldoussoren/pyobjc/>`_\n\n" elif opt in ('packages', 'namespace_packages', 'platforms', 'keywords'): metadata[opt] = [x.strip() for x in val.split(',')] elif opt in ['zip-safe']: metadata['zip_safe'] = int(val) else: metadata[opt] = val metadata['version'] = package_version() return metadata
def parse_package_metadata(): """ Read the 'metadata' section of 'setup.cfg' to calculate the package metadata (at least those parts that can be configured staticly). """ try: from ConfigParser import RawConfigParser except ImportError: from configparser import RawConfigParser cfg = RawConfigParser() cfg.optionxform = lambda x: x with open("setup.cfg") as fp: cfg.read_file(fp) metadata = {} for opt in cfg.options("x-metadata"): val = cfg.get("x-metadata", opt) if opt in ("classifiers", ): metadata[opt] = [x for x in val.splitlines() if x] elif opt in ("long_description", ): # In python 2.7 empty lines in the long description are handled incorrectly, # therefore setup.cfg uses '$' at the start of empty lines. Remove that # character from the description val = val[1:] val = val.replace("$", "") metadata[opt] = val # Add links to interesting location to the long_description metadata[opt] += "\n\nProject links\n" metadata[opt] += "-------------\n" metadata[opt] += "\n" metadata[ opt] += "* `Documentation <https://pyobjc.readthedocs.io/en/latest/>`_\n\n" metadata[ opt] += "* `Issue Tracker <https://github.com/ronaldoussoren/pyobjc/issues>`_\n\n" metadata[ opt] += "* `Repository <https://github.com/ronaldoussoren/pyobjc/>`_\n\n" elif opt in ("packages", "namespace_packages", "platforms", "keywords"): metadata[opt] = [x.strip() for x in val.split(",")] elif opt in ["zip-safe"]: metadata["zip_safe"] = int(val) else: metadata[opt] = val metadata["version"] = package_version() return metadata
def __obter_ou_atualizar_versao_ini(nome_extensao, versao=None): try: try: lista_ver = [int(v.strip()) for v in versao.split('.')] if versao else [] except Exception as e: raise RuntimeError(f'A versão fornecida é inválida: {versao} {e}') if len(lista_ver) > 3: raise RuntimeError( f'A versão fornecida deve conter até 3 números: {versao}.\n' f'O build_number deve ser fornecido como um parâmetro separado.' ) versao_ini = obter_caminho_extensao(nome_extensao + r'\versao.ini') with open(versao_ini, 'r') as vi: config = RawConfigParser() config.read_file(vi) if config.has_section('versaoinfo'): valores_atuais = dict(config.items('versaoinfo')) if lista_ver: lista_atualizar = ['majorversion', 'minorversion', 'release'] if not config.has_section('versaoinfo'): config.add_section('versaoinfo') for chave, valor in zip(lista_atualizar, (lista_ver + [0, 0])[:3]): texto_valor = str(valor) valores_atuais[chave] = texto_valor config.set('versaoinfo', chave, texto_valor) with open(versao_ini, 'w') as vi: config.write(vi) return valores_atuais except Exception as e: print(str(e)) print(f'===> Não foi possível obter a versão do "versao.ini"')
def override_from_config(self, filename): config = RawConfigParser() if IS_PY3: config.read_file(open(filename)) else: config.readfp(open(filename)) # Common options if config.has_section('bumpr'): for option in config.options('bumpr'): if option in ('tag', 'commit'): self[option] = config.getboolean('bumpr', option) elif option == 'files': # pylint: disable=W0201 self.files = [name.strip() for name in config.get('bumpr', 'files').split('\n') if name.strip()] # pylint: enable=W0201 else: self[option] = config.get('bumpr', option) # Bump and next section for section in 'bump', 'prepare': for option in 'message', 'suffix': if config.has_option(section, option): self[section][option] = config.get(section, option) if config.has_option(section, 'unsuffix'): self[section]['unsuffix'] = config.getboolean(section, 'unsuffix') if config.has_option(section, 'part'): self[section]['part'] = PARTS[config.get(section, 'part').lower()] for hook in HOOKS: if config.has_section(hook.key): if not self.get(hook.key, False): self[hook.key] = hook.defaults self[hook.key].update(config.items(hook.key)) else: self[hook.key] = False
def override_from_config(self, filename): config = RawConfigParser() if IS_PY3: config.read_file(open(filename)) else: config.readfp(open(filename)) # Common options if config.has_section('bumpr'): for option in config.options('bumpr'): if option in ('tag', 'commit'): self[option] = config.getboolean('bumpr', option) elif option == 'files': # pylint: disable=W0201 self.files = [name.strip() for name in config.get('bumpr', 'files').split('\n') if name.strip()] # pylint: enable=W0201 else: self[option] = config.get('bumpr', option) # Bump and next section for section in 'bump', 'prepare': for option in 'message', 'suffix': if config.has_option(section, option): self[section][option] = config.get(section, option) if config.has_option(section, 'unsuffix'): self[section]['unsuffix'] = config.getboolean(section, 'unsuffix') if config.has_option(section, 'part'): self[section]['part'] = PARTS[config.get(section, 'part').lower()] for hook in HOOKS: if config.has_section(hook.key): if not self.get(hook.key, False): self[hook.key] = hook.defaults self[hook.key].update(config.items(hook.key)) else: self[hook.key] = False
request_full_posts = 0 [comments] urls = /comments/#5 ''' arguments = {'--': []} if PY2: from ConfigParser import RawConfigParser config = RawConfigParser(allow_no_value=True) config.readfp(io.BytesIO(default_config.encode('utf-8'))) else: from configparser import RawConfigParser config = RawConfigParser(allow_no_value=True) config.read_file([x for x in default_config.split('\n')]) config_files = [] logger = logging.getLogger('tabun_feed') loglevel = logging.WARNING plugins = {} notify_func = None gevent_used = False class PluginError(Exception): pass def parse_arguments(args):
def parse_mapping(fileobj, filename=None): """Parse an extraction method mapping from a file-like object. >>> buf = StringIO(''' ... [extractors] ... custom = mypackage.module:myfunc ... ... # Python source files ... [python: **.py] ... ... # Genshi templates ... [genshi: **/templates/**.html] ... include_attrs = ... [genshi: **/templates/**.txt] ... template_class = genshi.template:TextTemplate ... encoding = latin-1 ... ... # Some custom extractor ... [custom: **/custom/*.*] ... ''') >>> method_map, options_map = parse_mapping(buf) >>> len(method_map) 4 >>> method_map[0] ('**.py', 'python') >>> options_map['**.py'] {} >>> method_map[1] ('**/templates/**.html', 'genshi') >>> options_map['**/templates/**.html']['include_attrs'] '' >>> method_map[2] ('**/templates/**.txt', 'genshi') >>> options_map['**/templates/**.txt']['template_class'] 'genshi.template:TextTemplate' >>> options_map['**/templates/**.txt']['encoding'] 'latin-1' >>> method_map[3] ('**/custom/*.*', 'mypackage.module:myfunc') >>> options_map['**/custom/*.*'] {} :param fileobj: a readable file-like object containing the configuration text to parse :see: `extract_from_directory` """ extractors = {} method_map = [] options_map = {} parser = RawConfigParser() parser._sections = odict(parser._sections) # We need ordered sections if PY2: parser.readfp(fileobj, filename) else: parser.read_file(fileobj, filename) for section in parser.sections(): if section == 'extractors': extractors = dict(parser.items(section)) else: method, pattern = [part.strip() for part in section.split(':', 1)] method_map.append((pattern, method)) options_map[pattern] = dict(parser.items(section)) if extractors: for idx, (pattern, method) in enumerate(method_map): if method in extractors: method = extractors[method] method_map[idx] = (pattern, method) return method_map, options_map
def cfg_to_args(path='setup.cfg'): """Compatibility helper to use setup.cfg in setup.py. This functions uses an existing setup.cfg to generate a dictionary of keywords that can be used by distutils.core.setup(**kwargs). It is used by generate_setup_py. *file* is the path to the setup.cfg file. If it doesn't exist, PackagingFileError is raised. """ # XXX ** == needs testing D1_D2_SETUP_ARGS = { "name": ("metadata", ), "version": ("metadata", ), "author": ("metadata", ), "author_email": ("metadata", ), "maintainer": ("metadata", ), "maintainer_email": ("metadata", ), "url": ("metadata", "home_page"), "description": ("metadata", "summary"), "long_description": ("metadata", "description"), "download-url": ("metadata", ), "classifiers": ("metadata", "classifier"), "platforms": ("metadata", "platform"), # ** "license": ("metadata", ), "requires": ("metadata", "requires_dist"), "provides": ("metadata", "provides_dist"), # ** "obsoletes": ("metadata", "obsoletes_dist"), # ** "package_dir": ("files", 'packages_root'), "packages": ("files", ), "scripts": ("files", ), "py_modules": ("files", "modules"), # ** } MULTI_FIELDS = ("classifiers", "platforms", "requires", "provides", "obsoletes", "packages", "scripts", "py_modules") def has_get_option(config, section, option): if config.has_option(section, option): return config.get(section, option) elif config.has_option(section, option.replace('_', '-')): return config.get(section, option.replace('_', '-')) else: return False # The real code starts here config = RawConfigParser() f = codecs.open(path, encoding='utf-8') try: config.read_file(f) finally: f.close() kwargs = {} for arg in D1_D2_SETUP_ARGS: if len(D1_D2_SETUP_ARGS[arg]) == 2: # The distutils field name is different than distutils2's section, option = D1_D2_SETUP_ARGS[arg] else: # The distutils field name is the same thant distutils2's section = D1_D2_SETUP_ARGS[arg][0] option = arg in_cfg_value = has_get_option(config, section, option) if not in_cfg_value: # There is no such option in the setup.cfg if arg == 'long_description': filenames = has_get_option(config, section, 'description-file') if filenames: filenames = split_multiline(filenames) in_cfg_value = [] for filename in filenames: fp = codecs.open(filename, encoding='utf-8') try: in_cfg_value.append(fp.read()) finally: fp.close() in_cfg_value = '\n\n'.join(in_cfg_value) else: continue if arg == 'package_dir' and in_cfg_value: in_cfg_value = {'': in_cfg_value} if arg in MULTI_FIELDS: # support multiline options in_cfg_value = split_multiline(in_cfg_value) kwargs[arg] = in_cfg_value return kwargs
def parse_mapping(fileobj, filename=None): """Parse an extraction method mapping from a file-like object. >>> buf = StringIO(''' ... [extractors] ... custom = mypackage.module:myfunc ... ... # Python source files ... [python: **.py] ... ... # Genshi templates ... [genshi: **/templates/**.html] ... include_attrs = ... [genshi: **/templates/**.txt] ... template_class = genshi.template:TextTemplate ... encoding = latin-1 ... ... # Some custom extractor ... [custom: **/custom/*.*] ... ''') >>> method_map, options_map = parse_mapping(buf) >>> len(method_map) 4 >>> method_map[0] ('**.py', 'python') >>> options_map['**.py'] {} >>> method_map[1] ('**/templates/**.html', 'genshi') >>> options_map['**/templates/**.html']['include_attrs'] '' >>> method_map[2] ('**/templates/**.txt', 'genshi') >>> options_map['**/templates/**.txt']['template_class'] 'genshi.template:TextTemplate' >>> options_map['**/templates/**.txt']['encoding'] 'latin-1' >>> method_map[3] ('**/custom/*.*', 'mypackage.module:myfunc') >>> options_map['**/custom/*.*'] {} :param fileobj: a readable file-like object containing the configuration text to parse :see: `extract_from_directory` """ extractors = {} method_map = [] options_map = {} parser = RawConfigParser() parser._sections = OrderedDict(parser._sections) # We need ordered sections if PY2: parser.readfp(fileobj, filename) else: parser.read_file(fileobj, filename) for section in parser.sections(): if section == 'extractors': extractors = dict(parser.items(section)) else: method, pattern = [part.strip() for part in section.split(':', 1)] method_map.append((pattern, method)) options_map[pattern] = dict(parser.items(section)) if extractors: for idx, (pattern, method) in enumerate(method_map): if method in extractors: method = extractors[method] method_map[idx] = (pattern, method) return method_map, options_map