From 928da0ec02085e5180698e640452ed125f384cb6 Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Thu, 25 Jun 2020 17:36:25 -0700 Subject: [PATCH 1/2] update-maintainer: Find debian/control from inside debian/ In addition to looking for ./debian in the current directory, scan up the path in the case of running update-maintain from inside the debian/ directory. This scans up to a maximum of 6 levels. The --help text is adjusted to identify the detected path if one was found, defaulting to './debian' otherwise. LP: #1885233 Signed-off-by: Bryce Harrington --- update-maintainer | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/update-maintainer b/update-maintainer index 95f551c..65b9d7d 100755 --- a/update-maintainer +++ b/update-maintainer @@ -22,6 +22,18 @@ from ubuntutools.update_maintainer import (update_maintainer, restore_maintainer, MaintainerUpdateException) +def find_debian_dir(depth=6): + """Scans up the directory hierarchy looking for a ./debian dir + + :param int depth: Levels to scan up the directory tree. + :rtype: str + :returns: a path to an existing debian/ directory, or None + """ + for path in ['../'*n or './' for n in list(range(0,depth+1))]: + debian_path = '{}debian'.format(path) + if os.path.exists(debian_path): + return debian_path + return None def main(): script_name = os.path.basename(sys.argv[0]) @@ -30,7 +42,8 @@ def main(): parser = optparse.OptionParser(usage=usage, epilog=epilog) parser.add_option("-d", "--debian-directory", dest="debian_directory", help="location of the 'debian' directory (default: " - "%default).", metavar="PATH", default="./debian") + "%default).", metavar="PATH", + default=find_debian_dir() or './debian') parser.add_option("-r", "--restore", help="Restore the original maintainer", action='store_true', default=False) From 8d77c72c3364daef69b3c9b1345d627dfc1265ea Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Fri, 26 Jun 2020 10:57:46 -0700 Subject: [PATCH 2/2] update-maintainer: Consider only valid-looking debian directories When scanning for debian/ directories to use, only consider ones that have control and changelog files present. This should handle cases where the user may have non-package directories named debian high in their path. --- update-maintainer | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update-maintainer b/update-maintainer index 65b9d7d..ccd1323 100755 --- a/update-maintainer +++ b/update-maintainer @@ -31,7 +31,8 @@ def find_debian_dir(depth=6): """ for path in ['../'*n or './' for n in list(range(0,depth+1))]: debian_path = '{}debian'.format(path) - if os.path.exists(debian_path): + if os.path.exists(os.path.join(debian_path, 'control')) \ + and os.path.exists(os.path.join(debian_path, 'changelog')): return debian_path return None