[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Formating of author field in debian/upstream (Was: [Debichem-commits] r3618 - /unstable/gromacs/debian/upstream)



Hi,

On Mon, May 07, 2012 at 12:53:36AM +0200, Michael Banck wrote:
> Test string input:  Xavier Didelot, Daniel Falush
> 
> (no "and", this one breaks on my patch)

The attached updated patch should get this right.


Michael
Index: blendstasktools.py
===================================================================
--- blendstasktools.py	(Revision 3315)
+++ blendstasktools.py	(Arbeitskopie)
@@ -1488,6 +1488,37 @@
                     if row[pub]:
                         if pub == "pages":
                             row[pub] = re.sub("--", "-", row[pub])
+                        if (pub == "authors" and row[pub].count(" and ") or row[pub].count(" AND ")):
+                            # assume "authors" string is a regular BibTeX "and" separated list of authors
+                            row[pub] = re.sub("AND", "and", row[pub].strip())
+                            authors_list = string.split(row[pub], " and ")
+                            # normalize several BibTeX styles to "First Last, First Last and First Last":
+                            # 1. "First Last and First Last and First Last"
+                            # 2. "Last, First and Last, First and Last, First"
+                            # 3. "First Last, First Last and First Last"
+                            authors_string = ""
+                            while (authors_list):
+                                author = authors_list.pop(0)
+                                if (author.count(",") > 1):
+                                    # 3. "First Last, First Last and First Last"
+                                    # authors string is already in desired format, keep it
+                                    authors_string = row[pub].strip()
+                                    break
+                                elif (row[pub].count(",") == row[pub].count(" and ") + 1):
+                                    # 2. "Last, First and Last, First and Last, First"
+                                    # reverse last and first name
+                                    (last, first) = string.split(author, ", ")
+                                    full_author = first + " " + last
+                                else:
+                                    # 1. "First Last and First Last and First Last"
+                                    full_author = author
+                                if (len(authors_list) > 1):
+                                    authors_string += full_author + ", "
+                                elif (len(authors_list) > 0):
+                                    authors_string += full_author + " and "
+                                else:
+                                    authors_string += full_author
+                            row[pub] = authors_string
                         if not dep.properties.has_key('published'):
                             dep.properties['published'] = {}
                         if dep.properties['published'].has_key(pub):

Reply to: