Ejemplo n.º 1
0
        def run():
            lib_dir = os.path.abspath(
                os.path.join(
                    os.path.dirname(__file__),
                    '..'
                )
            )
            for lib in ['cube', 'cubeapp']:
                import_tests(lib_dir, lib)

            cube.log.set_mode(cube.log.Mode.synchroneous)
            if args.unittest:
                pattern = '*%s*' % args.unittest
            else:
                pattern = '*'
            if cube.test.registry.run(pattern):
                cube.info("All tests passed")
                return 0
            else:
                return 1
Ejemplo n.º 2
0
    def populate(cls):
        if cls.fonts is not None:
            return

        start = time.time()
        from cube.constants.application import config_directory
        fonts_dir = os.path.join(config_directory(), "fonts")
        if not os.path.exists(fonts_dir):
            os.makedirs(fonts_dir)
        fonts_file = os.path.join(fonts_dir, "fonts.lst")
        if os.path.exists(fonts_file):
            cube.debug("Loading fonts from cache file '%s'" % fonts_file)
            try:
                with open(fonts_file, 'rb') as f:
                    cls.fonts = pickle.loads(f.read())
            except Exception as e:
                cube.warn("font cache file '%s' is not valid, it will be removed:" % fonts_file, e)
                os.unlink(fonts_file)
        else:
            cube.info("Finding fonts on your system, this may take a while...")
            cls.fonts = {}
            for font_dir in cls.font_directories():
                for root, dirs, files in os.walk(font_dir):
                    for f in files:
                        path = os.path.join(root, f)
                        if font.is_valid(path):
                            try:
                                cls.fonts[path] = font.get_infos(path)
                            except:
                                cube.error("ignoring font file", path)

        if not cls.fonts:
            raise Exception("Couldn't find any font on your system !")
        cube.info(len(cls.fonts), "font infos fetched in %f seconds" % (time.time() - start))

        cube.debug("Saving fonts into cache file '%s'" % fonts_file)
        with open(fonts_file, 'wb') as f:
            f.write(pickle.dumps(cls.fonts))
Ejemplo n.º 3
0
def main(argv):
    cube = import_cube()
    sys.argv = ['cubeapp.main'] + argv
    cube.info("Launching 8cube with args", argv)
    cube.constants.application.name("8cube")

    # XXX remove that
    #with cube.trace_info("Initializing the font manager"):
    #    cube.gui.FontManager.populate()

    try:
        parser, args = parse_args(argv)
    except SystemExit as e:
        return e.code

    if args.disable_gc:
        gc.disable()

    try:
        if args.debug:
            gc.set_debug(gc.DEBUG_STATS)
        if args.profile:
            import cProfile, pstats
            pr = cProfile.Profile()
            pr.enable()
            ret = _main(parser, args)
            pr.disable()
            stats = pstats.Stats(pr)
            stats.sort_stats(*tuple(args.profile))
            stats.print_stats()
            stats.dump_stats(args.profile_output)
        else:
            ret = _main(parser, args)
        gc.collect()
        return ret
    except KeyboardInterrupt:
        return 1
    except BaseException as e:
        if isinstance(e, cube.Exception):
            bt = e.backtrace[2:]
            index = -1
            for i, frame in enumerate(bt):
                if 'boost::python::detail::caller' in frame or \
                   'boost::python::detail::invoke' in frame:
                    index = i
                    break
            if index > 0:
                bt = bt[:index]
            bt.reverse()
        else:
            bt = None

        cube.log.error("Python traceback: (most recent call last)")
        cube.log.error('\n'.join(traceback.format_exception(type(e), e, e.__traceback__)))
        if bt is not None:
            cube.log.error("c++ traceback: (most recent call last)")
            s = ''
            for i, frame in enumerate(bt):
                s += '  %i: %s\n' % (i + 1, frame)
            cube.log.error(s)
        if args.debug:
            import pdb
            pdb.post_mortem(e.__traceback__)
        cube.log.fatal('\n'.join(traceback.format_exception_only(type(e), e)))
        return 1