Changeset 423

Show
Ignore:
Timestamp:
05/17/07 09:02:10 (2 years ago)
Author:
athomas
Message:

cly:

  • Converted Wiki tutorial to RST.
  • Cleaned up doc directory.
  • Renamed cly.variables.LocalFile to File.
  • Fixed a few bugs in File completion.
  • Nuked all non-whitespace delimeters.
  • Fixed a bug where cly.console failed to work under pydoc.
  • Updated setup.py in preparation for release.
  • Added README.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cly/trunk/cly/console.py

    r422 r423  
    5252 
    5353 
    54 try: 
    55     import curses 
    56     curses.setupterm() 
    57     if curses.tigetnum('colors') >= 0: 
    58         _colour_terminal = 1 
    59 except: 
    60     pass 
     54if sys.stdout.isatty(): 
     55    try: 
     56        import curses 
     57        curses.setupterm() 
     58        if curses.tigetnum('colors') >= 0: 
     59            _colour_terminal = 1 
     60    except: 
     61        pass 
     62 
     63    try: 
     64        import msvcrt 
     65        def getch(): 
     66            """Get a single character from the terminal.""" 
     67            return msvcrt.getch() 
     68    except ImportError: 
     69        def getch(): 
     70            """Get a single character from the terminal.""" 
     71            import tty 
     72            import termios 
     73 
     74            fd = sys.stdin.fileno() 
     75            old_settings = termios.tcgetattr(fd) 
     76            try: 
     77                tty.setraw(sys.stdin.fileno()) 
     78                ch = sys.stdin.read(1) 
     79            finally: 
     80                termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 
     81            return ch 
    6182 
    6283 
     
    440461        rowalt += 1 
    441462 
    442 try: 
    443     import msvcrt 
    444     def getch(): 
    445         """Get a single character from the terminal.""" 
    446         return msvcrt.getch() 
    447 except ImportError: 
    448     import tty, sys, termios 
    449  
    450     def getch(): 
    451         """Get a single character from the terminal.""" 
    452         fd = sys.stdin.fileno() 
    453         old_settings = termios.tcgetattr(fd) 
    454         try: 
    455             tty.setraw(sys.stdin.fileno()) 
    456             ch = sys.stdin.read(1) 
    457         finally: 
    458             termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 
    459         return ch 
    460  
    461 getch.__doc__ = " Read a single character from stdin. " 
    462  
    463463 
    464464if __name__ == '__main__': 
  • cly/trunk/cly/interactive.py

    r421 r423  
    6161                 user_context=None, history_file=None, history_length=500, 
    6262                 completion_key='tab', 
    63                  completion_delimiters='`!#$%^&*()=+[{]}\|;\'",<>? \t', 
     63                 #completion_delimiters='`!#$%^&*()=+[{]}\|;\'",<>? \t', 
     64                 completion_delimiters=' \t', 
    6465                 help_key='?'): 
    6566        if prompt is None: 
  • cly/trunk/cly/rlext.c

    r403 r423  
     1/* 
     2 * 
     3 * Copyright (C) 2006-2007 Alec Thomas <alec@swapoff.org> 
     4 * 
     5 * This software is licensed as described in the file COPYING, which 
     6 * you should have received as part of this distribution. 
     7 * 
     8 * 
     9*/ 
    110#include "Python.h" 
    211#include <readline/readline.h> 
  • cly/trunk/cly/variables.py

    r413 r423  
    1717 
    1818__all__ = ['Word', 'String', 'URI', 'LDAPDN', 'Integer', 'Float', 'IP', 
    19            'Hostname', 'Host', 'EMail', 'LocalFile'] 
     19           'Hostname', 'Host', 'EMail', 'File'] 
    2020 
    2121 
     
    179179 
    180180 
    181 class LocalFile(Variable): 
     181class File(Variable): 
    182182    """Match and provide completion candidates for local files. 
    183183 
    184184    >>> from cly import * 
    185     >>> parser = Parser(Grammar(foo=LocalFile('Foo'))) 
     185    >>> parser = Parser(Grammar(foo=File('Foo', allow_directories=True))) 
    186186    >>> parser.parse('.').vars['foo'] 
    187187    '.' 
     
    190190    includes = ['*'] 
    191191    excludes = [] 
    192     dotfiles = False 
     192    allow_dotfiles = False 
     193    allow_directories = False 
    193194 
    194195    def match(self, context): 
    195196        match = Variable.match(self, context) 
    196         if match and os.path.exists(os.path.expanduser(match.group())): 
     197        if match and self.match_file(match.group(), self.allow_directories): 
    197198            return match 
     199 
     200    def match_file(self, file, match_directories=True): 
     201        from fnmatch import fnmatch 
     202        file = os.path.expanduser(file) 
     203        if match_directories and os.path.isdir(file): 
     204            return True 
     205        if not self.allow_dotfiles and os.path.basename(file).startswith('.'): 
     206            return False 
     207        for exclude in self.excludes: 
     208            if fnmatch(file, exclude): 
     209                return False 
     210        for include in self.includes: 
     211            if fnmatch(file, include): 
     212                return True 
     213        return False 
    198214 
    199215    def candidates(self, context, text): 
    200216        """Return list of valid file candidates.""" 
    201         from fnmatch import fnmatch 
    202217 
    203218        if text.startswith('~'): 
     
    223238            return file 
    224239 
    225         def match(file): 
    226             if os.path.isdir(file): 
    227                 return True 
    228             for exclude in self.excludes: 
    229                 if fnmatch(file, exclude): 
    230                     return False 
    231             for include in self.includes: 
    232                 if fnmatch(file, include): 
    233                     return True 
    234             return False 
    235  
    236240        def get_candidates(dir, file): 
    237241            return [f for f in os.listdir(dir) if f.startswith(file) 
    238                     and match(os.path.join(dir, f))] 
     242                    and self.match_file(os.path.join(dir, f))] 
    239243 
    240244        candidates = get_candidates(dir, file) 
     
    242246            if os.path.isdir(os.path.join(dir, candidates[0])): 
    243247                dir = os.path.join(dir, candidates[0] + '/') 
     248                return [dir] 
    244249                file = '' 
    245250                candidates = get_candidates(dir, file) 
     
    247252                return [clean(os.path.join(dir, candidates[0] + ' '))] 
    248253        return [clean(os.path.join(dir, f)) 
    249                 for f in candidates if self.dotfiles or f[0] != '.'] 
     254                for f in candidates if self.allow_dotfiles or f[0] != '.'] 
    250255 
    251256 
  • cly/trunk/setup.py

    r413 r423  
    1111      author_email='alec@swapoff.org', 
    1212      version=cly.__version__, 
     13      description="CLY is a Python module for simplifying the creation of interactive shells. Kind of like the builtin `cmd` module on steroids.", 
     14      long_description=cly.__doc__, 
     15      license='BSD', 
     16      platforms=['any'], 
    1317      packages=['cly'], 
    1418      test_suite='cly.test.suite', 
     19      classifiers=['Development Status :: 3 - Alpha', 
     20                   'Intended Audience :: Developers', 
     21                   'License :: OSI Approved :: BSD License', 
     22                   'Operating System :: OS Independent', 
     23                   'Topic :: System :: Shells', 
     24                   'Environment :: Console', 
     25                   'Topic :: Software Development :: Libraries'], 
    1526      ext_modules=[Extension('cly.rlext', ['cly/rlext.c'], 
    1627                             libraries = ['readline', 'curses'])])