How to use the aj.platform function in aj

To help you get started, we’ve selected a few aj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ajenti / ajenti / ajenti-core / aj / __init__.py View on Github external
def init():
    import aj
    aj.version = detect_version()
    if aj.platform is None:
        aj.platform_unmapped, aj.platform = detect_platform()
    else:
        logging.warn('Platform ID was enforced by commandline!')
        aj.platform_unmapped = aj.platform
    aj.platform_string = detect_platform_string()
github ajenti / ajenti / ajenti-core / aj / __init__.py View on Github external
def init():
    import aj
    aj.version = detect_version()
    if aj.platform is None:
        aj.platform_unmapped, aj.platform = detect_platform()
    else:
        logging.warn('Platform ID was enforced by commandline!')
        aj.platform_unmapped = aj.platform
    aj.platform_string = detect_platform_string()
github ajenti / ajenti / ajenti-core / aj / core.py View on Github external
if os.path.exists(path):
            os.unlink(path)
        listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        try:
            listener.bind(path)
        except OSError:
            logging.error('Could not bind to %s', path)
            sys.exit(1)

    if aj.config.data['bind']['mode'] == 'tcp':
        host = aj.config.data['bind']['host']
        port = aj.config.data['bind']['port']
        listener = socket.socket(
            socket.AF_INET6 if ':' in host else socket.AF_INET, socket.SOCK_STREAM
        )
        if aj.platform not in ['freebsd', 'osx']:
            try:
                listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 1)
            except socket.error:
                logging.warn('Could not set TCP_CORK')
        listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        logging.info('Binding to [%s]:%s', host, port)
        try:
            listener.bind((host, port))
        except socket.error as e:
            logging.error('Could not bind: %s', str(e))
            sys.exit(1)

    # Fix stupid socketio bug (it tries to do *args[0][0])
    socket.socket.__getitem__ = lambda x, y: None

    listener.listen(10)
github ajenti / ajenti / ajenti-core / aj / core.py View on Github external
if aj.debug:
        logging.warn('Debug mode')
    if aj.dev:
        logging.warn('Dev mode')

    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error:
        logging.warning('Couldn\'t set default locale')

    # install a passthrough gettext replacement since all localization is handled in frontend
    # and _() is here only for string extraction
    __builtins__['_'] = lambda x: x

    logging.info('Ajenti Core %s', aj.version)
    logging.info('Detected platform: %s / %s', aj.platform, aj.platform_string)

    # Load plugins
    PluginManager.get(aj.context).load_all_from(aj.plugin_providers)
    if len(PluginManager.get(aj.context)) == 0:
        logging.warn('No plugins were loaded!')

    if aj.config.data['bind']['mode'] == 'unix':
        path = aj.config.data['bind']['socket']
        if os.path.exists(path):
            os.unlink(path)
        listener = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        try:
            listener.bind(path)
        except OSError:
            logging.error('Could not bind to %s', path)
            sys.exit(1)
github ajenti / ajenti / plugins / network / managers / ubuntu_manager.py View on Github external
def __verify__(cls):
        if b'Ubuntu' in aj.platform_string:
            ubuntu_version = int(aj.platform_string[7:9])
        return aj.platform in ['debian'] and ubuntu_version >= 18
github ajenti / ajenti / plugins / datetime / managers / debian_manager.py View on Github external
def __verify__(cls):
        return aj.platform in ['debian', 'gentoo']
github ajenti / ajenti / ajenti-core / aj / util / misc.py View on Github external
"""
    Selects a value from **kwargs** depending on runtime platform

    ::

        service = platform_select(
            debian='samba',
            ubuntu='smbd',
            centos='smbd',
            default='samba',
        )

    """
    if aj.platform_unmapped in values:
        return values[aj.platform_unmapped]
    if aj.platform in values:
        return values[aj.platform]
    return values.get('default', None)
github ajenti / ajenti / ajenti-core / aj / util / misc.py View on Github external
Python | %s
Debug | %s
Loaded plugins | %s

Library | Version
------- | -------
gevent | %s
greenlet | %s
psutil | %s


%s

            """ % (
            version,
            platform, platform_unmapped, platform_string,
            subprocess.check_output(['uname', '-mp']).strip(),
            '.'.join([str(x) for x in _platform.python_version_tuple()]),
            debug,
            ', '.join(sorted(PluginManager.get(aj.context).get_loaded_plugins_list())),

            gevent.__version__,
            greenlet.__version__,
            psutil.__version__,

            tb,
        )
github ajenti / ajenti / plugins / core / views / main.py View on Github external
)
                    o, e = p.communicate()
                    if p.returncode != 0:
                        logging.error('Resource compilation failed')
                        logging.error(o + e)

        manager = PluginManager.get(aj.context)
        path = manager.get_content_path('core', 'content/pages/index.html')
        content = open(path).read() % {
            'prefix': http_context.prefix,
            'plugins': json.dumps(
                dict((manager[n]['info']['name'], manager[n]['info']['title']) for n in manager)
            ),
            'config': json.dumps(aj.config.data),
            'version': six.text_type(aj.version),
            'platform': aj.platform,
            'platformUnmapped': aj.platform_unmapped,
            'bootstrapColor': aj.config.data.get('color', None),
        }
        http_context.add_header('Content-Type', 'text/html')
        http_context.respond_ok()
        return content