Example #1
0
def galacteekGui(args):
    progName = args.binaryname if args.binaryname else sys.argv[0]

    gc.enable()

    if inPyInstaller():
        folder = pyInstallerBundleFolder()
        binPath = folder.joinpath('bin')
        os.environ['PATH'] = str(binPath) + os.pathsep + os.environ['PATH']

        os.chdir(str(folder))

    if args.mallocdebug:
        tracemalloc.start()

    if args.debug:
        faulthandler.enable()

    # QtWebEngine init
    QtWebEngine.initialize()

    # Initialize webengine schemes before creating the application
    initializeSchemes()

    gApp = application.GalacteekApplication(
        profile=args.profile,
        debug=args.debug,
        enableOrbital=args.enableorbital,
        sslverify=False if args.nosslverify else True,
        progName=progName,
        cmdArgs=args)

    level = 'DEBUG' if args.debug else 'INFO'
    if args.logstderr:
        glogger.basicConfig(level=level,
                            colorized=args.logcolorized,
                            loop=gApp.loop)
    else:
        glogger.basicConfig(outputFile=gApp.mainLogFileLocation,
                            level=level,
                            colorized=args.logcolorized,
                            loop=gApp.loop)

    if not gApp.acquireLock():
        gApp.onExit()
        return

    gApp.configure()

    # Monitor event loop if aiomonitor is available
    # Use the context manager so loop cleanup/close is automatic

    loop = gApp.loop
    if args.monitor is True and haveAiomonitor:
        with aiomonitor.start_monitor(loop=loop):
            with loop:
                loop.run_forever()
    else:
        with loop:
            loop.run_forever()
Example #2
0
def pkgListPackages(pkgName: str):
    """
    Lists packages names in a package given its name

    Yields (pkg, fullname) tuples
    """

    if inPyInstaller():
        # From pyinstaller, pkgutil.iter_modules() doesn't work AFAIK
        # Use the TOC instead

        toc = tocGet()

        for fname in toc:
            if fname.startswith(pkgName):
                match = re.search(rf'{pkgName}\.([a-zA-Z0-9]+)$', fname)
                if match:
                    yield (match.group(1), fname)
    else:
        try:
            pkg = importlib.import_module(pkgName)
            for imp, modname, isPkg in pkgutil.iter_modules(pkg.__path__):
                if not isPkg:
                    continue

                yield (modname, f'{pkgName}.{modname}')
        except Exception:
            pass
Example #3
0
def start():
    global appStarter

    if platform.system() == 'Windows' and inPyInstaller() and 0:
        # Hide the console window when running with pyinstaller
        hideConsoleWindow()

    args = gArgsParse()

    if args.version is True:
        print(__version__)
        sys.exit()

    appStarter = ApplicationStarter(args)
    appStarter.start()
Example #4
0
def magicInstance():
    global iMagic

    if iMagic is None:
        pl = platform.system()

        if pl == 'Linux':
            iMagic = magic.Magic(mime=True)
        elif pl in ['Darwin', 'Windows']:
            if inPyInstaller():
                dbPath = str(pyInstallerBundleFolder().joinpath('magic.mgc'))
            else:
                dbPath = os.environ.get('GALACTEEK_MAGIC_DBPATH')

            if dbPath:
                log.debug(f'Using magic DB from path: {dbPath}')
                iMagic = magic.Magic(mime=True, magic_file=dbPath)

    return iMagic
Example #5
0
def defaultJinjaEnv():
    # We use Jinja's async rendering

    if inPyInstaller():
        tFolder = pyInstallerPkgFolder().joinpath('galacteek/templates')
        log.debug(f'jinja2 env: using filesystem loader with root '
                  f'{tFolder}')
        loader = jinja2.FileSystemLoader(tFolder)
    else:
        loader = jinja2.PackageLoader('galacteek', 'templates')

    env = jinja2.Environment(
        loader=loader,
        enable_async=True
    )
    env.filters['tstodate'] = tstodate
    env.filters['ipfspathnorm'] = ipfspathnorm
    env.filters['markdown'] = markdownconv
    env.filters['dtclean'] = datetimeclean
    env.filters['ipidExtract'] = ipidExtract
    return env