From: Fabian Groffen <grobian@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Subject: [gentoo-portage-dev] [PATCH 3 of 3] repoman: update copyright on modified files
Date: Wed, 19 Oct 2011 21:55:46 +0200 [thread overview]
Message-ID: <7204f1a467392c31000b.1319054146@nut.cheops.ods.org> (raw)
In-Reply-To: <patchbomb.1319054143@nut.cheops.ods.org>
To retain the behaviour of echangelog, update the copyrights on modified
files (mostly ebuilds) when necessary. We also use this to 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,84 @@
return outvcs
+def update_copyrights(pkgdir, files, year, pretend):
+ """
+ Check list of files for Copyright statements, and update them to
+ 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.
+ patches and diffs (identified by .patch and .diff) are excluded
+ """
+
+ for fn in files:
+ if fn.endswith('.diff') or fn.endswith('.patch'):
+ continue
+
+ fn_path = os.path.join(pkgdir, fn)
+ try:
+ fn_hdl = io.open(_unicode_encode(fn_path,
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'], errors='replace')
+ except EnvironmentError:
+ continue
+
+ 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 +623,12 @@
logging.critical(err)
return None
+ year = time.strftime('%Y')
+ date = time.strftime('%d %b %Y')
+
+ # check modified files and the ChangeLog for copyright updates
+ update_copyrights(pkgdir, new + changed + ['ChangeLog'], year, pretend)
+
cl_path = os.path.join(pkgdir, 'ChangeLog')
clold_lines = []
clnew_lines = []
@@ -578,7 +659,8 @@
# construct correct header first
try:
if clold_file is not None:
- # retain header from old ChangeLog
+ # retain header from old ChangeLog, its copyright has
+ # already been updated by update_copyrights
for line in clold_file:
line_strip = line.strip()
clold_lines.append(line)
@@ -597,7 +679,7 @@
line = line.replace('<CATEGORY>', category)
line = line.replace('<PACKAGE_NAME>', 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()
@@ -651,7 +733,7 @@
if clold_file is not None:
# clold_lines may contain a saved non-header line
# that we want to write first.
- if clold_lines[-1].strip():
+ if len(clold_lines) > 0 and clold_lines[-1].strip():
f.write(clold_lines[-1])
for line in clold_file:
next prev parent reply other threads:[~2011-10-19 19:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-19 19:55 [gentoo-portage-dev] [PATCH 0 of 3] repoman changelog patches Fabian Groffen
2011-10-19 19:55 ` [gentoo-portage-dev] [PATCH 1 of 3] repoman: get default to update changelog from layout.conf Fabian Groffen
2011-10-19 19:55 ` [gentoo-portage-dev] [PATCH 2 of 3] repoman: get ChangeLog header from skel.ChangeLog Fabian Groffen
2011-10-19 21:58 ` Zac Medico
2011-10-20 17:36 ` Fabian Groffen
2011-10-19 19:55 ` Fabian Groffen [this message]
2011-10-19 22:14 ` [gentoo-portage-dev] [PATCH 3 of 3] repoman: update copyright on modified files Zac Medico
2011-10-20 18:23 ` [gentoo-portage-dev] [PATCH] " Fabian Groffen
2011-10-20 18:38 ` Zac Medico
2011-10-20 18:55 ` Mike Gilbert
2011-10-20 19:12 ` Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7204f1a467392c31000b.1319054146@nut.cheops.ods.org \
--to=grobian@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox