Rev 3518: (mbp) patch from Martin von Gagern to run setlocale for libsvn in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jul 3 12:37:05 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3518
revision-id:pqm at pqm.ubuntu.com-20080703113657-6twl1rf07wq3o42d
parent: pqm at pqm.ubuntu.com-20080702195105-5gqthymygmtjrwaf
parent: mbp at sourcefrog.net-20080703104434-v4qgzvxd2wxg8etl
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-07-03 12:36:57 +0100
message:
  (mbp) patch from Martin von Gagern to run setlocale for libsvn
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzr                            bzr.py-20050313053754-5485f144c7006fa6
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/blackbox/test_locale.py test_lang.py-20060824204205-80v50j25qkuop7yn-1
  bzrlib/timestamp.py            timestamp.py-20070306142322-ttbb9oulf3jotljd-1
    ------------------------------------------------------------
    revno: 3517.1.1
    revision-id:mbp at sourcefrog.net-20080703104434-v4qgzvxd2wxg8etl
    parent: pqm at pqm.ubuntu.com-20080702195105-5gqthymygmtjrwaf
    parent: martin.vgagern at gmx.net-20080626172736-z4ro811mbdlqmmzg
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: integration
    timestamp: Thu 2008-07-03 20:44:34 +1000
    message:
      Set locale from environment for third party libs and day of week.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzr                            bzr.py-20050313053754-5485f144c7006fa6
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/tests/blackbox/test_locale.py test_lang.py-20060824204205-80v50j25qkuop7yn-1
      bzrlib/timestamp.py            timestamp.py-20070306142322-ttbb9oulf3jotljd-1
    ------------------------------------------------------------
    revno: 3512.3.2
    revision-id:martin.vgagern at gmx.net-20080626172736-z4ro811mbdlqmmzg
    parent: martin.vgagern at gmx.net-20080626171855-qqok6tbgkouo409t
    committer: Martin von Gagern <Martin.vGagern at gmx.net>
    branch nick: setlocale.mini
    timestamp: Thu 2008-06-26 19:27:36 +0200
    message:
      added NEWS item for setlocale.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3512.3.1
    revision-id:martin.vgagern at gmx.net-20080626171855-qqok6tbgkouo409t
    parent: pqm at pqm.ubuntu.com-20080626004245-dnw85so4xqg8r9hy
    committer: Martin von Gagern <Martin.vGagern at gmx.net>
    branch nick: setlocale.mini
    timestamp: Thu 2008-06-26 19:18:55 +0200
    message:
      Hand-selected minimalistic set of changes from my setlocale branch.
      This introduces a call to setlocale without changing the behaviour of bzr.
      Day of the week formatting is handled in Python to avoid locale dependency.
    modified:
      bzr                            bzr.py-20050313053754-5485f144c7006fa6
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/tests/blackbox/test_locale.py test_lang.py-20060824204205-80v50j25qkuop7yn-1
      bzrlib/timestamp.py            timestamp.py-20070306142322-ttbb9oulf3jotljd-1
=== modified file 'NEWS'
--- a/NEWS	2008-07-02 01:40:02 +0000
+++ b/NEWS	2008-07-03 10:44:34 +0000
@@ -65,6 +65,9 @@
     * revision_history now tolerates mainline ghosts for Branch format 6.
       (Aaron Bentley, #235055)
 
+    * Set locale from environment for third party libs.
+      (Martin von Gagern, #128496)
+
   DOCUMENTATION:
 
     * Updated developer documentation.

=== modified file 'bzr'
--- a/bzr	2008-06-17 01:29:47 +0000
+++ b/bzr	2008-07-03 10:44:34 +0000
@@ -59,6 +59,35 @@
     profile_imports.install()
     profiling = True
 
+if sys.platform == 'darwin':
+    # jameinel says this hack is to force python to honor the LANG setting,
+    # even on Darwin.  Otherwise it is apparently hardcoded to Mac-Roman,
+    # which is incorrect for the normal Terminal.app which wants UTF-8.  
+    #
+    # "It might be that I should be setting the "system locale" somewhere else
+    # on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
+    # Switching to 'posix' and setting LANG worked for me." 
+    #
+    # So we can remove this if someone works out the right way to tell Mac
+    # Python which encoding to use.  -- mbp 20080703
+    sys.platform = 'posix'
+    try:
+        import locale
+    finally:
+        sys.platform = 'darwin'
+else:
+    import locale
+
+try:
+    locale.setlocale(locale.LC_ALL, '')
+except locale.Error, e:
+    sys.stderr.write('bzr: warning: %s\n'
+                     '  bzr could not set the application locale.\n'
+                     '  Although this should be no problem for bzr itself,\n'
+                     '  it might cause problems with some plugins.\n'
+                     '  To investigate the issue, look at the output\n'
+                     '  of the locale(1p) tool available on POSIX systems.\n'
+                     % e)
 
 try:
     import bzrlib

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2008-06-11 03:56:46 +0000
+++ b/bzrlib/osutils.py	2008-06-26 17:18:55 +0000
@@ -641,6 +641,7 @@
     offset = datetime.fromtimestamp(t) - datetime.utcfromtimestamp(t)
     return offset.days * 86400 + offset.seconds
 
+weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
     
 def format_date(t, offset=0, timezone='original', date_fmt=None,
                 show_offset=True):
@@ -672,6 +673,8 @@
         offset_str = ' %+03d%02d' % (offset / 3600, (offset / 60) % 60)
     else:
         offset_str = ''
+    # day of week depends on locale, so we do this ourself
+    date_fmt = date_fmt.replace('%a', weekdays[tt[6]])
     return (time.strftime(date_fmt, tt) +  offset_str)
 
 

=== modified file 'bzrlib/tests/blackbox/test_locale.py'
--- a/bzrlib/tests/blackbox/test_locale.py	2007-08-31 00:35:37 +0000
+++ b/bzrlib/tests/blackbox/test_locale.py	2008-06-26 17:18:55 +0000
@@ -65,6 +65,12 @@
         # as the first part of the string. It may be a little tempermental
         self.assertEqualDiff("""\
 bzr: warning: unsupported locale setting
+  bzr could not set the application locale.
+  Although this should be no problem for bzr itself,
+  it might cause problems with some plugins.
+  To investigate the issue, look at the output
+  of the locale(1p) tool available on POSIX systems.
+bzr: warning: unsupported locale setting
   Could not determine what text encoding to use.
   This error usually means your Python interpreter
   doesn't support the locale set by $LANG (BOGUS)

=== modified file 'bzrlib/timestamp.py'
--- a/bzrlib/timestamp.py	2008-04-24 07:22:53 +0000
+++ b/bzrlib/timestamp.py	2008-06-26 17:18:55 +0000
@@ -56,7 +56,8 @@
         offset = 0
     tt = time.gmtime(t + offset)
 
-    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
+    return (osutils.weekdays[tt[6]] +
+            time.strftime(" %Y-%m-%d %H:%M:%S", tt)
             # Get the high-res seconds, but ignore the 0
             + ('%.9f' % (t - int(t)))[1:]
             + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
@@ -100,6 +101,11 @@
     ...      break
 
     """
+    # Weekday parsing is locale sensitive, so drop the weekday
+    space_loc = date.find(' ')
+    if space_loc == -1 or date[:space_loc] not in osutils.weekdays:
+        raise ValueError(
+            'Date string does not contain a day of week: %r' % date)
     # Up until the first period is a datestamp that is generated
     # as normal from time.strftime, so use time.strptime to
     # parse it
@@ -107,7 +113,7 @@
     if dot_loc == -1:
         raise ValueError(
             'Date string does not contain high-precision seconds: %r' % date)
-    base_time = time.strptime(date[:dot_loc], "%a %Y-%m-%d %H:%M:%S")
+    base_time = time.strptime(date[space_loc:dot_loc], " %Y-%m-%d %H:%M:%S")
     fract_seconds, offset = date[dot_loc:].split()
     fract_seconds = float(fract_seconds)
 




More information about the bazaar-commits mailing list