#! /usr/bin/env python
# (c) Copyright 2009-2015. 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 shutil
import stat
# pylint: disable=W0611
import checkpython
import cxopt
import cxlog
# for localization
from cxutils import cxgettext as _
def install(src_license, src_sig):
etc_dir = os.path.join(cxutils.CX_ROOT, "etc")
dst_license = os.path.join(etc_dir, "license.txt")
dst_sig = os.path.join(etc_dir, "license.sig")
try:
shutil.copyfile(src_license, dst_license)
shutil.copyfile(src_sig, dst_sig)
os.chmod(dst_license, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
os.chmod(dst_sig, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
return 0
except Exception: # pylint: disable=W0703
exception = (sys.exc_info())[1]
cxlog.err(str(exception))
return 1
def return_from_root_check(_response):
sys.exit(1)
def main():
# Parse the command line before we do anything that assumes $DISPLAY is set
# so we can handle --help and issue usage errors normally.
opt_parser = cxopt.Parser(usage="%prog [--help]",
description="Registers and unlocks a demo version of CrossOver.")
opt_parser.add_option('--install', action="store_true", dest='install', help="Installs the specified license files")
(options, args) = opt_parser.parse_args()
if options.install:
if len(args) < 2:
opt_parser.error("not enough arguments for --install")
elif len(args) > 2:
opt_parser.error("unexpected argument '%s'" % args[2])
else:
return install(args[0], args[1])
elif args:
opt_parser.error("unexpected argument '%s'" % args[0])
# Check for gtk and $DISPLAY
import checkgtk
if checkgtk.check_gtk() != checkgtk.OK:
return 1
import gtk
import cxguitools
import cxproduct
try:
cxproduct.get_user_dir()
except Exception: # pylint: disable=W0703
exception = (sys.exc_info())[1]
cxguitools.CXMessageDlg(primary=str(exception), secondary=_("This command must be run in your regular user account."), buttons=gtk.BUTTONS_CLOSE, response_function=return_from_root_check, message_type=gtk.MESSAGE_ERROR)
gtk.main()
return 1
cxguitools.set_default_icon('cxregister')
# It's ok to run this tool as root
import cxregisterui
cxregisterui.open_or_show(close_when_finished=True)
gtk.main()
return 0
if __name__ == "__main__":
sys.exit(main())