From 6cd05a95afe799807c90e71d577fb87b1bd01093 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 4 Mar 2012 16:01:29 -0800 Subject: repoman: support overlays without repo_name --- pym/repoman/utilities.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'pym') diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 449005ab1..34d649414 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -1,5 +1,5 @@ # repoman: Utilities -# Copyright 2007-2011 Gentoo Foundation +# Copyright 2007-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 """This module contains utility functions to help repoman find ebuilds to @@ -17,6 +17,7 @@ __all__ = [ "get_commit_message_with_editor", "get_commit_message_with_stdin", "get_committer_name", + "have_ebuild_dir", "have_profile_dir", "parse_metadata_use", "UnknownHerdsError", @@ -30,6 +31,7 @@ from itertools import chain import logging import pwd import re +import stat import sys import time import textwrap @@ -126,6 +128,33 @@ def have_profile_dir(path, maxdepth=3, filename="profiles.desc"): path = normalize_path(path + "/..") maxdepth -= 1 +def have_ebuild_dir(path, maxdepth=3): + """ + Try to figure out if 'path' or a subdirectory contains one or more + ebuild files named appropriately for their parent directory. + """ + stack = [(normalize_path(path), 1)] + while stack: + path, depth = stack.pop() + basename = os.path.basename(path) + try: + listdir = os.listdir(path) + except OSError: + continue + for filename in listdir: + abs_filename = os.path.join(path, filename) + try: + st = os.stat(abs_filename) + except OSError: + continue + if stat.S_ISDIR(st.st_mode): + if depth < maxdepth: + stack.append((abs_filename, depth + 1)) + elif stat.S_ISREG(st.st_mode): + if filename.endswith(".ebuild") and \ + filename.startswith(basename + "-"): + return os.path.dirname(os.path.dirname(path)) + def parse_metadata_use(xml_tree): """ Records are wrapped in XML as per GLEP 56 @@ -447,6 +476,8 @@ def FindPortdir(settings): # file. if not portdir_overlay: portdir_overlay = have_profile_dir(location, filename="repo_name") + if not portdir_overlay: + portdir_overlay = have_ebuild_dir(location) if portdir_overlay: subdir = location[len(portdir_overlay):] if subdir and subdir[-1] != os.sep: -- cgit v1.2.3-1-g7c22