Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

beebox / crossover   deb

Repository URL to install this package:

Version: 18.5.0-1 

/ opt / cxoffice / bin / cxrun

#! /usr/bin/env python
# (c) Copyright 2009-2013. CodeWeavers, Inc.

import os

# Portable which(1) implementation
def which(path, app):
    """Looks for an executable in the specified directory list.

    path is an os.pathsep-separated list of directories and app is the
    executable name. If app contains a path separator then path is ignored.
    If the file is not found, then None is returned.
    """
    if os.path.isabs(app):
        if os.path.isfile(app) and os.access(app, os.X_OK):
            return app
    elif os.sep in app or (os.altsep and os.altsep in app):
        app_path = os.path.join(os.getcwd(), app)
        if os.path.isfile(app_path) and os.access(app_path, os.X_OK):
            return app_path
    else:
        for directory in path.split(os.pathsep):
            if directory == "":
                continue
            app_path = os.path.join(directory, app)
            if os.path.isfile(app_path) and os.access(app_path, os.X_OK):
                return app_path
    return None
import sys
def locate_cx_root():
    """Locate where CrossOver is installed.

    We start by locating our own python script file and walking back up the
    path, traversing symbolic links on the way. Then we verify what we have
    found the right directory by checking for the presence of the cxmenu
    script.
    """
    # pylint: disable=I0011,W0601,W0603
    global CX_ROOT
    if "CX_DEVELOP_ROOT" in os.environ:
        CX_ROOT = os.environ["CX_DEVELOP_ROOT"]
        return

    # figure out argv0
    argv0 = which(os.environ["PATH"], sys.argv[0])
    if not argv0:
        argv0 = sys.argv[0]
        if not os.path.isabs(argv0):
            argv0 = os.path.join(os.getcwd(), argv0)

    # traverse the symbolic links
    dir0 = os.path.dirname(argv0)
    while True:
        if dir0.endswith("/lib"):
            bindir = dir0[0:-3] + "bin"
        else:
            bindir = dir0
        landmark = os.path.join(bindir, "cxmenu")
        if os.path.isfile(landmark):
            break
        if not os.path.islink(argv0):
            break
        argv0 = os.readlink(argv0)
        if not os.path.isabs(argv0):
            argv0 = os.path.join(dir0, argv0)
        dir0 = os.path.dirname(argv0)

    # compute CX_ROOT
    CX_ROOT = os.path.dirname(os.path.normpath(bindir))

    # check CX_ROOT
    landmark = os.path.join(CX_ROOT, "bin", "cxmenu")
    if not os.path.isfile(landmark) or not os.access(landmark, os.X_OK):
        sys.stderr.write("%s:error: could not find CrossOver in '%s'\n" % (os.path.dirname(sys.argv[0]), CX_ROOT))
        sys.exit(1)

    sys.path.append(os.path.join(CX_ROOT, "lib", "python"))

locate_cx_root()
import cxutils
cxutils.CX_ROOT = CX_ROOT


# pylint: disable=W0611
import checkpython

import cxopt

import bottlequery


def main():
    # Parse the command line options
    opt_parser = cxopt.Parser(usage="%prog [--bottle BOTTLE] [--command COMMAND] [--help] [--] [ARGLIST]",
                              description="Runs Windows applications and commands and optionally creates shortcuts for them.")
    opt_parser.add_option("--bottle", dest="bottle", help="Use the specified bottle. If this option is not used, fallback to $CX_BOTTLE and then to 'default'")
    opt_parser.add_option("--command", dest="command", help="Start the dialog with the specified command line already filled in.")
    opt_parser.add_option("--allow-root", action='store_true', dest="allow_root", help="Don't warn about running this tool as root")
    (options, args) = opt_parser.parse_args()

    # Do more checks and provide defaults
    default_bottle = bottlequery.get_default_bottle()
    if options.command:
        options.command = cxutils.uri_to_path(options.command)
    if args:
        if options.command:
            opt_parser.error("unexpected argument '%s'" % args[0])
        else:
            options.command = cxutils.argvtocmdline(cxutils.uri_to_path(arg) for arg in args)

    # Check for gtk and $DISPLAY
    import checkgtk
    if checkgtk.check_gtk() != checkgtk.OK:
        return 1

    import cxguitools
    cxguitools.set_default_icon()
    if not options.allow_root:
        cxguitools.warn_if_root()

    if options.command and not options.bottle:
        # We were probably invoked from the command line or via an association,
        # so we should just launch the command immediately. First, pick
        # a reasonable bottle to use.
        if 'CX_BOTTLE' in os.environ:
            options.bottle = os.environ['CX_BOTTLE']
        else:
            bottlelist = bottlequery.get_bottle_list()

            # If the launched file is inside a bottle, use that bottle
            for bottlename in bottlelist:
                cdrive = os.path.realpath(os.path.abspath(bottlequery.get_system_drive(bottlename)))
                filepath = os.path.realpath(os.path.abspath(options.command))
                if filepath.startswith(cdrive):
                    options.bottle = bottlename
                    break

            # Use the default bottle, if there is one:
            if not options.bottle and default_bottle:
                options.bottle = default_bottle

            # If there's only one bottle, use that.
            if len(bottlelist) == 1:
                options.bottle = bottlelist[0]

            if not bottlelist:
                # This is a special case. We can't run anything until
                # a bottle is created, so launch the 'No Bottles' dialog.
                import nobottlesdlg
                nobottlesdlg.NoBottlesController(options.command)
                import gtk
                gtk.main()
                return 0

    if options.command and options.bottle:
        args = [os.path.join(cxutils.CX_ROOT, "bin", "cxstart"),
                "--bottle", options.bottle, "--"]
        args.extend(cxutils.cmdlinetoargv(options.command))
        os.execv(args[0], args)
    else:
        if not options.command and not options.bottle and default_bottle:
            options.bottle = default_bottle

        # Start the GUI
        import cxrunui
        rundlg = cxrunui.open_or_show(options.bottle)
        if options.command:
            rundlg.set_command(options.command)
        import gtk
        gtk.main()
    return 0

if __name__ == "__main__":
    sys.exit(main())