From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RGxHm-0000P1-8v for garchives@archives.gentoo.org; Thu, 20 Oct 2011 18:24:10 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4B7F021C062; Thu, 20 Oct 2011 18:23:56 +0000 (UTC) Received: from amun.cheops.ods.org (amun.cheops.ods.org [83.161.135.166]) by pigeon.gentoo.org (Postfix) with ESMTP id 98E4721C04B for ; Thu, 20 Oct 2011 18:23:46 +0000 (UTC) Received: from nut.cheops.ods.org ([172.17.2.83]) by amun.cheops.ods.org with esmtp (Exim 4.77) (envelope-from ) id 1RGxHL-0007nf-9h; Thu, 20 Oct 2011 20:23:45 +0200 Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [gentoo-portage-dev] [PATCH] repoman: update copyright on modified files X-Mercurial-Node: 2f204b2ec375bba6598fcc88b2dc6c74edac0521 Message-Id: <2f204b2ec375bba6598f.1319135020@nut.cheops.ods.org> In-Reply-To: <4E9F4BCC.2030601@gentoo.org> References: <4E9F4BCC.2030601@gentoo.org> User-Agent: Mercurial-patchbomb/1.9.3 Date: Thu, 20 Oct 2011 20:23:40 +0200 From: Fabian Groffen To: gentoo-portage-dev@lists.gentoo.org X-Content-Scanned: by amun.cheops.ods.org (Exim Exiscan) using SpamAssassin and ClamAV X-Archives-Salt: X-Archives-Hash: 205c5395b53c629c02ada17e932327a1 To retain the behaviour of echangelog, update the copyrights on modified files (mostly ebuilds) when necessary. Also update the ChangeLog's copyright. diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -523,9 +523,77 @@ return outvcs +def update_copyright(fn_path, year, pretend): + """ + Check file for a Copyright statement, and update its year. The + patterns used for replacing copyrights are taken from echangelog. + Only the first lines of each file that start with a hash ('#') are + considered, until a line is found that doesn't start with a hash. + """ + + try: + fn_hdl = io.open(_unicode_encode(fn_path, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['repo.content'], errors='replace') + except EnvironmentError: + return + + orig_header = [] + new_header = [] + + for line in fn_hdl: + line_strip = line.strip() + orig_header.append(line) + if not line_strip or line_strip[:1] != '#': + new_header.append(line) + break + + # these two regexes are taken from + # echangelog update_copyright() + line = re.sub(r'^(# Copyright \d+) ', + r'\1-%s ' % year, line) + line = re.sub(r'^(# Copyright) \d\d\d\d-\d\d\d\d', + r'\1 1999-%s' % year, line) + new_header.append(line) + + difflines = 0 + for line in difflib.unified_diff(orig_header, new_header, + fromfile=fn_path, tofile=fn_path, n=0): + util.writemsg_stdout(line, noiselevel=-1) + difflines += 1 + util.writemsg_stdout("\n", noiselevel=-1) + + # unified diff has three lines to start with + if difflines > 3 and not pretend: + # write new file with changed header + f, fnnew_path = mkstemp() + f = io.open(f, mode='w', encoding=_encodings['repo.content'], + errors='backslashreplace') + for line in new_header: + f.write(line); + for line in fn_hdl: + f.write(line) + f.close() + try: + fn_stat = os.stat(fn_path) + except OSError: + fn_stat = None + + shutil.move(fnnew_path, fn_path) + + if fn_stat is None: + util.apply_permissions(fn_path, mode=0o644) + else: + util.apply_stat_permissions(fn_path, fn_stat) + fn_hdl.close() + def UpdateChangeLog(pkgdir, category, package, new, removed, changed, \ msg, pretend, repodir): - """ Write an entry to an existing ChangeLog, or create a new one. """ + """ + Write an entry to an existing ChangeLog, or create a new one. + Updates copyright year on changed files, and updates the header of + ChangeLog with the contents of skel.ChangeLog. + """ # figure out who to write as if 'GENTOO_COMMITTER_NAME' in os.environ and \ @@ -548,6 +616,16 @@ logging.critical(err) return None + year = time.strftime('%Y') + date = time.strftime('%d %b %Y') + + # check modified files and the ChangeLog for copyright updates + # patches and diffs (identified by .patch and .diff) are excluded + for fn in new + changed: + if fn.endswith('.diff') or fn.endswith('.patch'): + continue + update_copyright(os.path.join(pkgdir, fn), year, pretend) + cl_path = os.path.join(pkgdir, 'ChangeLog') clold_lines = [] clnew_lines = [] @@ -584,8 +662,9 @@ clold_lines.append(line) if line_strip[:1] != '#': break - if clskel_file is None: - clnew_lines.append(line) + line = re.sub(r'^(# Copyright) \d\d\d\d-\d\d\d\d', + r'\1 1999-%s' % year, line) + clnew_lines.append(line) if not line_strip: break elif clskel_file is not None: @@ -597,7 +676,7 @@ line = line.replace('', category) line = line.replace('', package) line = re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ', - r'\1-%s ' % time.strftime('%Y'), line) + r'\1-%s ' % year, line) clnew_lines.append(line) clnew_lines.append(_unicode_decode('\n')) clskel_file.close()