From: Rob Cakebread Date: Sat, 26 Jul 2008 05:01:23 +0000 (+0000) Subject: Added -l option to specify overlay by name X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=17d29735cd1571a40968c4e4a15d147f69aebbe1;p=g-pypi.git Added -l option to specify overlay by name git-svn-id: http://g-pypi.googlecode.com/svn/trunk@6 118783bc-b352-0410-bbc3-0f610f6f7ae8 --- diff --git a/g_pypi/cli.py b/g_pypi/cli.py index 4061029..f9e0da3 100755 --- a/g_pypi/cli.py +++ b/g_pypi/cli.py @@ -43,7 +43,7 @@ class StdOut: """ Filter stdout or stderr from specific modules - So far this is just used for pkg_resources + So far this is just used for pkg_resources which is quite noisy """ def __init__(self, stream, modulenames): @@ -354,6 +354,10 @@ def main(): "my_p", default=False, help= "Specify MY_P") + opt_parser.add_option("-l", "--overlay", action='store', dest= + 'overlay', metavar='OVERLAY_NAME', default=None, help= + 'Specify overy to use by name ($OVERLAY/profiles/repo_name)') + opt_parser.add_option("--format", action='store', dest= "format", default=None, help= "Format when printing to stdout: ansi, html, bbcode, or none") diff --git a/g_pypi/ebuild.py b/g_pypi/ebuild.py index a679801..408d0d3 100755 --- a/g_pypi/ebuild.py +++ b/g_pypi/ebuild.py @@ -33,9 +33,9 @@ from pygments.lexers import BashLexer from pygments.formatters import TerminalFormatter, HtmlFormatter from pygments.formatters import BBCodeFormatter -from g_pypi.portage_utils import make_overlay_dir, find_s_dir, unpack_ebuild -from g_pypi.portage_utils import get_portdir, get_workdir, find_egg_info_dir -from g_pypi.portage_utils import valid_cpn, get_installed_ver +from g_pypi.portage_utils import (make_overlay_dir, find_s_dir, unpack_ebuild, + get_portdir, get_workdir, find_egg_info_dir, valid_cpn, + get_installed_ver, get_repo_names) from g_pypi.config import MyConfig from g_pypi import enamer from g_pypi.__init__ import __version__ as VERSION @@ -475,8 +475,20 @@ class Ebuild: def write_ebuild(self, overwrite=False): """Write ebuild file""" + #Use command-line overlay if specified, else the one in .g-pyprc + if self.options.overlay: + overlay_name = self.options.overlay + overlays = get_repo_names() + if overlays.has_key(overlay_name): + overlay_path = overlays[overlay_name] + else: + self.logger.error("Couldn't find overylay by that name. I know about these:") + self.logger.error(overlays) + sys.exit(1) + else: + overlay_path = self.config['overlay'] ebuild_dir = make_overlay_dir(self.options.category, self.vars['pn'], \ - self.config['overlay']) + overlay_path) if not ebuild_dir: self.logger.error("Couldn't create overylay ebuild directory.") sys.exit(2) @@ -484,7 +496,7 @@ class Ebuild: self.vars['p']) if os.path.exists(self.ebuild_path) and not overwrite: #self.logger.error("Ebuild exists. Use -o to overwrite.") - self.logger.error("Ebuild exists, skipping: %s" % self.ebuild_path) + self.logger.warn("Ebuild exists, skipping: %s" % self.ebuild_path) return try: out = open(self.ebuild_path, "w") @@ -527,6 +539,7 @@ def get_portage_license(my_license): Map defined classifier license to Portage license http://cheeseshop.python.org/pypi?%3Aaction=list_classifiers + We should probably check this list with every major list, eh? """ my_license = my_license.split(":: ")[-1:][0] known_licenses = { diff --git a/g_pypi/portage_utils.py b/g_pypi/portage_utils.py index a8b94a3..7a92a4c 100644 --- a/g_pypi/portage_utils.py +++ b/g_pypi/portage_utils.py @@ -16,7 +16,9 @@ import commands import logging #import fnmatch -import portage +from portage import config as portage_config +from portage import settings as portage_settings +from portage.const import REPO_NAME_LOC try: #portage >= 2.2 @@ -31,12 +33,33 @@ import gentoolkit __docformat__ = 'restructuredtext' -ENV = portage.config(clone=portage.settings).environ() +ENV = portage_config(clone=portage_settings).environ() LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) LOGGER.addHandler(logging.StreamHandler()) +def get_repo_names(): + """ + Return a dict of overlay names with their paths + e.g. + {'reponame': '/path/to/repo', ...} + + @returns: dict with repoman/paths + + """ + porttrees = [ENV['PORTDIR']] + \ + [os.path.realpath(t) for t in ENV["PORTDIR_OVERLAY"].split()] + treemap = {} + for path in porttrees: + repo_name_path = os.path.join(path, REPO_NAME_LOC) + try: + repo_name = open(repo_name_path, 'r').readline().strip() + treemap[repo_name] = path + except (OSError,IOError): + LOGGER.warn("No repo_name in %s" % path) + return treemap + def get_installed_ver(cpn): """ Return PV for installed version of package @@ -251,3 +274,5 @@ def find_egg_info_dir(root): # for path, dirs, files in os.walk(os.path.abspath(root)): # for filename in fnmatch.filter(dirs, pattern): # yield os.path.join(path, filename) +if __name__ == '__main__': + print get_repo_names()