Пример #1
0
def get_fife_paths():
	"""Returns all possible paths to search for the fife module. New paths to be added as needed."""
	# Use the path the user provided.
	from horizons.util.cmdlineoptions import get_option_parser
	options = get_option_parser().parse_args()[0]
	paths = []
	# Check if path was provided by user.
	if options.fife_path:
		fife_path = os.path.abspath(options.fife_path)
		paths.append(fife_path)
		# Support giving the path to FIFE_ROOT/engine/python/fife/__init__.pyc etc.
		if os.path.isfile(fife_path):
			# Support giving the path to FIFE_ROOT/engine/python
			fife_path = os.path.dirname(fife_path)
			paths.append(fife_path)
			# Support giving the path to FIFE_ROOT/engine
			paths.append(os.path.join(fife_path, 'python'))
			# Support giving the path to FIFE_ROOT
			paths.append(os.path.join(fife_path, 'engine', 'python'))
			# Support giving the path to FIFE_ROOT/engine/python/fife
			paths.append(os.path.join(fife_path, '..'))

	# Look for FIFE in the neighborhood of the game dir:
	for opt1 in ('.', '..', '..' + os.sep + '..'):
		for opt2 in ('.', 'fife', 'FIFE', 'Fife', 'fifengine'):
			for opt3 in ('.', 'trunk'):
				path = os.path.abspath(os.path.join('.', opt1, opt2, opt3, 'engine', 'python'))
				if os.path.exists(path):
					paths.append(path)

	return paths
Пример #2
0
def get_fife_paths():
    """Returns all possible paths to search for the fife module. New paths to be added as needed."""
    # Use the path the user provided.
    from horizons.util.cmdlineoptions import get_option_parser
    options = get_option_parser().parse_args()[0]
    paths = []
    # Check if path was provided by user.
    if options.fife_path:
        fife_path = os.path.abspath(options.fife_path)
        paths.append(fife_path)
        # Support giving the path to FIFE_ROOT/engine/python/fife/__init__.pyc etc.
        if os.path.isfile(fife_path):
            # Support giving the path to FIFE_ROOT/engine/python
            fife_path = os.path.dirname(fife_path)
            paths.append(fife_path)
            # Support giving the path to FIFE_ROOT/engine
            paths.append(os.path.join(fife_path, 'python'))
            # Support giving the path to FIFE_ROOT
            paths.append(os.path.join(fife_path, 'engine', 'python'))
            # Support giving the path to FIFE_ROOT/engine/python/fife
            paths.append(os.path.join(fife_path, '..'))

    # Look for FIFE in the neighborhood of the game dir:
    for opt1 in ('.', '..', '..' + os.sep + '..'):
        for opt2 in ('.', 'fife', 'FIFE', 'Fife', 'fifengine'):
            for opt3 in ('.', 'trunk'):
                path = os.path.abspath(
                    os.path.join('.', opt1, opt2, opt3, 'engine', 'python'))
                if os.path.exists(path):
                    paths.append(path)

    return paths
Пример #3
0
def main():
    # abort silently on signal
    signal.signal(signal.SIGINT, functools.partial(exithandler, 130))
    signal.signal(signal.SIGTERM, functools.partial(exithandler, 1))

    # avoid crashing when writing to unavailable standard streams
    setup_streams()

    # use locale-specific time.strftime handling
    try:
        locale.setlocale(locale.LC_TIME, '')
    except locale.Error:  # Workaround for "locale.Error: unsupported locale setting"
        pass

    # Change the working directory to the parent of the content directory
    os.chdir(get_content_dir_parent_path())

    logging.config.dictConfig({
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'default': {
                'class': 'logging.StreamHandler',
                'level': 'WARN',
                'stream': 'ext://sys.stderr'
            }
        },
        'root': {
            'handlers': ['default']
        }
    })

    import horizons.main
    from horizons.i18n import gettext as T
    from horizons.util import create_user_dirs
    from horizons.util.cmdlineoptions import get_option_parser

    check_requirements()
    create_user_dirs()

    options = get_option_parser().parse_args()[0]
    setup_debugging(options)
    init_environment(True)

    # Start UH.
    ret = horizons.main.start(options)

    if logfile:
        logfile.close()
    if ret:
        print(T('Thank you for using Unknown Horizons!'))
    else:
        # Game didn't end successfully
        sys.exit(1)
Пример #4
0
def main():
	# abort silently on signal
	signal.signal(signal.SIGINT, functools.partial(exithandler, 130))
	signal.signal(signal.SIGTERM, functools.partial(exithandler, 1))

	# avoid crashing when writing to unavailable standard streams
	setup_streams()

	# use locale-specific time.strftime handling
	try:
		locale.setlocale(locale.LC_TIME, '')
	except locale.Error: # Workaround for "locale.Error: unsupported locale setting"
		pass

	# Change the working directory to the parent of the content directory
	os.chdir(get_content_dir_parent_path())

	logging.config.dictConfig({
		'version': 1,
		'disable_existing_loggers': False,
		'handlers': {
			'default': {
				'class': 'logging.StreamHandler',
				'level': 'WARN',
				'stream': 'ext://sys.stderr'
			}
		},
		'root': {
			'handlers': ['default']
		}
	})

	import horizons.main
	from horizons.i18n import gettext as T
	from horizons.util import create_user_dirs
	from horizons.util.cmdlineoptions import get_option_parser

	check_requirements()
	create_user_dirs()

	options = get_option_parser().parse_args()[0]
	setup_debugging(options)
	init_environment(True)

	# Start UH.
	ret = horizons.main.start(options)

	if logfile:
		logfile.close()
	if ret:
		print(T('Thank you for using Unknown Horizons!'))
	else:
		# Game didn't end successfully
		sys.exit(1)
Пример #5
0
	def test_sets_up_gui_logger(self, mock_setup_gui_logger, mock_set_debug_log, mock_fife):
		"""
		Make sure the gui logger is setup when starting UH with --gui-log.

		We need some tricks here because horizons.main has some inline imports that would
		trigger the normal Fife setup. By mocking setup_gui_logger with a special
		exception, we quit the startup process but can still assert that is was called.
		"""
		mock_setup_gui_logger.side_effect = Exception('i was called')

		options = get_option_parser().parse_args(['--gui-log', '--no-atlas-generation'])[0]
		try:
			horizons.main.start(options)
		except Exception as e:
			assert e.message == 'i was called', "setup_gui_logger wasn't called"
Пример #6
0
    def test_sets_up_gui_logger(self, mock_setup_gui_logger,
                                mock_set_debug_log, mock_fife):
        """
		Make sure the gui logger is setup when starting UH with --gui-log.

		We need some tricks here because horizons.main has some inline imports that would
		trigger the normal Fife setup. By mocking setup_gui_logger with a special
		exception, we quit the startup process but can still assert that is was called.
		"""
        mock_setup_gui_logger.side_effect = Exception('i was called')

        options = get_option_parser().parse_args(
            ['--gui-log', '--no-atlas-generation'])[0]
        with self.assertRaisesRegex(Exception, 'i was called'):
            horizons.main.start(options)
Пример #7
0
def find_fife():
    # Use the path the user provided.
    from horizons.util.cmdlineoptions import get_option_parser
    options = get_option_parser().parse_args()[0]
    if options.fife_path:
        fife_path = os.path.abspath(options.fife_path)
        # Support giving the path to FIFE_ROOT/engine/python/fife/__init__.pyc etc.
        if os.path.isfile(fife_path):
            fife_path = os.path.dirname(fife_path)
        # Support giving the path to FIFE_ROOT/engine/python
        if import_fife([fife_path]):
            return True
        # Support giving the path to FIFE_ROOT/engine
        if import_fife([os.path.join(fife_path, 'python')]):
            return True
        # Support giving the path to FIFE_ROOT
        if import_fife([os.path.join(fife_path, 'engine', 'python')]):
            return True
        # Support giving the path to FIFE_ROOT/engine/python/fife
        if import_fife([os.path.join(fife_path, '..')]):
            return True

        # End the search to avoid using the wrong (non-user-specified) FIFE.
        log().error('Unable to find FIFE in %s', fife_path)
        exit(1)

    # Try to use the default FIFE (equivalent of just trying to import it).
    if import_fife(None):
        return True

    # Look for FIFE in the neighborhood of the game dir.
    paths = []
    for opt1 in ('.', '..', '..' + os.sep + '..'):
        for opt2 in ('.', 'fife', 'FIFE', 'Fife', 'fifengine'):
            for opt3 in ('.', 'trunk'):
                path = os.path.abspath(
                    os.path.join('.', opt1, opt2, opt3, 'engine', 'python'))
                if os.path.exists(path):
                    paths.append(path)
    return import_fife(paths)
Пример #8
0
def find_fife():
    # Use the path the user provided.
    from horizons.util.cmdlineoptions import get_option_parser

    options = get_option_parser().parse_args()[0]
    if options.fife_path:
        fife_path = os.path.abspath(options.fife_path)
        # Support giving the path to FIFE_ROOT/engine/python/fife/__init__.pyc etc.
        if os.path.isfile(fife_path):
            fife_path = os.path.dirname(fife_path)
            # Support giving the path to FIFE_ROOT/engine/python
        if import_fife([fife_path]):
            return True
            # Support giving the path to FIFE_ROOT/engine
        if import_fife([os.path.join(fife_path, "python")]):
            return True
            # Support giving the path to FIFE_ROOT
        if import_fife([os.path.join(fife_path, "engine", "python")]):
            return True
            # Support giving the path to FIFE_ROOT/engine/python/fife
        if import_fife([os.path.join(fife_path, "..")]):
            return True

            # End the search to avoid using the wrong (non-user-specified) FIFE.
        log().error("Unable to find FIFE in %s", fife_path)
        exit(1)

        # Try to use the default FIFE (equivalent of just trying to import it).
    if import_fife(None):
        return True

        # Look for FIFE in the neighborhood of the game dir.
    paths = []
    for opt1 in (".", "..", ".." + os.sep + ".."):
        for opt2 in (".", "fife", "FIFE", "Fife", "fifengine"):
            for opt3 in (".", "trunk"):
                path = os.path.abspath(os.path.join(".", opt1, opt2, opt3, "engine", "python"))
                if os.path.exists(path):
                    paths.append(path)
    return import_fife(paths)
Пример #9
0
def main():
    # abort silently on signal
    signal.signal(signal.SIGINT, functools.partial(exithandler, 130))
    signal.signal(signal.SIGTERM, functools.partial(exithandler, 1))

    # avoid crashing when writing to unavailable standard streams
    setup_streams()

    # use locale-specific time.strftime handling
    try:
        locale.setlocale(locale.LC_TIME, '')
    except locale.Error:  # Workaround for "locale.Error: unsupported locale setting"
        pass

    # Change the working directory to the parent of the content directory
    os.chdir(get_content_dir_parent_path())
    logging.config.fileConfig(os.path.join('content', 'logging.conf'))
    create_user_dirs()

    from horizons.util.cmdlineoptions import get_option_parser
    options = get_option_parser().parse_args()[0]
    setup_debugging(options)
    init_environment(True)

    # test if required libs can be found or display specific error message
    try:
        import yaml
    except ImportError:
        headline = _('Error: Unable to find required library "PyYAML".')
        msg = _("PyYAML (a required library) is missing and needs to be installed.") + "\n" + \
            _('The Windows installer is available at http://pyyaml.org/wiki/PyYAML.') + " " + \
            _('Linux users should find it using their package manager under the name "pyyaml" or "python-yaml".')
        exit_with_error(headline, msg)

    # Start UH.
    import horizons.main
    ret = True
    if not options.profile:
        # start normal
        ret = horizons.main.start(options)
    else:
        # start with profiling
        try:
            import cProfile as profile
        except ImportError:
            import profile

        from horizons.constants import PATHS
        profiling_dir = os.path.join(PATHS.USER_DIR, 'profiling')
        if not os.path.exists(profiling_dir):
            os.makedirs(profiling_dir)

        pattern = os.path.join(profiling_dir,
                               time.strftime('%Y-%m-%d') + '.%02d.prof')
        num = 1
        while os.path.exists(pattern % num):
            num += 1

        outfilename = pattern % num
        print('Starting in profile mode. Writing output to: %s' % outfilename)
        profile.runctx('horizons.main.start(options)', globals(), locals(),
                       outfilename)
        print('Program ended. Profiling output: %s' % outfilename)

    if logfile:
        logfile.close()
    if ret:
        print(_('Thank you for using Unknown Horizons!'))
Пример #10
0
def main():
    # abort silently on signal
    signal.signal(signal.SIGINT, functools.partial(exithandler, 130))
    signal.signal(signal.SIGTERM, functools.partial(exithandler, 1))

    # avoid crashing when writing to unavailable standard streams
    setup_streams()

    # use locale-specific time.strftime handling
    try:
        locale.setlocale(locale.LC_TIME, "")
    except locale.Error:  # Workaround for "locale.Error: unsupported locale setting"
        pass

        # Change the working directory to the parent of the content directory
    os.chdir(get_content_dir_parent_path())
    logging.config.fileConfig(os.path.join("content", "logging.conf"))
    create_user_dirs()

    from horizons.util.cmdlineoptions import get_option_parser

    options = get_option_parser().parse_args()[0]
    setup_debugging(options)
    init_environment(True)

    # test if required libs can be found or display specific error message
    try:
        import yaml
    except ImportError:
        headline = _('Error: Unable to find required library "PyYAML".')
        msg = (
            _("PyYAML (a required library) is missing and needs to be installed.")
            + "\n"
            + _("The Windows installer is available at http://pyyaml.org/wiki/PyYAML.")
            + " "
            + _('Linux users should find it using their package manager under the name "pyyaml" or "python-yaml".')
        )
        exit_with_error(headline, msg)

        # Start UH.
    import horizons.main

    ret = True
    if not options.profile:
        # start normal
        ret = horizons.main.start(options)
    else:
        # start with profiling
        try:
            import cProfile as profile
        except ImportError:
            import profile

        from horizons.constants import PATHS

        profiling_dir = os.path.join(PATHS.USER_DIR, "profiling")
        if not os.path.exists(profiling_dir):
            os.makedirs(profiling_dir)

        pattern = os.path.join(profiling_dir, time.strftime("%Y-%m-%d") + ".%02d.prof")
        num = 1
        while os.path.exists(pattern % num):
            num += 1

        outfilename = pattern % num
        print("Starting in profile mode. Writing output to: %s" % outfilename)
        profile.runctx("horizons.main.start(options)", globals(), locals(), outfilename)
        print("Program ended. Profiling output: %s" % outfilename)

    if logfile:
        logfile.close()
    if ret:
        print(_("Thank you for using Unknown Horizons!"))
def start_game(*args):
	options = get_option_parser().parse_args(list(args) + ['--no-atlas-generation'])[0]
	horizons.main.start(options)
Пример #12
0
 def start_game(*args):
     options = get_option_parser().parse_args(
         list(args) + ['--no-atlas-generation'])[0]
     horizons.main.start(options)