From 28861486f0006002e082039c70249c279b23493e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 4 Apr 2017 16:50:40 +0100 Subject: [PATCH] ownsource: try to honour .gitignore --- hippotatlib/ownsource.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/hippotatlib/ownsource.py b/hippotatlib/ownsource.py index 218661a..4369cb9 100644 --- a/hippotatlib/ownsource.py +++ b/hippotatlib/ownsource.py @@ -16,10 +16,11 @@ class SourceShipmentPreparer(): s.src_package_globs = ['!/usr/local/*', '/usr*'] s.src_filter_globs = ['!/etc/*'] s.src_likeparent = s.src_likeparent_git + s.src_direxcludes = s.src_direxcludes_git s.report_from_packages = s.report_from_packages_debian s.cwd = os.getcwd() s.find_rune_base = "find -type f -perm -004 \! -path '*/tmp/*'" - s.excludes = ['*~', '*.bak', '*.tmp', '#*#', + s.ignores = ['*~', '*.bak', '*.tmp', '#*#', '__pycache__', '[0-9][0-9][0-9][0-9]-src.cpio'] s.rune_shell = ['/bin/bash', '-ec'] s.show_pathnames = True @@ -57,6 +58,19 @@ class SourceShipmentPreparer(): def src_filter_glob(s, src): # default s.src_filter return s.thing_matches_globs(src, s.src_filter_globs) + def src_direxcludes_git(s, d): + try: + excl = open(os.path.join(d, '.gitignore')) + except FileNotFoundError: + return [] + r = [] + for l in excl: + l.strip + if l.startswith('#'): next + if not len(l): next + r += l + return r + def src_likeparent_git(s, src): try: os.stat(os.path.join(src, '.git/.')) @@ -101,9 +115,12 @@ class SourceShipmentPreparer(): def srcdir_find_rune(s, d): script = s.find_rune_base - for excl in s.excludes + [s.output_name, s.manifest_name]: + ignores = s.ignores + [s.output_name, s.manifest_name] + ignores += s.src_direxcludes(d) + for excl in ignores: assert("'" not in excl) - script += r" \! -name '%s'" % excl + script += r" \! -name '%s'" % excl + script += r" \! -path '*/%s/*'" % excl script += ' -print0' return script -- 2.30.2