2
# Terminator.optionparse - Parse commandline options
3
# Copyright (C) 2006-2010 cmsj@tenshu.net
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.
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.
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"""
22
from optparse import OptionParser, SUPPRESS_HELP
23
from util import dbg, err
28
def execute_cb(option, opt, value, lparser):
29
"""Callback for use in parsing execute options"""
33
arg = lparser.rargs[0]
36
setattr(lparser.values, option.dest, value)
39
"""Parse the command line options"""
40
usage = "usage: %prog [options]"
42
configobj = config.Config()
43
parser = OptionParser(usage)
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',
80
(options, args) = parser.parse_args()
82
parser.error('Additional unexpected arguments found: %s' % args)
85
print '%s %s' % (version.APP_NAME, version.APP_VERSION)
88
if options.debug_classes or options.debug_methods:
89
if not options.debug > 0:
95
util.DEBUGFILES = True
96
if options.debug_classes:
97
classes = options.debug_classes.split(',')
99
util.DEBUGCLASSES.append(item.strip())
100
if options.debug_methods:
101
methods = options.debug_methods.split(',')
103
util.DEBUGMETHODS.append(item.strip())
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))
109
err('OptionParse::parse_options: %s does not exist' %
110
options.working_directory)
111
options.working_directory = ''
113
if options.layout is None:
114
options.layout = 'default'
116
configobj.options_set(options)
118
if util.DEBUG == True:
119
dbg('OptionParse::parse_options: command line options: %s' % options)