예제 #1
0
def x_man_page(url):
    """x_man_page(url) -> None

    Asynchronously open a session with the '/usr/bin/man' command
    based on the given "x-man-page://" URL.

    Raises an exception for some failures.  Note, however, that
    as an asynchronous process spawn, other types of failures
    could occur later that are not trapped at call time.

    (Below are REAL testcases run by doctest!)

    >>> x_man_page('x-man-page://ls')

    >>> x_man_page('x-man-page://3/printf')

    """
    url_info = _parse_x_man_page(url)
    cmd = url_info.get('cmd', None)
    section = url_info.get('section', None)
    # pull the command name and optional section number out of the URL path
    if section is not None:
        ignored_session = quills.Session(['/usr/bin/man', section, cmd])
    elif cmd is not None:
        ignored_session = quills.Session(['/usr/bin/man', cmd])
    else:
        raise ValueError("unsupported form of x-man-page URL")
예제 #2
0
def script(pathname):
    """script(pathname) -> None

    Asynchronously open a session from the given script file, by
    running the script!  Raise an exception on failure.

    """
    args = [pathname]
    ignored_session = quills.Session(args)
예제 #3
0
def sftp(url):
    """sftp(url) -> None

    Asynchronously open a session with the '/usr/bin/sftp'
    command based on the given "sftp://" URL.

    Raises an exception for some failures.  Note, however, that
    as an asynchronous process spawn, other types of failures
    could occur later that are not trapped at call time.

    WARNING: The specification for this URL type is not complete.
    This implementation does not yet provide support for all
    possible bits of information suggested in the proposals to
    date.  It probably needs to be updated when this becomes a
    standard.  (Aren't you glad it's in Python so it's easy to
    fix when that day comes?  I am!!!)

    (Below are REAL testcases run by doctest!)

    >>> sftp('sftp://yourserver.com')

    >>> sftp('sftp://[email protected]:12345')

    >>> try:
    ...        sftp('not an sftp url!')
    ... except ValueError as e:
    ...        print(e)
    not an sftp URL

    """
    url_info = _parse_sftp(url)
    host = url_info.get('host', None)
    user = url_info.get('user', None)
    port = url_info.get('port', None)
    if host is not None:
        args = ['/usr/bin/sftp']
        if port is not None:
            args.append('-oPort=%s' % str(port))
        # sftp uses "user@host" form
        if user is not None:
            host = "%s@%s" % (user, host)
        args.append(host)
        ignored_session = quills.Session(args)
    else:
        raise ValueError("unsupported form of sftp URL")
예제 #4
0
def file(url):
    """file(url) -> None

    Asynchronously open a session with "emacs" in file browser
    mode, looking at the resource from a given "file://" URL.

    Raises an exception for some failures.  Note, however, that
    as an asynchronous process spawn, other types of failures
    could occur later that are not trapped at call time.

    (Below are REAL testcases run by doctest!)

    >>> file('file:///System/Library')

    >>> try:
    ...        file('not a file url!')
    ... except ValueError as e:
    ...        print(e)
    not a file URL

    """
    url_info = _parse_file(url)
    path = url_info.get('path', None)
    if path is not None:
        if len(path) == 0:
            # default to the home directory
            from os import getuid as _getuid
            from pwd import getpwuid as _getpwuid
            (pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, \
                pw_dir, pw_shell) = _getpwuid(_getuid())
            path = pw_dir
            if path is None or len(path) == 0:
                from os import getenv as _getenv
                path = _getenv('HOME')
                if path is None:
                    path = '/'
        # emacs is a good choice because it has a command line
        # option to set a start location, it is an excellent file
        # browser and it can remain running to perform other tasks
        args = ['/usr/bin/emacs', "--file=%s" % path]
        ignored_session = quills.Session(args)
    else:
        raise ValueError("unsupported form of file URL")
예제 #5
0
def session(pathname):
    """session(pathname) -> None

    Asynchronously open a session from the given ".session" file,
    by parsing the file for command information, and trying to
    use other information from the file to configure the session
    and its terminal window.
    Raise SyntaxError if the file is not formatted properly.
    Raise KeyError if the file is successfully parsed but it has
    no command information.

    WARNING: This routine is incomplete, as the Quills API has
    not advanced far enough to make use of all of the settings
    that could exist in a ".session" file.

    """
    with open(pathname, 'rU') as ifh:
        parser = file_kvp.Parser(file_object=ifh)
        defs = parser.results()
        if 'command' in defs:
            args = defs['command'].split()
            ignored_session = quills.Session(args)
        else:
            raise KeyError('no "command" was found in the file')