~ubuntu-branches/ubuntu/saucy/terminator/saucy

« back to all changes in this revision

Viewing changes to terminatorlib/optionparse.py

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella (Canonical)
  • Date: 2010-04-07 17:10:31 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100407171031-35nsuj0tmbub0bj5
Tags: 0.92-0ubuntu1
* New upstream release
* Remove python-xdg from Recommends. (Closes: #567967)
* Downgrade python-gnome2 to Recommends.
* Update python-gtk2 dependency to (>= 2.14.0)
* Add python-keybinder to Recommends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#    Terminator.optionparse - Parse commandline options
 
3
#    Copyright (C) 2006-2010  cmsj@tenshu.net
 
4
#
 
5
#  This program is free software; you can redistribute it and/or modify
 
6
#  it under the terms of the GNU General Public License as published by
 
7
#  the Free Software Foundation, version 2 only.
 
8
#
 
9
#  This program is distributed in the hope that it will be useful,
 
10
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#  GNU General Public License for more details.
 
13
#
 
14
#  You should have received a copy of the GNU General Public License
 
15
#  along with this program; if not, write to the Free Software
 
16
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
"""Terminator.optionparse - Parse commandline options"""
 
18
 
 
19
import sys
 
20
import os
 
21
 
 
22
from optparse import OptionParser, SUPPRESS_HELP
 
23
from util import dbg, err
 
24
import util
 
25
import config
 
26
import version
 
27
 
 
28
def execute_cb(option, opt, value, lparser):
 
29
    """Callback for use in parsing execute options"""
 
30
    assert value is None
 
31
    value = []
 
32
    while lparser.rargs:
 
33
        arg = lparser.rargs[0]
 
34
        value.append(arg)
 
35
        del(lparser.rargs[0])
 
36
    setattr(lparser.values, option.dest, value)
 
37
 
 
38
def parse_options():
 
39
    """Parse the command line options"""
 
40
    usage = "usage: %prog [options]"
 
41
 
 
42
    configobj = config.Config()
 
43
    parser = OptionParser(usage)
 
44
 
 
45
    parser.add_option('-v', '--version', action='store_true', dest='version',
 
46
            help='Display program version')
 
47
    parser.add_option('-m', '--maximise', action='store_true', dest='maximise',
 
48
            help='Maximise the window')
 
49
    parser.add_option('-f', '--fullscreen', action='store_true',
 
50
            dest='fullscreen', help='Make the window fill the screen')
 
51
    parser.add_option('-b', '--borderless', action='store_true',
 
52
            dest='borderless', help='Disable window borders')
 
53
    parser.add_option('-H', '--hidden', action='store_true', dest='hidden',
 
54
            help='Hide the window at startup')
 
55
    parser.add_option('-T', '--title', dest='forcedtitle', help='Specify a \
 
56
title for the window')
 
57
    parser.add_option('--geometry', dest='geometry', type='string', help='Set \
 
58
the preferred size and position of the window (see X man page)')
 
59
    parser.add_option('-e', '--command', dest='command', help='Specify a \
 
60
command to execute inside the terminal')
 
61
    parser.add_option('-x', '--execute', dest='execute', action='callback',
 
62
            callback=execute_cb, help='Use the rest of the command line as a \
 
63
command to execute inside the terminal, and its arguments')
 
64
    parser.add_option('--working-directory', metavar='DIR',
 
65
            dest='working_directory', help='Set the working directory')
 
66
    parser.add_option('-r', '--role', dest='role', help='Set a custom \
 
67
WM_WINDOW_ROLE property on the window')
 
68
    parser.add_option('-l', '--layout', dest='layout', help='Select a layout')
 
69
    parser.add_option('-d', '--debug', action='count', dest='debug',
 
70
            help='Enable debugging information (twice for debug server)')
 
71
    parser.add_option('--debug-classes', action='store', dest='debug_classes', 
 
72
            help='Comma separated list of classes to limit debugging to')
 
73
    parser.add_option('--debug-methods', action='store', dest='debug_methods',
 
74
            help='Comma separated list of methods to limit debugging to')
 
75
    for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n',
 
76
    '--no-gconf', '-p', '--profile' ]:
 
77
        parser.add_option(item, dest='dummy', action='store',
 
78
                help=SUPPRESS_HELP)
 
79
 
 
80
    (options, args) = parser.parse_args()
 
81
    if len(args) != 0:
 
82
        parser.error('Additional unexpected arguments found: %s' % args)
 
83
 
 
84
    if options.version:
 
85
        print '%s %s' % (version.APP_NAME, version.APP_VERSION)
 
86
        sys.exit(0)
 
87
 
 
88
    if options.debug_classes or options.debug_methods:
 
89
        if not options.debug > 0:
 
90
            options.debug = 1
 
91
 
 
92
    if options.debug:
 
93
        util.DEBUG = True
 
94
        if options.debug > 1:
 
95
            util.DEBUGFILES = True
 
96
        if options.debug_classes:
 
97
            classes = options.debug_classes.split(',')
 
98
            for item in classes:
 
99
                util.DEBUGCLASSES.append(item.strip())
 
100
        if options.debug_methods:
 
101
            methods = options.debug_methods.split(',')
 
102
            for item in methods:
 
103
                util.DEBUGMETHODS.append(item.strip())
 
104
 
 
105
    if options.working_directory:
 
106
        if os.path.exists(os.path.expanduser(options.working_directory)):
 
107
            os.chdir(os.path.expanduser(options.working_directory))
 
108
        else:
 
109
            err('OptionParse::parse_options: %s does not exist' %
 
110
                    options.working_directory)
 
111
            options.working_directory = ''
 
112
 
 
113
    if options.layout is None:
 
114
        options.layout = 'default'
 
115
 
 
116
    configobj.options_set(options)
 
117
 
 
118
    if util.DEBUG == True:
 
119
        dbg('OptionParse::parse_options: command line options: %s' % options)
 
120
 
 
121
    return(options)