Rev 4488: (igc) Teach get_app_path to read wordpad.exe (Alexander Belchenko) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sat Jun 27 01:29:55 BST 2009


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

------------------------------------------------------------
revno: 4488 [merge]
revision-id: pqm at pqm.ubuntu.com-20090627002953-q4333x7hfvw1q3wz
parent: pqm at pqm.ubuntu.com-20090626180331-304i6c0fz5nc54fs
parent: ian.clatworthy at canonical.com-20090626232846-i9dimb1ktctogdsg
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2009-06-27 01:29:53 +0100
message:
  (igc) Teach get_app_path to read wordpad.exe (Alexander Belchenko)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_win32utils.py test_win32utils.py-20070713181630-8xsrjymd3e8mgw23-108
  bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
=== modified file 'NEWS'
--- a/NEWS	2009-06-26 09:24:34 +0000
+++ b/NEWS	2009-06-26 23:28:46 +0000
@@ -83,6 +83,9 @@
   rather than requiring all command names be known a-priori.
   (Robert Collins)
 
+* ``get_app_path`` from win32utils.py now supports REG_EXPAND_SZ data type
+  and can read path to wordpad.exe. (Alexander Belchenko, #392046)
+
 * ``graph.KnownGraph`` has been added. This is a class that can give
   answers to ``heads()`` very quickly. However, it has the assumption that
   the whole graph has already been loaded. This is true during

=== modified file 'bzrlib/tests/test_win32utils.py'
--- a/bzrlib/tests/test_win32utils.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_win32utils.py	2009-06-25 10:05:17 +0000
@@ -164,6 +164,16 @@
             self.assertEquals('iexplore.exe', b.lower())
             self.assertNotEquals('', d)
 
+    def test_wordpad(self):
+        # typical windows users should have wordpad in the system
+        # but there is problem: its path has the format REG_EXPAND_SZ
+        # so naive attempt to get the path is not working
+        for a in ('wordpad', 'wordpad.exe'):
+            p = get_app_path(a)
+            d, b = os.path.split(p)
+            self.assertEquals('wordpad.exe', b.lower())
+            self.assertNotEquals('', d)
+
     def test_not_existing(self):
         p = get_app_path('not-existing')
         self.assertEquals('not-existing', p)

=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py	2009-06-10 06:25:56 +0000
+++ b/bzrlib/win32utils.py	2009-06-26 07:15:24 +0000
@@ -96,6 +96,10 @@
 UNLEN = 256
 MAX_COMPUTERNAME_LENGTH = 31
 
+# Registry data type ids
+REG_SZ = 1
+REG_EXPAND_SZ = 2
+
 
 def debug_memory_win32api(message='', short=True):
     """Use trace.note() to dump the running memory info."""
@@ -462,25 +466,34 @@
                 or appname itself if nothing found.
     """
     import _winreg
+
+    basename = appname
+    if not os.path.splitext(basename)[1]:
+        basename = appname + '.exe'
+
     try:
         hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
-                               r'SOFTWARE\Microsoft\Windows'
-                               r'\CurrentVersion\App Paths')
+            'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' +
+            basename)
     except EnvironmentError:
         return appname
 
-    basename = appname
-    if not os.path.splitext(basename)[1]:
-        basename = appname + '.exe'
     try:
         try:
-            fullpath = _winreg.QueryValue(hkey, basename)
+            path, type_id = _winreg.QueryValueEx(hkey, '')
         except WindowsError:
-            fullpath = appname
+            return appname
     finally:
         _winreg.CloseKey(hkey)
 
-    return fullpath
+    if type_id == REG_SZ:
+        return path
+    if type_id == REG_EXPAND_SZ and has_win32api:
+        fullpath = win32api.ExpandEnvironmentStrings(path)
+        if len(fullpath) > 1 and fullpath[0] == '"' and fullpath[-1] == '"':
+            fullpath = fullpath[1:-1]   # remove quotes around value
+        return fullpath
+    return appname
 
 
 def set_file_attr_hidden(path):




More information about the bazaar-commits mailing list