Added -l option to specify overlay by name
authorRob Cakebread <pythonhead@gentoo.org>
Sat, 26 Jul 2008 05:01:23 +0000 (05:01 +0000)
committerRob Cakebread <pythonhead@gentoo.org>
Sat, 26 Jul 2008 05:01:23 +0000 (05:01 +0000)
git-svn-id: http://g-pypi.googlecode.com/svn/trunk@6 118783bc-b352-0410-bbc3-0f610f6f7ae8

g_pypi/cli.py
g_pypi/ebuild.py
g_pypi/portage_utils.py

index 4061029832a109e51403b2b0012079d529d35e15..f9e0da3ea97923ff07f897d59c1d55a50db2ec2c 100755 (executable)
@@ -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")
index a6798011bc131666890b4c0b9256a64d43ec2434..408d0d300018c2750178c8fbd3bead8714f9b375 100755 (executable)
@@ -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 = {
index a8b94a3ada54d938ed5141b389e90d4b2550bfd5..7a92a4c3ad5d25919a30467b1aee1bdf4bd6338c 100644 (file)
@@ -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()