Пример #1
0
    def _load_modules(self, ctx):
        sys.path.append(environ.pod_dir())
        logger.debug("Webhooks module directory: %s", self.modules_path)

        module_files = self._scan_modules()

        logger.debug("Found %d webhook module(s)" % len(module_files))

        for s in module_files:
            name = os.path.basename(s)
            if '__init__.py' == name:
                continue

            # gets the basename without extension part.
            name = os.path.splitext(name)[0]
            try:
                logger.debug("Loading webhook module: %s", name)
                mod = import_module(_MODULE_PKG + name)
                mod_info = ModuleInfo(name, mod)
                self.modules[name] = mod_info

                ctx.send(signal=MODULE_LOADED, sender=self)
            except ImportError:
                logger.error("Failed to import webhook module: %s",
                             name,
                             exc_info=True)
Пример #2
0
    def __init__(self):
        self.jobs = {}
        self.contexts = {}
        self.runners = {}

        self.jobs_path = os.path.join(environ.pod_dir(), _AVATARS_DIR)
        self.jobs_path = os.path.abspath(self.jobs_path)
        self.validator = ScriptValidator()
        self._core_context = None
        self._stopping = False
        self._task_engine = False
Пример #3
0
    def __init__(self):
        self.jobs = {}
        self.contexts = {}
        self.runners = {}

        self.jobs_path = os.path.join(environ.pod_dir(), _AVATARS_DIR)
        self.jobs_path = os.path.abspath(self.jobs_path)
        self.validator = ScriptValidator()
        self._core_context = None
        self._stopping = False
        self._task_engine = False
Пример #4
0
def init(folder):
    """
    Constructs the skeleton of directories if it not there already.
    :return:
    """

    if os.path.exists(folder):
        click.echo("Folder %s is not empty!" % folder, err=True)
        return

    os.makedirs(folder)

    src_dir = environ.pod_dir()
    # copy files from base_dir to user_dir
    subdirs = os.listdir(src_dir)
    for d in subdirs:
        src_path = os.path.join(src_dir, d)
        dst_path = os.path.join(folder, d)
        if os.path.isdir(src_path):
            shutil.copytree(src_path, dst_path)
        else:
            shutil.copy2(src_path, dst_path)
Пример #5
0
def init(folder):
    """
    Constructs the skeleton of directories if it not there already.
    :return:
    """

    if os.path.exists(folder):
        click.echo("Folder %s is not empty!" % folder, err=True)
        return

    os.makedirs(folder)

    src_dir = environ.pod_dir()
    # copy files from base_dir to user_dir
    subdirs = os.listdir(src_dir)
    for d in subdirs:
        src_path = os.path.join(src_dir, d)
        dst_path = os.path.join(folder, d)
        if os.path.isdir(src_path):
            shutil.copytree(src_path, dst_path)
        else:
            shutil.copy2(src_path, dst_path)
Пример #6
0
def load_commands():
    sys.path.append(environ.pod_dir())
    # logger.debug("Command module directory: %s", _modules_path)

    module_files = _scan_modules()

    # logger.debug("Found %d command module(s)" % len(module_files))

    for s in module_files:
        name = os.path.basename(s)
        if '__init__.py' == name:
            continue

        # gets the basename without extension part.
        name = os.path.splitext(name)[0]
        try:
            # logger.debug("Loading command module: %s", name)
            mod = import_module(_MODULE_PKG + name)
            _modules[name] = mod
        except ImportError:
            logger.error("Failed to import command module: %s",
                         name,
                         exc_info=True)
Пример #7
0
def load_commands():
    sys.path.append(environ.pod_dir())
    # logger.debug("Command module directory: %s", _modules_path)

    module_files = _scan_modules()

    # logger.debug("Found %d command module(s)" % len(module_files))

    for s in module_files:
        name = os.path.basename(s)
        if '__init__.py' == name:
            continue

        # gets the basename without extension part.
        name = os.path.splitext(name)[0]
        try:
            # logger.debug("Loading command module: %s", name)
            mod = import_module(_MODULE_PKG + name)
            _modules[name] = mod
        except ImportError:
            logger.error("Failed to import command module: %s",
                         name,
                         exc_info=True)
Пример #8
0
    def start(self, ctx=None):
        logger.debug("Starting data engine...")

        # register with the context
        ctx.bind('dataengine', self)

        self.datapath = os.path.join(environ.pod_dir(), _DATA_FILE_DIR)
        logger.debug("Data path: %s", self.datapath)

        try:
            self.database = lmdb.Environment(self.datapath,
                                             map_size=2000000000,
                                             max_dbs=1024)
            with self.database.begin(write=False) as txn:
                cur = txn.cursor()
                for k, v in iter(cur):
                    logger.debug("Found existing store: %s", k)
                    _db = self.database.open_db(k, create=False)
                    self.stores[k] = Store(k, _db, self)
        except lmdb.Error:
            logger.exception("Failed to open database.", exc_info=True)
            raise

        logger.debug("Data engine started.")
Пример #9
0
    def _load_modules(self, ctx):
        sys.path.append(environ.pod_dir())
        logger.debug("Tasks module directory: %s", self.modules_path)

        module_files = self._scan_modules()

        logger.debug("Found %d task module(s)" % len(module_files))

        for s in module_files:
            name = os.path.basename(s)
            if '__init__.py' == name:
                continue

            # gets the basename without extension part.
            name = os.path.splitext(name)[0]
            try:
                logger.debug("Loading task module: %s", name)
                mod = import_module(_MODULE_PKG + name)
                mod_info = ModuleInfo(name, mod)
                self.modules[name] = mod_info

                ctx.send(signal=MODULE_LOADED, sender=self)
            except ImportError:
                logger.error("Failed to import task module: %s", name, exc_info=True)
Пример #10
0
from ava import APP_NAME
from ava.runtime import environ

click.disable_unicode_literals_warning = True

_MODULES_DIR = os.path.join('mods', 'commands')

# the package name for modules.
_MODULE_PKG = 'mods.commands.'

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])

logger = logging.getLogger(__name__)

_modules_path = os.path.join(environ.pod_dir(), _MODULES_DIR)
_modules_path = os.path.abspath(_modules_path)
_modules = {}


def _scan_modules():
    pattern = os.path.join(_modules_path, '[a-zA-Z][a-zA-Z0-9_]*.py')
    return glob.glob(pattern)


def load_commands():
    sys.path.append(environ.pod_dir())
    # logger.debug("Command module directory: %s", _modules_path)

    module_files = _scan_modules()
Пример #11
0
 def __init__(self):
     self.modules = {}
     self.modules_path = os.path.join(environ.pod_dir(), _MODULES_DIR)
     self.modules_path = os.path.abspath(self.modules_path)
Пример #12
0
from ava import APP_NAME
from ava.runtime import environ

click.disable_unicode_literals_warning = True

_MODULES_DIR = os.path.join('mods', 'commands')

# the package name for modules.
_MODULE_PKG = 'mods.commands.'

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])

logger = logging.getLogger(__name__)

_modules_path = os.path.join(environ.pod_dir(), _MODULES_DIR)
_modules_path = os.path.abspath(_modules_path)
_modules = {}


def _scan_modules():
    pattern = os.path.join(_modules_path, '[a-zA-Z][a-zA-Z0-9_]*.py')
    return glob.glob(pattern)


def load_commands():
    sys.path.append(environ.pod_dir())
    # logger.debug("Command module directory: %s", _modules_path)

    module_files = _scan_modules()
Пример #13
0
def open():
    """ Open Pod folder in a file explorer or the like.
    """
    click.launch(environ.pod_dir())
Пример #14
0
def open():
    """ Open Pod folder in a file explorer or the like.
    """
    click.launch(environ.pod_dir())
Пример #15
0
import os

import logging
from ..core import get_core_context
from ava.runtime import environ
from ava.runtime.config import settings

from .bottle import request, response, HTTPError, static_file as _static_file
from . import defines as D



logger = logging.getLogger(__name__)


static_folder = os.path.join(environ.pod_dir(), 'webroot')


def get_webfront_engine():
    return get_core_context().lookup(D.WEBFRONT_CONTEXT_NAME)


def raise_unauthorized(desc=b'Authentication required.'):
    raise HTTPError(D.HTTP_STATUS_AUTH_REQUIRED, desc)


def get_access_token():
    return get_webfront_engine().access_token


def require_auth(callback):
Пример #16
0
 def on_open_folder(self, sender):
     click.launch(environ.pod_dir())
Пример #17
0
 def __init__(self):
     self.modules = {}
     self.modules_path = os.path.join(environ.pod_dir(), _MODULES_DIR)
     self.modules_path = os.path.abspath(self.modules_path)
Пример #18
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

import os

import logging
from ..core import get_core_context
from ava.runtime import environ
from ava.runtime.config import settings

from .bottle import request, response, HTTPError, static_file as _static_file
from . import defines as D

logger = logging.getLogger(__name__)

static_folder = os.path.join(environ.pod_dir(), 'webroot')


def get_webfront_engine():
    return get_core_context().lookup(D.WEBFRONT_CONTEXT_NAME)


def raise_unauthorized(desc=b'Authentication required.'):
    raise HTTPError(D.HTTP_STATUS_AUTH_REQUIRED, desc)


def get_access_token():
    return get_webfront_engine().access_token


def require_auth(callback):
Пример #19
0
    def __init__(self, config, repository=None):

        util.initLogging(config[b"verbose"], config.get(b"enable_loggers", []))
        util.log("Default encoding: %s (file system: %s)" % (sys.getdefaultencoding(), sys.getfilesystemencoding()))

        self.config = config
        self.repository = repository
        self.repo_provider = RepositoryProvider(repository)

        # Evaluate configuration and set defaults
        _checkConfig(config)
#        response_trailer = config.get("response_trailer", "")
        self._verbose = config.get(b"verbose", 2)

        lockStorage = config.get(b"locksmanager")
        if lockStorage is True:
            lockStorage = LockStorageDict()
            
        if not lockStorage:
            self.locksManager = None
        else:
            self.locksManager = LockManager(lockStorage)

        self.propsManager = config.get(b"propsmanager")
        if not self.propsManager:
            # Normalize False, 0 to None
            self.propsManager = None
        elif self.propsManager is True:
            self.propsManager = PropertyManager()

        self.mount_path = config.get(b"mount_path")
         
        user_mapping = self.config.get(b"user_mapping", {})
        domainController = config.get(b"domaincontroller") or WsgiDAVDomainController(user_mapping)
        isDefaultDC = isinstance(domainController, WsgiDAVDomainController)

        # authentication fields
        authacceptbasic = config.get(b"acceptbasic", True)
        authacceptdigest = config.get(b"acceptdigest", True)
        authdefaultdigest = config.get(b"defaultdigest", True)
        
        # Check configuration for NTDomainController
        # We don't use 'isinstance', because include would fail on non-windows boxes.
        wdcName = b"NTDomainController"
        if domainController.__class__.__name__ == wdcName:
            if authacceptdigest or authdefaultdigest or not authacceptbasic:
                util.warn("WARNING: %s requires basic authentication.\n\tSet acceptbasic=True, acceptdigest=False, defaultdigest=False" % wdcName)
                
        # Instantiate DAV resource provider objects for every share
        self.repo_provider.setSharePath(b'/')
        self.repo_provider.setLockManager(self.locksManager)
        self.repo_provider.setPropManager(self.propsManager)

        if self.mount_path:
            self.repo_provider.setMountPath(self.mount_path)

        fs_provider = FilesystemProvider(os.path.join(environ.pod_dir(), b'temp'))
        fs_provider.setSharePath(b'/temp')
        fs_provider.setLockManager(self.locksManager)
        fs_provider.setPropManager(self.propsManager)
        if self.mount_path:
            fs_provider.setMountPath(self.mount_path)

        self.providerMap = {}
        self.providerMap[b'/'] = self.repo_provider
        self.providerMap[b'/temp'] = fs_provider

        for name in self.repository.repository_names():
            archive = self.repository.get_repository(name)
            provider = ArchiveProvider(self.repository,
                                       name,
                                       archive)
            sharePath = b'/' + name
            provider.setSharePath(sharePath)

            if self.mount_path:
                provider.setMountPath(self.mount_path)

            provider.setLockManager(self.locksManager)
            provider.setPropManager(self.propsManager)
            self.providerMap[sharePath] = provider

        if self._verbose >= 2:
            logger.debug("Using lock manager: %r", self.locksManager)
            logger.debug("Using property manager: %r", self.propsManager)
            logger.debug("Using domain controller: %s", domainController)
            logger.debug("Registered DAV providers:")

            for share, provider in self.providerMap.items():
                hint = b""
                if isDefaultDC and not user_mapping.get(share):
                    hint = b" (anonymous)"
                print("  Share '%s': %s%s" % (share, provider, hint))

        # If the default DC is used, emit a warning for anonymous realms
        if isDefaultDC and self._verbose >= 1:
            for share in self.providerMap:
                if not user_mapping.get(share):
                    # TODO: we should only warn here, if --no-auth is not given
                    logger.warning("WARNING: share '%s' will allow anonymous access.", share)

        # Define WSGI application stack
        application = RequestResolver()
        
        if config.get(b"dir_browser") and config[b"dir_browser"].get(b"enable", True):
            application = config[b"dir_browser"].get(b"app_class", WsgiDavDirBrowser)(application)

        application = HTTPAuthenticator(application, 
                                        domainController, 
                                        authacceptbasic, 
                                        authacceptdigest, 
                                        authdefaultdigest)      
        application = ErrorPrinter(application, catchall=False)

        application = WsgiDavDebugFilter(application, config)
        
        self._application = application