Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
crossover / opt / cxoffice / bin / cxfix
Size: Mime:
#! /usr/bin/env python
# (c) Copyright 2017. 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


import cxopt
import cxdiag
import cxfixes


def main():
    opt_parser = cxopt.Parser(usage="%prog [--show|--show-all] [--help] (--auto|ISSUE1...)",
                              description="Fixes or shows the fixes for the specified cxdiag issues.")
    opt_parser.add_option('--dry-run', action="store_true", dest='dry_run', help="Show the command that would be run to fix the issues instead of running it.")
    opt_parser.add_option('--show-all', action="store_true", dest='showall', help="Show how the issues would be fixed for each supported distribution.")
    opt_parser.add_option('--auto', action="store_true", dest='auto', help="Call cxdiag and fix all the reported issues.")
    opt_parser.add_option('--required', action="store_true", dest='required', help="Call cxdiag and fix all the critical issues.")
    opt_parser.add_option('--recommended', action="store_true", dest='recommended', help="Call cxdiag and fix the issues that are recommended to fix (including critical ones).")
    opt_parser.add_option('--all', action="store_true", dest='all', help="Apply the fixes for all known issues, whether the issue is reported by cxdiag or not. This is only meant as a debugging option.")
    (options, args) = opt_parser.parse_args()
    if options.auto:
        options.required = options.recommended = True
    elif options.recommended:
        options.required = True
    if options.required or options.all:
        if args:
            opt_parser.error("unexpected argument '%s'" % args[0])
        elif not options.all:
            diag = cxdiag.get(None)
            for errid, (level, title, _description) in diag.warnings.iteritems():
                if (options.required and level == 'Require') or \
                   (options.recommended and level == 'Recommend') or \
                   options.auto:
                    cxfixes.add_error(errid, title)
    else:
        if args:
            for errid in args:
                cxfixes.add_error(errid.lower())
        else:
            opt_parser.error("you must provide the --auto or --all option or a list of issues to fix")

    # Show which distribution we are running on for reference.
    distro = cxfixes.detect_distribution()
    bitness = cxfixes.detect_bitness()
    print "Distribution: %s %s bit (%s)" % (cxfixes.get_distribution_property(distro, 'name'), bitness, distro)

    if options.all:
        for errid in cxfixes.FIXES.iterkeys():
            cxfixes.add_error(errid, None)

    if not cxfixes.has_errors():
        print "There is no issue to fix"
        return 0

    # Try to fix the issues all at once.
    initial_count = len(cxfixes.get_errors())
    if not options.showall:
        if options.dry_run:
            fixable_errors, cmd = cxfixes.get_fix_command()
            print "\nYou may fix the issues by running the following command as root:"
            print cmd
            for errid in fixable_errors:
                cxfixes.remove_error(errid)
        else:
            cxfixes.fix_errors(new_console=False)

    # If we tried to install a nonexistent package the above will have failed.
    # In that case try the fixes one by one.
    if not options.showall and not options.dry_run and \
       cxfixes.has_errors() and initial_count > 1:
        errors = cxfixes.get_errors()
        remaining = {}
        first = True
        for errid in errors.iterkeys():
            cxfixes.clear_errors()
            cxfixes.add_error(errid, errors[errid])
            if cxfixes.has_fix(errid):
                if first:
                    print
                    print "Trying to fix the issues one by one:"
                    first = False
                print "* " + errid
                cxfixes.fix_errors(new_console=False, update=False)
            if cxfixes.has_errors():
                remaining[errid] = errors[errid]
        for errid in remaining.iterkeys():
            cxfixes.add_error(errid, remaining[errid])

    # Finally point the user to online help for issues we cannot fix.
    if cxfixes.has_errors():
        cxfixes.report_errors(prefix=False, gui=False)

    return 0


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