def __init__(self, package_name, version_range=None, paths=None, verbose=False): """Create a PackageHelp object. Args: package_name (str): Package to search. version_range (`VersionRange`): Versions to search. """ self.package = None self._verbose = verbose self._sections = [] # find latest package with a help entry package = None it = iter_packages(package_name, range_=version_range) packages = sorted(it, key=lambda x: x.version, reverse=True) for package_ in packages: if self._verbose: print "searching for help in %s..." % package_.uri if package_.help: package = package_ break if package: help_ = package.help if isinstance(help_, basestring): sections = [["Help", help_]] elif isinstance(help_, list): sections = help_ if self._verbose: print "found %d help entries in %s." % (len(sections), package.uri) # create string formatter for help entries if package.num_variants == 0: base = package.base root = base else: variant = package.get_variant(0) base = variant.base root = variant.root formatter = scoped_formatter( base=base, root=root, config=config, version=VersionBinding(package.version), system=system) # format sections for section in sections: uri = section[1] uri = convert_old_command_expansions(uri) uri = uri.replace("$BROWSER", "").strip() uri = formatter.format(uri) section[1] = uri self.package = package self._sections = sections
def __init__(self, package_name, version_range=None, paths=None, verbose=False): """Create a PackageHelp object. Args: package_name (str): Package to search. version_range (`VersionRange`): Versions to search. """ self.package = None self._verbose = verbose self._sections = [] # find latest package with a help entry package = None it = iter_packages(package_name, range_=version_range) packages = sorted(it, key=lambda x: x.version, reverse=True) for package_ in packages: if self._verbose: print("searching for help in %s..." % package_.uri) if package_.help: package = package_ break if package: help_ = package.help if isinstance(help_, six.string_types): sections = [["Help", help_]] elif isinstance(help_, list): sections = help_ if self._verbose: print("found %d help entries in %s." % (len(sections), package.uri)) # create string formatter for help entries if package.num_variants == 0: base = package.base root = base else: variant = package.get_variant(0) base = variant.base root = variant.root formatter = scoped_formatter( base=base, root=root, config=config, version=VersionBinding(package.version), system=system) # format sections for section in sections: uri = section[1] uri = convert_old_command_expansions(uri) uri = uri.replace("$BROWSER", "").strip() uri = formatter.format(uri) section[1] = uri self.package = package self._sections = sections