[orca] Move the argument parsing and startup into orca.in, clean up related code



commit f86b4ed8da5815e4bbd6bd0513072f08653842d0
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon May 21 19:11:19 2012 -0400

    Move the argument parsing and startup into orca.in, clean up related code

 src/orca/Makefile.am         |   12 ++
 src/orca/bookmarks.py        |    3 +
 src/orca/orca.py             |  335 ++++--------------------------------------
 src/orca/orca_bin.py.in      |  278 ++++++++++++++++++++++++++++++++++-
 src/orca/settings_manager.py |   21 ---
 5 files changed, 315 insertions(+), 334 deletions(-)
---
diff --git a/src/orca/Makefile.am b/src/orca/Makefile.am
index 9add9e9..78b01d9 100644
--- a/src/orca/Makefile.am
+++ b/src/orca/Makefile.am
@@ -84,3 +84,15 @@ gfx_DATA = \
 EXTRA_DIST = \
 	$(ui_DATA) \
 	$(gfx_DATA)
+
+CLEANFILES = \
+	orca \
+	orca_bin.py \
+	orca_i18n.py \
+	orca_platform.py
+
+DISTCLEANFILES = \
+	orca \
+	orca_bin.py \
+	orca_i18n.py \
+	orca_platform.py
diff --git a/src/orca/bookmarks.py b/src/orca/bookmarks.py
index 9c0ffca..1a64306 100644
--- a/src/orca/bookmarks.py
+++ b/src/orca/bookmarks.py
@@ -213,6 +213,9 @@ class Bookmarks:
         that represents a bookmark """
         filename = filename or self._script.name.split(' ')[0]
         orcaDir = _settingsManager.getPrefsDir()
+        if not orcaDir:
+            return
+
         orcaBookmarksDir = os.path.join(orcaDir, "bookmarks")
         try:
             inputFile = open( os.path.join( orcaBookmarksDir, \
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 2dacbd4..fd9adf0 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -29,13 +29,13 @@ __copyright__ = "Copyright (c) 2004-2009 Sun Microsystems Inc." \
                 "Copyright (c) 2012 Igalia, S.L."
 __license__   = "LGPL"
 
-import argparse
+import gc
 import os
-import subprocess
+import pyatspi
 import re
 import signal
+import subprocess
 import sys
-import time
 
 try:
     from gi.repository.Gio import Settings
@@ -43,7 +43,6 @@ try:
 except:
     a11yAppSettings = None
 
-import pyatspi
 try:
     # This can fail due to gtk not being available.  We want to
     # be able to recover from that if possible.  The main driver
@@ -55,193 +54,11 @@ try:
     # Note: This last import is here due to bgo #673396.
     # See bgo#673397 for the rest of the story.
     from gi.repository.GdkX11 import X11Screen
-    desktopRunning = True
 except:
-    desktopRunning = False
-
-# Importing anything that requires a functioning settings manager
-# instance should NOT be done here.
-#
-from . import debug
-from . import orca_platform
-from . import settings
-from .orca_i18n import _
-from .orca_i18n import ngettext
-
-def onEnabledChanged(gsetting, key):
-    try:
-        enabled = gsetting.get_boolean(key)
-    except:
-        return
-
-    if key == 'screen-reader-enabled' and not enabled:
-        shutdown()
-
-class ListApps(argparse.Action):
-    def __call__(self, parser, namespace, values, option_string=None):
-        try:
-            apps = filter(lambda x: x != None, pyatspi.Registry.getDesktop(0))
-            names = [app.name for app in apps]
-        except:
-            pass
-        else:
-            print("\n".join(names))
-        parser.exit()
-
-class Settings(argparse.Action):
-    def __call__(self, parser, namespace, values, option_string=None):
-        for value in values.split(','):
-            item = str.title(value).replace('-', '')
-            try:
-                test = 'enable%s' % item
-                eval('settings.%s' % test)
-            except AttributeError:
-                try:
-                    test = 'show%s' % item
-                    eval('settings.%s' % test)
-                except AttributeError:
-                    namespace.invalid.append(item)
-                    continue
-            namespace.settings[test] = self.const
-
-class Options(argparse.Namespace):
-    """Class to handle getting run-time options."""
-
-    def __init__(self, **kwargs):
-        """Initialize the Options class."""
-
-        super(Options, self).__init__(**kwargs)
-        self.settings = {}
-        self.invalid = []
-        self._validFeaturesPrinted = False
-        self.debug = False
-        self.debugFile = None
-
-    def validate(self):
-        """Validate the commandline options."""
-
-        if self.debugFile:
-            self.debug = True
-        elif self.debug:
-            self.debugFile = time.strftime('debug-%Y-%m-%d-%H:%M:%S.out')
-
-def presentInvalidOptions(invalidOptions):
-    """Presents any invalid options to the user. Returns True if there were
-    invalid options to present and a message printed; otherwise returns False.
-    """
-
-    if invalidOptions:
-        # Translators: This message is displayed when the user tries to start
-        # Orca and includes an invalid option as an argument. After the message,
-        # the list of arguments, as typed by the user, is displayed.
-        #
-        msg = _("The following arguments are not valid: ")
-        print((msg + " ".join(invalidOptions)))
-        return True
-
-    return False
-
-parser = argparse.ArgumentParser(
-    # Translators: this text is the description displayed when Orca is
-    # launched from the command line and the help text is displayed.
-    description = _("orca - scriptable screen reader"),
-    # Translators: this text is the description displayed when Orca is
-    # launched from the command line and the help text is displayed.
-    epilog = _("Report bugs to orca-list gnome org "))
-
-parser.add_argument(
-    "-v", "--version", action = "version", version = orca_platform.version,
-    help = orca_platform.version)
-
-parser.add_argument(
-    "-l", "--list-apps", action = ListApps, nargs=0,
-    # Translators: this is a testing option for the command line.  It prints
-    # the names of applications known to the accessibility infrastructure
-    # to stdout and then exits.
-    #
-    help = _("Print the known running applications"))
-
-parser.add_argument(
-    "--debug", action = "store_true", dest = "debug",
-    # Translators: this enables debug output for Orca.  The
-    # YYYY-MM-DD-HH:MM:SS portion is a shorthand way of saying that the file
-    # name will be formed from the current date and time with 'debug' in front
-    # and '.out' at the end.  The 'debug' and '.out' portions of this string
-    # should not be translated (i.e., it will always start with 'debug' and end
-    # with '.out', regardless of the locale.).
-    #
-    help = _("Send debug output to debug-YYYY-MM-DD-HH:MM:SS.out"))
-
-parser.add_argument(
-    "--debug-file", action = "store", dest = "debugFile",
-    default = time.strftime("debug-%Y-%m-%d-%H:%M:%S.out"),
-    # Translators: this enables debug output for Orca and overrides the name
-    # of the debug file Orca will use for debug output if the --debug option
-    # is used.
-    #
-    help = _("Send debug output to the specified file"))
-
-parser.add_argument(
-    "-t", "--text-setup", action = "store_true",
-    dest = "textSetupRequested",
-    # Translators: this is the description of the command line option
-    # '-t, --text-setup' that will initially display a list of questions in
-    # text form, that the user will need to answer, before Orca will startup.
-    # For this to happen properly, Orca will need to be run from a terminal
-    # window.
-    #
-    help = _("Set up user preferences (text version)"))
-
-parser.add_argument(
-    "-u", "--user-prefs-dir", action = "store", dest = "userPrefsDir",
-    # Translators: this is the description of the command line option
-    # '-u, --user-prefs-dir=dirname' that allows you to specify an alternate
-    # location for the user preferences.
-    #
-    help = _("Use alternate directory for user preferences"))
-
-parser.add_argument(
-    "-e", "--enable", action = Settings, const=True,
-    # Translators: if the user supplies an option via the '-e, --enable'
-    # command line option, it will be automatically enabled as Orca is started.
-    #
-    help = _("Force use of option"))
-
-parser.add_argument(
-    "-d", "--disable", action = Settings, const=False,
-    # Translators: if the user supplies an option via the '-d, --disable'
-    # command line option, it will be automatically disabled as Orca is started.
-    #
-    help = _("Prevent use of option"))
-
-parser.add_argument(
-    "-i", "--import-file", action = "append", dest = "profiles", default = [],
-    # Translators: this is the Orca command line option to import to Orca a user
-    # profile from a given file
-    #
-    help = _("Import a profile from a given orca profile file"))
-
-parser.add_argument(
-    "--replace", action = "store_true", dest = "replace",
-    # Translators: this is the Orca command line option to tell Orca to replace
-    # any existing Orca process(es) that might be running.
-    #
-    help = _("Replace a currently running Orca"))
-
-options, invalidOpts = parser.parse_known_args(namespace = Options())
-invalidOpts.extend(options.invalid)
-options.validate()
+    pass
 
-# This needs to occur prior to our importing anything which might in turn
-# import anything which might expect to be able to use the Settings Manager
-# You have been warned.
-#
 from .settings_manager import SettingsManager
 _settingsManager = SettingsManager()
-_settingsManager.activate(options.userPrefsDir)
-if _settingsManager is None:
-    print("Could not load the settings manager. Exiting.")
-    sys.exit(1)
 
 from .event_manager import EventManager
 _eventManager = EventManager()
@@ -249,21 +66,35 @@ _eventManager = EventManager()
 from .script_manager import ScriptManager
 _scriptManager = ScriptManager()
 
+from . import braille
+from . import debug
+from . import notification_messages
+from . import orca_state
+from . import settings
+from . import speech
+from .input_event import BrailleEvent
+from .input_event import KeyboardEvent
+from .orca_i18n import _
+from .orca_i18n import ngettext
+
 try:
     # If we don't have an active desktop, we will get a RuntimeError.
     from . import mouse_review
 except RuntimeError:
     pass
 
-from . import braille
-from . import orca_state
-from . import speech
-from . import notification_messages
+def onEnabledChanged(gsetting, key):
+    try:
+        enabled = gsetting.get_boolean(key)
+    except:
+        return
 
-from .input_event import BrailleEvent
-from .input_event import KeyboardEvent
+    if key == 'screen-reader-enabled' and not enabled:
+        shutdown()
+
+def getSettingsManager():
+    return _settingsManager
 
-import gc
 if settings.debugMemoryUsage:
     gc.set_debug(gc.DEBUG_UNCOLLECTABLE
                  | gc.DEBUG_COLLECTABLE
@@ -599,10 +430,6 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False):
         _profile = _settingsManager.profile
         try:
             _userSettings = _settingsManager.getGeneralSettings(_profile)
-            if options.debug:
-                debug.debugLevel = debug.LEVEL_ALL
-                debug.eventDebugLevel = debug.LEVEL_OFF
-                debug.debugFile = open(options.debugFile, 'w', 0)
         except ImportError:
             debug.printException(debug.LEVEL_FINEST)
         except:
@@ -726,24 +553,6 @@ def showMainWindowGUI(script=None, inputEvent=None):
 
     return True
 
-def _showPreferencesConsole(script=None, inputEvent=None):
-    """Displays the user interace to configure Orca and set up
-    user preferences via a command line interface.
-
-    Returns True to indicate the input event has been consumed.
-    """
-
-    try:
-        module = __import__(settings.consolePreferencesModule,
-                            globals(),
-                            locals(),
-                            [''])
-        module.showPreferencesUI(_commandLineSettings)
-    except:
-        debug.printException(debug.LEVEL_SEVERE)
-
-    return True
-
 def helpForOrca(script=None, inputEvent=None, page=""):
     """Show Orca Help window (part of the GNOME Access Guide).
 
@@ -1193,42 +1002,6 @@ def examineProcesses():
         debug.println(
             debug.LEVEL_ALL, '%3i. %s (pid: %s) %s' % (i+1, name, pid, cmd))
 
-def otherOrcas():
-    """Returns the pid of any other instances of Orca owned by this user."""
-
-    openFile = os.popen('pgrep -u %s orca' % os.getuid())
-    pids = openFile.read()
-    openFile.close()
-    orcas = [int(p) for p in pids.split()]
-
-    pid = os.getpid()
-    return [p for p in orcas if p != pid]
-
-def multipleOrcas():
-    """Returns True if multiple instances of Orca are running which are
-    are owned by this user."""
-
-    return len(otherOrcas()) > 0
-
-def cleanup(sigval):
-    """Tries to clean up any other running Orca instances owned by this user."""
-
-    orcasToKill = otherOrcas()
-    debug.println(
-        debug.LEVEL_INFO, "INFO: Cleaning up these PIDs: %s" % orcasToKill)
-
-    def onTimeout(signum, frame):
-        orcasToKill = otherOrcas()
-        debug.println(
-            debug.LEVEL_INFO, "INFO: Timeout cleaning up: %s" % orcasToKill)
-        map(lambda x: os.kill(x, signal.SIGKILL), orcasToKill)
-
-    map(lambda x: os.kill(x, sigval), orcasToKill)
-    signal.signal(signal.SIGALRM, onTimeout)
-    signal.alarm(2)
-    while otherOrcas():
-        time.sleep(0.5)
-
 def cleanupGarbage():
     """Cleans up garbage on the heap."""
     gc.collect()
@@ -1240,7 +1013,7 @@ def cleanupGarbage():
         except:
             pass
 
-def main():
+def main(settingsDict={}):
     """The main entry point for Orca.  The exit codes for Orca will
     loosely be based on signals, where the exit code will be the
     signal used to terminate Orca (if a signal was used).  Otherwise,
@@ -1259,65 +1032,11 @@ def main():
     signal.signal(signal.SIGQUIT, shutdownOnSignal)
     signal.signal(signal.SIGSEGV, abortOnSignal)
 
-    invalidOptionsPresented = presentInvalidOptions(invalidOpts)
-
-    if multipleOrcas():
-        if invalidOptionsPresented:
-            die(0)
-        elif options.replace:
-            cleanup(signal.SIGKILL)
-        else:
-            # Translators: This message is presented to the user when
-            # he/she tries to launch Orca, but Orca is already running.
-            print(_('Another Orca process is already running for this ' \
-                    'session.\n Run "orca --replace" to replace that ' \
-                    'process with a new one.'))
-            return 1
-
-    _commandLineSettings.update(options.settings)
-    for profile in options.profiles:
-        # Translators: This message is what is presented to the user
-        # when he/she attempts to import a settings profile, but the
-        # import failed for some reason.
-        #
-        msg = _("Unable to import profile.")
-        try:
-            if _settingsManager.importProfile(profile):
-                # Translators: This message is what is presented to the user
-                # when he/she successfully imports a settings profile.
-                #
-                msg = _("Profile import success.")
-        except KeyError as ex:
-            # Translators: This message is what is presented to the user
-            # when he/she attempts to import a settings profile but the
-            # import failed due to a bad key.
-            #
-            msg = _("Import failed due to an unrecognized key: %s") % ex
-        except IOError as ex:
-            msg = "%s: %s" % (ex.strerror, ex.filename)
-        except:
-            continue
-
-        print(msg)
-        if multipleOrcas():
-            die(0)
+    _commandLineSettings.update(settingsDict)
 
     if not _settingsManager.isAccessibilityEnabled():
         _settingsManager.setAccessibility(True)
 
-    if options.textSetupRequested:
-        _showPreferencesConsole()
-
-    if not desktopRunning:
-        # Translators: This message is presented to the user who attempts
-        # to launch Orca from some other environment than the graphical
-        # desktop.
-        print (_('Cannot start Orca because it cannot connect to the Desktop.'))
-        return 1
-
-    sys.path.insert(0, _settingsManager.getPrefsDir())
-    sys.path.insert(0, '') # current directory
-
     init(pyatspi.Registry)
 
     try:
diff --git a/src/orca/orca_bin.py.in b/src/orca/orca_bin.py.in
index b9ff13d..f0bbe69 100644
--- a/src/orca/orca_bin.py.in
+++ b/src/orca/orca_bin.py.in
@@ -27,7 +27,188 @@ __copyright__ = "Copyright (c) 2010-2012 The Orca Team" \
                 "Copyright (c) 2012 Igalia, S.L."
 __license__   = "LGPL"
 
+import argparse
+import os
+import signal
 import sys
+import time
+
+sys.prefix = '@prefix@'
+pyexecdir = '@pyexecdir@'.replace('${exec_prefix}', '@prefix@')
+sys.path.insert(1, pyexecdir)
+
+from orca import debug
+from orca import orca
+from orca import orca_console_prefs
+from orca import settings
+from orca.orca_i18n import _
+from orca.orca_platform import version
+
+class ListApps(argparse.Action):
+    def __call__(self, parser, namespace, values, option_string=None):
+        try:
+            apps = filter(lambda x: x != None, pyatspi.Registry.getDesktop(0))
+            names = [app.name for app in apps]
+        except:
+            pass
+        else:
+            print("\n".join(names))
+        parser.exit()
+
+class Settings(argparse.Action):
+    def __call__(self, parser, namespace, values, option_string=None):
+        settingsDict = getattr(namespace, 'settings', {})
+        invalid = getattr(namespace, 'invalid', [])
+        for value in values.split(','):
+            item = str.title(value).replace('-', '')
+            try:
+                test = 'enable%s' % item
+                eval('settings.%s' % test)
+            except AttributeError:
+                try:
+                    test = 'show%s' % item
+                    eval('settings.%s' % test)
+                except AttributeError:
+                    invalid.append(item)
+                    continue
+            settingsDict[test] = self.const
+            setattr(namespace, 'settings', settingsDict)
+            setattr(namespace, 'invalid', invalid)
+
+class HelpFormatter(argparse.HelpFormatter):
+    def __init__(self, prog, indent_increment=2, max_help_position=32,
+                 width=None):
+
+        super(HelpFormatter, self).__init__(
+            prog, indent_increment, max_help_position, width)
+
+class Parser(argparse.ArgumentParser):
+    def __init__(self, *args, **kwargs):
+        # Translators: this text is the description displayed when Orca is
+        # launched from the command line and the help text is displayed.
+        description = _("orca - scriptable screen reader")
+        # Translators: this text is the description displayed when Orca is
+        # launched from the command line and the help text is displayed.
+        epilog = _("Report bugs to orca-list gnome org ")
+        super(Parser, self).__init__(
+            description=description,
+            epilog=epilog,
+            formatter_class=HelpFormatter)
+
+        self.add_argument(
+            "-v", "--version", action="version", version=version, help=version)
+
+        self.add_argument(
+            "-r", "--replace", action="store_true",
+            # Translators: this is the description of the command line option
+            # '-r, --replace' which tells Orca to replace any existing Orca
+            # process(es) that might be running.
+            help=_("Replace a currently running Orca"))
+
+        self.add_argument(
+            "-t", "--text-setup", action="store_true",
+            # Translators: this is the description of the command line option
+            # '-t, --text-setup' that will initially display a list of questions
+            # in text form, that the user will need to answer, before Orca will
+            # startup. For this to happen properly, Orca will need to be run
+            # from a terminal window.
+            help=_("Set up user preferences (text version)"))
+
+        self.add_argument(
+            "-l", "--list-apps", action=ListApps, nargs=0,
+            # Translators: this is the description of the command line option
+            # '-l, --list-apps' which prints the names of running applications
+            # which can be seen by assistive technologies such as Orca and
+            # Accercser.
+            help=_("Print the known running applications"))
+
+        self.add_argument(
+            "-e", "--enable", action=Settings, const=True,
+            # Translators: this is the description of the command line option
+            # '-e, --enable' which allows the user to specify an option to
+            # enable as Orca is started.
+            help=_("Force use of option"),
+            # Translators: this string indicates to the user what should be
+            # provided when using the '-e, --enable' or '-d, --disable' command
+            # line option.
+            metavar=_("OPTION"))
+
+        self.add_argument(
+            "-d", "--disable", action=Settings, const=False,
+            # Translators: this is the description of the command line option
+            # '-d, --disable' which allows the user to specify an option to
+            # enable as Orca is started.
+            help=_("Prevent use of option"),
+            # Translators: this string indicates to the user what should be
+            # provided when using the '-e, --enable' or '-d, --disable' command
+            # line option.
+            metavar=_("OPTION"))
+
+        self.add_argument(
+            "-p", "--profile", action="store",
+            # Translators: this is the description of the command line option
+            # '-p, --profile' which allows you to specify a profile to be
+            # loaded. A profile stores a group of Orca settings configured by
+            # the user for a particular purpose, such as a 'Spanish' profile
+            # which would include Spanish braille and Spanish text-to-speech.
+            # An Orca settings file contains one or more profiles.
+            help=_("Load profile"),
+            # Translators: this string indicates to the user what should be
+            # provided when using the '-p, --profile' command line option.
+            metavar=_("NAME"))
+
+        self.add_argument(
+            "-u", "--user-prefs", action="store",
+            # Translators: this is the description of the command line option
+            # '-u, --user-prefs' that allows you to specify an alternate
+            # location from which to loadr the user preferences.
+            help=_("Use alternate directory for user preferences"),
+            # Translators: this string indicates to the user what should be
+            # provided when using the 'u, --user-prefs' command line option.
+            metavar=_("DIR"))
+
+        self.add_argument(
+            "--debug-file", action="store",
+            # Translators: this is the description of the command line option
+            # '--debug-file' which allows the user to override the default,
+            # date-based name of the debugging output file.
+            help=_("Send debug output to the specified file"),
+            # Translators: this string indicates to the user what should be
+            # provided when using the '--debug-file' command line option.
+            metavar=_("FILE"))
+
+        self.add_argument(
+            "--debug", action="store_true",
+            # Translators: this is the description of the command line option
+            # '--debug' which enables debugging output for Orca to be sent to
+            # a file. The YYYY-MM-DD-HH:MM:SS portion of the string indicates
+            # the file name will be formed from the current date and time with
+            # 'debug' in front and '.out' at the end. The 'debug' and '.out'
+            # portions of this string should not be translated (i.e., it will
+            # always start with 'debug' and end with '.out', regardless of the
+            # locale.).
+            help=_("Send debug output to debug-YYYY-MM-DD-HH:MM:SS.out"))
+
+    def parse_known_args(self, *args, **kwargs):
+        opts, invalid = super(Parser, self).parse_known_args(*args, **kwargs)
+        try:
+            invalid.extend(opts.invalid)
+        except:
+            pass
+        if invalid:
+            # Translators: This message is displayed when the user starts Orca
+            # from the command line and includes an invalid option or argument.
+            # After the message, the list of invalid items, as typed by the
+            # user, is displayed.
+            msg = _("The following are not valid: ")
+            print((msg + " ".join(invalid)))
+
+        if opts.debug_file:
+            opts.debug = True
+        elif opts.debug:
+            opts.debug_file = time.strftime('debug-%Y-%m-%d-%H:%M:%S.out')
+
+        return opts, invalid
 
 def setProcessName():
     """Attempts to set the process name to 'orca'."""
@@ -54,15 +235,102 @@ def setProcessName():
 
     return False
 
+def inGraphicalDesktop():
+    """Returns True if we are in a graphical desktop."""
+
+    # TODO - JD: Make this desktop environment agnostic
+    try:
+        from gi.repository import Gtk
+    except:
+        return False
+
+    return True
+
+def otherOrcas():
+    """Returns the pid of any other instances of Orca owned by this user."""
+
+    openFile = os.popen('pgrep -u %s orca' % os.getuid())
+    pids = openFile.read()
+    openFile.close()
+    orcas = [int(p) for p in pids.split()]
+
+    pid = os.getpid()
+    return [p for p in orcas if p != pid]
+
+def cleanup(sigval):
+    """Tries to clean up any other running Orca instances owned by this user."""
+
+    orcasToKill = otherOrcas()
+    debug.println(
+        debug.LEVEL_INFO, "INFO: Cleaning up these PIDs: %s" % orcasToKill)
+
+    def onTimeout(signum, frame):
+        orcasToKill = otherOrcas()
+        debug.println(
+            debug.LEVEL_INFO, "INFO: Timeout cleaning up: %s" % orcasToKill)
+        map(lambda x: os.kill(x, signal.SIGKILL), orcasToKill)
+
+    map(lambda x: os.kill(x, sigval), orcasToKill)
+    signal.signal(signal.SIGALRM, onTimeout)
+    signal.alarm(2)
+    while otherOrcas():
+        time.sleep(0.5)
+
 def main():
     setProcessName()
 
-    sys.prefix = '@prefix@'
-    pyexecdir = '@pyexecdir@'.replace('${exec_prefix}', '@prefix@')
-    sys.path.insert(1, pyexecdir)
+    if not inGraphicalDesktop():
+        # Translators: This message is presented to the user who attempts
+        # to launch Orca from some other environment than the graphical
+        # desktop.
+        msg = _('Cannot start Orca because it cannot connect to the Desktop.')
+        print (msg)
+        return 1
+
+    parser = Parser()
+    args, invalid = parser.parse_known_args()
+
+    if args.debug:
+        debug.debugLevel = debug.LEVEL_ALL
+        debug.eventDebugLevel = debug.LEVEL_OFF
+        debug.debugFile = open(args.debug_file, 'w')
+
+    if args.replace:
+        cleanup(signal.SIGKILL)
+
+    settingsDict = getattr(args, 'settings', {})
+    if args.text_setup:
+        orca_console_prefs.showPreferencesUI(settingsDict)
+
+    manager = orca.getSettingsManager()
+    if not manager:
+        print("Could not activate the settings manager. Exiting.")
+        return 1
+
+    manager.activate(args.user_prefs)
+    sys.path.insert(0, manager.getPrefsDir())
+
+    if args.profile:
+        try:
+            manager.setProfile(args.profile)
+        except:
+            # Translators: This message is presented to the user when
+            # the specified profile could not be loaded. A profile stores
+            # a group of Orca settings configured for a particular purpose,
+            # such as a Spanish profile which would include Spanish braille
+            # and Spanish text-to-speech.
+            print(_("Profile could not be loaded: %s") % args.profile)
+            manager.setProfile()
+
+    if otherOrcas():
+        # Translators: This message is presented to the user when
+        # he/she tries to launch Orca, but Orca is already running.
+        print(_('Another Orca process is already running for this ' \
+                'session.\nRun "orca --replace" to replace that ' \
+                'process with a new one.'))
+        return 1
 
-    from orca import orca
-    return orca.main()
+    return orca.main(settingsDict)
 
 if __name__ == "__main__":
     sys.exit(main())
diff --git a/src/orca/settings_manager.py b/src/orca/settings_manager.py
index e3f3ac2..8780b31 100644
--- a/src/orca/settings_manager.py
+++ b/src/orca/settings_manager.py
@@ -31,7 +31,6 @@ __license__   = "LGPL"
 import os
 import imp
 from gi.repository import Gio, GLib
-from json import load
 
 from . import debug
 from .keybindings import KeyBinding
@@ -495,26 +494,6 @@ class SettingsManager(object):
 
         return self._backend.availableProfiles()
 
-
-    def importProfile(self, fileName):
-        """Import profile from a given filename"""
-
-        prefs = {}
-        with open(fileName) as settingsFile:
-            prefs = load(settingsFile)
-
-        general = {}
-
-        for key, value in list(prefs.items()):
-            if key not in settings.excludeKeys:
-                general[key] = value
-
-        pronunciations = prefs.get('pronunciations', {})
-        keybindings = prefs.get('keybindings', {})
-
-        self.saveSettings(general, pronunciations, keybindings)
-        return True
-
     def loadAppSettings(self, script):
         """Load the users application specific settings for an app.
         Note that currently the settings manager does not manage



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]