[Asterisk-code-review] releases: Fix Unicode support. (repotools[master])

Joshua Colp asteriskteam at digium.com
Wed Apr 6 16:48:01 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: releases: Fix Unicode support.
......................................................................


releases: Fix Unicode support.

This change fixes Unicode support within the release process.

Byte strings were being used when passing Unicode strings around
instead of Unicode strings themselves. This was problematic and
caused things to try to decode to ASCII at times. Now byte strings
are only used when writing data out (such as to the HTML summary).

Some places were also expecting and forcing only ASCII characters.
These have been changed so strings which may contain Unicode remain
Unicode strings for their entirety.

The formatting of strings which contain Unicode are now also created
as Unicode strings instead of ASCII.

Change-Id: Ic57b8ebfcdd42deea9f3d57050253a8bbb7e375e
---
M digium_commits.py
M digium_git.py
M digium_jira_user.py
M mkrelease.py
M release_summary.py
5 files changed, 28 insertions(+), 29 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/digium_commits.py b/digium_commits.py
index 7739e66..5727c20 100644
--- a/digium_commits.py
+++ b/digium_commits.py
@@ -37,7 +37,7 @@
         commit of code.  The blocked attribute will be set to True if the
         string "Blocked revisions " is found in the commit message.
         '''
-        self.message = unicode(message).encode('utf-8')
+        self.message = unicode(message)
         self.author = get_user_by_username(author.strip())
         self.raw = raw
         self.block = False
@@ -224,21 +224,21 @@
         # Create the log message header
         timestamp = datetime.fromtimestamp(
             self.raw.authored_date).strftime('%Y-%m-%d %H:%M +0000')
-        coders = ','.join([str(coder) for coder in self.get_coders()])
-        text = "{0} [{1}]  {2}\n\n".format(timestamp,
+        coders = ','.join([unicode(coder) for coder in self.get_coders()])
+        text = u"{0} [{1}]  {2}\n\n".format(timestamp,
                                            self.raw.hexsha[:10],
                                            coders)
 
         for i, line in enumerate(self.message.split('\n')):
             if i == 0:
-                text += '\t* {0}\n'.format(line)
+                text += u'\t* {0}\n'.format(line)
             elif len(line) != 0:
-                text += '\t  {0}\n'.format(line)
+                text += u'\t  {0}\n'.format(line)
             else:
                 text += '\n'
 
         return text
 
-    def __repr__(self):
-        '''Return a string represenation of the object'''
-        return 'Author: {0}\n{1}'.format(self.author, self.message)
+    def __unicode__(self):
+        '''Return a unicode represenation of the object'''
+        return u'Author: {0}\n{1}'.format(self.author, self.message)
diff --git a/digium_git.py b/digium_git.py
index ac8a837..4a78b7f 100644
--- a/digium_git.py
+++ b/digium_git.py
@@ -284,10 +284,10 @@
 
         digium_commit = DigiumCommitMessageParser(
                             git_commit.message,
-                            unicode(git_commit.author.name).encode('utf-8'),
+                            unicode(git_commit.author.name),
                             git_commit)
         digium_commit.author.email = unicode(
-                git_commit.author.email).encode('utf-8')
+                git_commit.author.email)
         return digium_commit
 
 
diff --git a/digium_jira_user.py b/digium_jira_user.py
index da42e6c..679f741 100644
--- a/digium_jira_user.py
+++ b/digium_jira_user.py
@@ -70,7 +70,7 @@
         self.jira_user_obj = None
         self.organization = None
 
-        self.username = str(username)
+        self.username = username
 
     @property
     def username(self):
@@ -111,19 +111,19 @@
         """
         return not (self.username == other.username)
 
-    def __repr__(self):
-        """Create a string representation of the object"""
+    def __unicode__(self):
+        """Create a unicode representation of the object"""
         name = ''
         if self.full_name:
-            name = unicode(self.full_name).encode('utf-8')
+            name = self.full_name
         elif self.username:
             name = self.username
         else:
-            name = "Unknown"
+            name = unicode("Unknown")
         if self.email:
-            name = "{0} <{1}>".format(name, self.email)
+            name = u"{0} <{1}>".format(name, self.email)
         if self.license:
-            name = "{0} ({1})".format(name, self.license)
+            name = u"{0} ({1})".format(name, self.license)
         return name
 
 
diff --git a/mkrelease.py b/mkrelease.py
index d83897e..f2a17fd 100755
--- a/mkrelease.py
+++ b/mkrelease.py
@@ -296,7 +296,7 @@
             for log_message in summary.raw_log_messages:
                 if log_message.raw and len(log_message.raw.parents) > 1:
                     continue
-                c_file.write(log_message.get_change_log())
+                c_file.write(unicode(log_message.get_change_log()).encode('utf-8'))
 
             with open(old_log_path, 'r') as old_file:
                 for line in old_file:
@@ -530,11 +530,12 @@
     return out_file
 
 
-def create_final_archive(archive):
+def create_final_archive(archive, options):
     """Take the tag archive and create a final release archive from it
 
     Keyword Arguments:
     archive - The full path to the tagged archive
+    options - The parsed command line parameters
     """
 
     def extract_archive():
@@ -672,7 +673,7 @@
     prompt_to_continue("Proceeding to tarball.")
     create_patch_archive(options)
     tag_archive = create_tag_archive(repo)
-    create_final_archive(tag_archive)
+    create_final_archive(tag_archive, options)
 
     prompt_to_continue("Pushing live.")
     os.system('push-release.sh {0} {1}'.format(version.replace('/', '-'), ftp_project))
diff --git a/release_summary.py b/release_summary.py
index 8ff09a1..9452404 100755
--- a/release_summary.py
+++ b/release_summary.py
@@ -376,10 +376,8 @@
 
         issue_a = html.a(href='{0}{1}'.format(JIRA_URL, issue.key))
         issue_a(issue.key)
-        html.raw_text(": {0}<br/>".format(
-            unicode(issue.fields.summary).encode('utf-8')))
-        html.raw_text("Reported by: {0}".format(
-            unicode(issue.fields.reporter.displayName).encode('utf-8')))
+        html.raw_text(u": {0}<br/>".format(issue.fields.summary))
+        html.raw_text(u"Reported by: {0}".format(issue.fields.reporter.displayName))
         log_list = html.ul()
         for log_message in self.jira_commits[issue.key]:
             msg_li = log_list.li()
@@ -390,10 +388,10 @@
                 msg_link = html_blob.a(href='{0}{1}'.format(fisheye_url,
                     log_message.raw.hexsha))
                 msg_link("[{0}]".format(log_message.raw.hexsha[:10]))
-                msg_li.raw_text("{0} {1} -- {2}".format(
+                msg_li.raw_text(u"{0} {1} -- {2}".format(
                     str(msg_link), coders, log_message.get_commit_summary()))
             else:
-                msg_li("{0} -- {1}".format(coders,
+                msg_li(u"{0} -- {1}".format(coders,
                     log_message.get_commit_summary()))
 
     def write_jira_issues_to_html(self, html, issue_type, issues):
@@ -543,7 +541,7 @@
             """
             column = row.td(width='33%')
             for commits, user in contrib_list:
-                column.raw_text('{0} {1}<br/>'.format(commits, user))
+                column.raw_text(u'{0} {1}<br/>'.format(unicode(commits), unicode(user)))
 
         write_sub_heading(root, 'contributors', 'Contributors')
         root.p("This table lists the people who have submitted code, "
@@ -602,7 +600,7 @@
             for log_message in self.misc_commits:
                 coders = [coder.full_name or coder.username for coder in
                           log_message.get_coders()]
-                coders = ','.join(coders).encode('utf-8')
+                coders = ','.join(coders)
                 coder_row = misc_table.tr()
                 rev_column = coder_row.td()
                 if log_message.raw:
@@ -626,7 +624,7 @@
             f.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 "
                     "Transitional//EN\""
                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
-            f.write(str(report))
+            f.write(unicode(report).encode('utf-8'))
 
         # And... done! Write out the txt file too.
         os.system("links2 -dump -width %d %s.html > %s.txt" %

-- 
To view, visit https://gerrit.asterisk.org/2540
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic57b8ebfcdd42deea9f3d57050253a8bbb7e375e
Gerrit-PatchSet: 1
Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list