UpdateChangeLog: split out get_committer_name()
authorZac Medico <zmedico@gentoo.org>
Fri, 21 Oct 2011 04:07:34 +0000 (21:07 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 21 Oct 2011 04:07:34 +0000 (21:07 -0700)
bin/repoman
pym/repoman/utilities.py

index 5b01825b7c98d0be1197f8285d48493ef6fb419e..bf91b85a93593738b0bc297f3ad9a32a186fa83f 100755 (executable)
@@ -2447,6 +2447,7 @@ else:
 
        if options.echangelog in ('y', 'force'):
                logging.info("checking for unmodified ChangeLog files")
+               committer_name = utilities.get_committer_name(env=repoman_settings)
                for x in sorted(vcs_files_to_cps(
                        chain(myupdates, mymanifests, myremoved))):
                        catdir, pkgdir = x.split("/")
@@ -2468,10 +2469,12 @@ else:
                        clnew = [elem[cdrlen:] for elem in mynew if elem.startswith(checkdir_relative)]
                        clremoved = [elem[cdrlen:] for elem in myremoved if elem.startswith(checkdir_relative)]
                        clchanged = [elem[cdrlen:] for elem in mychanged if elem.startswith(checkdir_relative)]
-                       new_changelog = utilities.UpdateChangeLog(checkdir_relative, \
-                               catdir, pkgdir, \
-                               clnew, clremoved, clchanged, \
-                               changelog_msg, options.pretend, repodir)
+                       new_changelog = utilities.UpdateChangeLog(checkdir_relative,
+                               committer_name, changelog_msg,
+                               os.path.join(repodir, 'skel.ChangeLog'),
+                               catdir, pkgdir,
+                               new=clnew, removed=clremoved, changed=clchanged,
+                               pretend=options.pretend)
                        if new_changelog is None:
                                writemsg_level("!!! Updating the ChangeLog failed\n", \
                                        level=logging.ERROR, noiselevel=-1)
index c1a9da84af5492456e7d502f5837272486bb3188..0ecc92cc7617f123ccb1754c4524f170ffb4effd 100644 (file)
@@ -16,6 +16,7 @@ __all__ = [
        "format_qa_output",
        "get_commit_message_with_editor",
        "get_commit_message_with_stdin",
+       "get_committer_name",
        "have_profile_dir",
        "parse_metadata_use",
        "UnknownHerdsError",
@@ -588,30 +589,34 @@ def update_copyright(fn_path, year, pretend):
                        util.apply_stat_permissions(fn_path, fn_stat)
        fn_hdl.close()
 
-def UpdateChangeLog(pkgdir, category, package, new, removed, changed, \
-               msg, pretend, repodir):
+def get_committer_name(env=None):
+       """Generate a committer string like echangelog does."""
+       if env is None:
+               env = os.environ
+       if 'GENTOO_COMMITTER_NAME' in env and \
+               'GENTOO_COMMITTER_EMAIL' in env:
+               user = '%s <%s>' % (env['GENTOO_COMMITTER_NAME'],
+                       env['GENTOO_COMMITTER_EMAIL'])
+       elif 'GENTOO_AUTHOR_NAME' in env and \
+                       'GENTOO_AUTHOR_EMAIL' in env:
+               user = '%s <%s>' % (env['GENTOO_AUTHOR_NAME'],
+                       env['GENTOO_AUTHOR_EMAIL'])
+       elif 'ECHANGELOG_USER' in env:
+               user = env['ECHANGELOG_USER']
+       else:
+               pwd_struct = pwd.getpwuid(os.getuid())
+               gecos = pwd_struct.pw_gecos.split(',')[0]  # bug #80011
+               user = '%s <%s@gentoo.org>' % (gecos, pwd_struct.pw_name)
+       return user
+
+def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
+       new=(), removed=(), changed=(), pretend=False):
        """
        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 \
-                       'GENTOO_COMMITTER_EMAIL' in os.environ:
-               user = '%s <%s>' % (os.environ['GENTOO_COMMITTER_NAME'], \
-                               os.environ['GENTOO_COMMITTER_EMAIL'])
-       elif 'GENTOO_AUTHOR_NAME' in os.environ and \
-                       'GENTOO_AUTHOR_EMAIL' in os.environ:
-               user = '%s <%s>' % (os.environ['GENTOO_AUTHOR_NAME'], \
-                               os.environ['GENTOO_AUTHOR_EMAIL'])
-       elif 'ECHANGELOG_USER' in os.environ:
-               user = os.environ['ECHANGELOG_USER']
-       else:
-               pwd_struct = pwd.getpwuid(os.getuid())
-               gecos = pwd_struct.pw_gecos.split(',')[0]  # bug #80011
-               user = '%s <%s@gentoo.org>' % (gecos, pwd_struct.pw_name)
-
        if '<root@' in user:
                err = 'Please set ECHANGELOG_USER or run as non-root'
                logging.critical(err)
@@ -647,8 +652,7 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, \
                # we will only need the ChangeLog skeleton if there is no
                # ChangeLog yet
                try:
-                       clskel_path = os.path.join(repodir, 'skel.ChangeLog')
-                       clskel_file = io.open(_unicode_encode(clskel_path,
+                       clskel_file = io.open(_unicode_encode(skel_path,
                                encoding=_encodings['fs'], errors='strict'),
                                mode='r', encoding=_encodings['repo.content'],
                                errors='replace')