2020-04-05 14:36:06 +00:00
|
|
|
# Terminator.optionparse - Parse commandline options
|
|
|
|
# Copyright (C) 2006-2010 cmsj@tenshu.net
|
2010-01-04 23:52:39 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 2 only.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
"""Terminator.optionparse - Parse commandline options"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
from optparse import OptionParser, SUPPRESS_HELP
|
2018-04-24 18:22:10 +00:00
|
|
|
from .util import dbg, err
|
|
|
|
from . import util
|
|
|
|
from . import config
|
|
|
|
from . import version
|
|
|
|
from .translation import _
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2012-03-30 19:35:19 +00:00
|
|
|
options = None
|
|
|
|
|
2010-01-04 23:52:39 +00:00
|
|
|
def execute_cb(option, opt, value, lparser):
|
|
|
|
"""Callback for use in parsing execute options"""
|
|
|
|
assert value is None
|
|
|
|
value = []
|
|
|
|
while lparser.rargs:
|
|
|
|
arg = lparser.rargs[0]
|
|
|
|
value.append(arg)
|
|
|
|
del(lparser.rargs[0])
|
|
|
|
setattr(lparser.values, option.dest, value)
|
|
|
|
|
|
|
|
def parse_options():
|
|
|
|
"""Parse the command line options"""
|
|
|
|
usage = "usage: %prog [options]"
|
|
|
|
|
2013-08-27 11:37:09 +00:00
|
|
|
is_x_terminal_emulator = os.path.basename(sys.argv[0]) == 'x-terminal-emulator'
|
2013-05-13 04:44:07 +00:00
|
|
|
|
2010-01-04 23:52:39 +00:00
|
|
|
parser = OptionParser(usage)
|
|
|
|
|
|
|
|
parser.add_option('-v', '--version', action='store_true', dest='version',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Display program version'))
|
2010-01-04 23:52:39 +00:00
|
|
|
parser.add_option('-m', '--maximise', action='store_true', dest='maximise',
|
2015-11-28 23:39:22 +00:00
|
|
|
help=_('Maximize the window'))
|
2020-06-11 18:01:15 +00:00
|
|
|
parser.add_option('-M', '--maximize', action='store_true', dest='maximise',
|
|
|
|
help=_('Maximize the window'))
|
2010-01-04 23:52:39 +00:00
|
|
|
parser.add_option('-f', '--fullscreen', action='store_true',
|
2010-09-04 09:03:57 +00:00
|
|
|
dest='fullscreen', help=_('Make the window fill the screen'))
|
2010-01-04 23:52:39 +00:00
|
|
|
parser.add_option('-b', '--borderless', action='store_true',
|
2010-09-04 09:03:57 +00:00
|
|
|
dest='borderless', help=_('Disable window borders'))
|
2010-01-04 23:52:39 +00:00
|
|
|
parser.add_option('-H', '--hidden', action='store_true', dest='hidden',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Hide the window at startup'))
|
2011-12-29 20:39:09 +00:00
|
|
|
parser.add_option('-T', '--title', dest='forcedtitle',
|
|
|
|
help=_('Specify a title for the window'))
|
|
|
|
parser.add_option('--geometry', dest='geometry', type='string',
|
|
|
|
help=_('Set the preferred size and position of the window'
|
|
|
|
'(see X man page)'))
|
2013-08-27 11:37:09 +00:00
|
|
|
if not is_x_terminal_emulator:
|
2013-08-04 19:36:33 +00:00
|
|
|
parser.add_option('-e', '--command', dest='command',
|
|
|
|
help=_('Specify a command to execute inside the terminal'))
|
2013-08-27 11:37:09 +00:00
|
|
|
else:
|
2013-08-04 19:36:33 +00:00
|
|
|
parser.add_option('--command', dest='command',
|
|
|
|
help=_('Specify a command to execute inside the terminal'))
|
|
|
|
parser.add_option('-e', '--execute2', dest='execute', action='callback',
|
|
|
|
callback=execute_cb,
|
2013-08-27 11:37:09 +00:00
|
|
|
help=_('Use the rest of the command line as a command to '
|
2013-08-04 19:36:33 +00:00
|
|
|
'execute inside the terminal, and its arguments'))
|
2012-10-19 05:14:39 +00:00
|
|
|
parser.add_option('-g', '--config', dest='config',
|
|
|
|
help=_('Specify a config file'))
|
2020-09-20 20:54:10 +00:00
|
|
|
parser.add_option('-j', '--config-json', dest='configjson',
|
|
|
|
help=_('Specify a partial config json file'))
|
2013-08-04 19:36:33 +00:00
|
|
|
parser.add_option('-x', '--execute', dest='execute', action='callback',
|
2011-12-29 20:39:09 +00:00
|
|
|
callback=execute_cb,
|
2013-01-30 13:17:11 +00:00
|
|
|
help=_('Use the rest of the command line as a command to execute '
|
|
|
|
'inside the terminal, and its arguments'))
|
2010-01-04 23:52:39 +00:00
|
|
|
parser.add_option('--working-directory', metavar='DIR',
|
2010-09-04 09:03:57 +00:00
|
|
|
dest='working_directory', help=_('Set the working directory'))
|
2012-06-28 16:07:00 +00:00
|
|
|
parser.add_option('-i', '--icon', dest='forcedicon', help=_('Set a custom \
|
|
|
|
icon for the window (by file or name)'))
|
2011-12-29 20:39:09 +00:00
|
|
|
parser.add_option('-r', '--role', dest='role',
|
|
|
|
help=_('Set a custom WM_WINDOW_ROLE property on the window'))
|
|
|
|
parser.add_option('-l', '--layout', dest='layout',
|
2013-08-28 21:09:17 +00:00
|
|
|
help=_('Launch with the given layout'))
|
|
|
|
parser.add_option('-s', '--select-layout', action='store_true',
|
|
|
|
dest='select', help=_('Select a layout from a list'))
|
2011-12-29 20:39:09 +00:00
|
|
|
parser.add_option('-p', '--profile', dest='profile',
|
|
|
|
help=_('Use a different profile as the default'))
|
2010-07-22 12:59:06 +00:00
|
|
|
parser.add_option('-u', '--no-dbus', action='store_true', dest='nodbus',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Disable DBus'))
|
2010-02-17 20:16:52 +00:00
|
|
|
parser.add_option('-d', '--debug', action='count', dest='debug',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Enable debugging information (twice for debug server)'))
|
2010-02-17 20:16:52 +00:00
|
|
|
parser.add_option('--debug-classes', action='store', dest='debug_classes',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Comma separated list of classes to limit debugging to'))
|
2010-02-17 20:16:52 +00:00
|
|
|
parser.add_option('--debug-methods', action='store', dest='debug_methods',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Comma separated list of methods to limit debugging to'))
|
2012-10-30 00:11:24 +00:00
|
|
|
parser.add_option('--new-tab', action='store_true', dest='new_tab',
|
|
|
|
help=_('If Terminator is already running, just open a new tab'))
|
2010-01-05 12:51:53 +00:00
|
|
|
for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n',
|
2011-12-29 20:39:09 +00:00
|
|
|
'--no-gconf' ]:
|
2010-01-04 23:52:39 +00:00
|
|
|
parser.add_option(item, dest='dummy', action='store',
|
|
|
|
help=SUPPRESS_HELP)
|
|
|
|
|
2012-03-30 19:35:19 +00:00
|
|
|
global options
|
2010-01-04 23:52:39 +00:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if len(args) != 0:
|
|
|
|
parser.error('Additional unexpected arguments found: %s' % args)
|
|
|
|
|
|
|
|
if options.version:
|
2018-04-24 18:22:10 +00:00
|
|
|
print('%s %s' % (version.APP_NAME, version.APP_VERSION))
|
2010-01-04 23:52:39 +00:00
|
|
|
sys.exit(0)
|
2010-02-17 20:16:52 +00:00
|
|
|
|
|
|
|
if options.debug_classes or options.debug_methods:
|
2010-03-21 00:48:39 +00:00
|
|
|
if not options.debug > 0:
|
2010-03-21 00:49:22 +00:00
|
|
|
options.debug = 1
|
2010-02-17 20:16:52 +00:00
|
|
|
|
2010-01-04 23:52:39 +00:00
|
|
|
if options.debug:
|
|
|
|
util.DEBUG = True
|
2010-01-22 19:04:37 +00:00
|
|
|
if options.debug > 1:
|
2010-01-14 13:15:05 +00:00
|
|
|
util.DEBUGFILES = True
|
2010-02-17 20:16:52 +00:00
|
|
|
if options.debug_classes:
|
|
|
|
classes = options.debug_classes.split(',')
|
|
|
|
for item in classes:
|
|
|
|
util.DEBUGCLASSES.append(item.strip())
|
|
|
|
if options.debug_methods:
|
|
|
|
methods = options.debug_methods.split(',')
|
|
|
|
for item in methods:
|
|
|
|
util.DEBUGMETHODS.append(item.strip())
|
2010-01-04 23:52:39 +00:00
|
|
|
|
|
|
|
if options.working_directory:
|
|
|
|
if os.path.exists(os.path.expanduser(options.working_directory)):
|
2016-12-02 21:45:49 +00:00
|
|
|
options.working_directory = os.path.expanduser(options.working_directory)
|
|
|
|
os.chdir(options.working_directory)
|
2010-01-04 23:52:39 +00:00
|
|
|
else:
|
|
|
|
err('OptionParse::parse_options: %s does not exist' %
|
|
|
|
options.working_directory)
|
2010-03-31 13:02:55 +00:00
|
|
|
options.working_directory = ''
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2010-02-04 23:52:43 +00:00
|
|
|
if options.layout is None:
|
|
|
|
options.layout = 'default'
|
|
|
|
|
2012-03-30 19:35:19 +00:00
|
|
|
configobj = config.Config()
|
2010-05-15 13:51:20 +00:00
|
|
|
if options.profile and options.profile not in configobj.list_profiles():
|
|
|
|
options.profile = None
|
|
|
|
|
2010-01-11 20:56:30 +00:00
|
|
|
configobj.options_set(options)
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2020-08-28 20:51:37 +00:00
|
|
|
optionslist = {}
|
|
|
|
for opt, val in list(options.__dict__.items()):
|
|
|
|
if type(val) == type([]):
|
|
|
|
val = ' '.join(val)
|
|
|
|
if val == True:
|
|
|
|
val = 'True'
|
|
|
|
optionslist[opt] = val and '%s'%val or ''
|
|
|
|
# optionslist = dbus.Dictionary(optionslist, signature='ss')
|
2010-01-04 23:52:39 +00:00
|
|
|
if util.DEBUG == True:
|
2010-01-10 23:47:36 +00:00
|
|
|
dbg('OptionParse::parse_options: command line options: %s' % options)
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2020-08-28 20:51:37 +00:00
|
|
|
|
|
|
|
return(options,optionslist)
|