Commits

Anonymous committed 7446f60

0.12.3dev: Improved `trac-admin` command completion when using pyreadline on Windows.

Initial patch by Peter Suter, thanks! Issue reported in comment:12:ticket:9336 and discussed in the following comments.

Comments (0)

Files changed (3)

trac/admin/api.py

     def complete(self, text):
         return list(set(a for a in self if a.startswith(text)))
 
-        
+
+def path_startswith(path, prefix):
+    return os.path.normcase(path).startswith(os.path.normcase(prefix))
+
+
 class PathList(list):
     """A list of paths for command argument auto-completion."""
     def complete(self, text):
         """Return the items in the list matching text."""
-        matches = list(set(a for a in self if a.startswith(text)))
+        matches = list(set(a for a in self if path_startswith(a, text)))
         if len(matches) == 1 and not os.path.isdir(matches[0]):
             matches[0] += ' '
         return matches
     except OSError:
         return result
     for entry in dlist:
-        path = os.path.join(dname, entry)
+        path = os.path.normpath(os.path.join(dname, entry))
         try:
             if os.path.isdir(path):
                 result.append(os.path.join(path, ''))

trac/admin/console.py

 import locale
 import os.path
 import pkg_resources
-import shlex
+from shlex import shlex
 import StringIO
 import sys
 import traceback
         try:
             import readline
             delims = readline.get_completer_delims()
-            for c in '-/:()':
+            for c in '-/:()\\':
                 delims = delims.replace(c, '')
             readline.set_completer_delims(delims)
             
 
         ... but shlex is not unicode friendly.
         """
-        return [unicode(token, 'utf-8')
-                for token in shlex.split(argstr.encode('utf-8'))] or ['']
+        lex = shlex(argstr.encode('utf-8'), posix=True)
+        lex.whitespace_split = True
+        lex.commenters = ''
+        if os.name == 'nt':
+            lex.escape = ''
+        return [unicode(token, 'utf-8') for token in lex] or ['']
 
     def word_complete(self, text, words):
         words = list(set(a for a in words if a.startswith(text)))

trac/admin/tests/console.py

 import unittest
 from StringIO import StringIO
 
+# IAdminCommandProvider implementations
+import trac.admin.api
+import trac.attachment
+import trac.perm
+import trac.ticket.admin
+import trac.versioncontrol.admin
+import trac.versioncontrol.api
+import trac.versioncontrol.web_ui
+import trac.wiki.admin
+
+# IPermissionRequestor implementations (for 'permission' related tests)
+import trac.about
+import trac.admin.web_ui
+import trac.config
+import trac.ticket.api
+import trac.ticket.report
+import trac.ticket.roadmap
+import trac.ticket.web_ui
+import trac.search.web_ui
+import trac.timeline.web_ui
+import trac.wiki.web_ui
+
 from trac.config import Configuration
 from trac.env import Environment
 from trac.admin import console, console_date_format