How to use the cartoview.log_handler.get_logger function in cartoview

To help you get started, we’ve selected a few cartoview 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 cartologic / cartoview / cartoview / app_manager / settings.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import importlib
import os
import sys
import threading

from future import standard_library

from cartoview.log_handler import get_logger

logger = get_logger(__name__, with_formatter=True)
lock = threading.Lock()
standard_library.install_aliases()

# BASE_DIR must be defined in project.settings

CARTOVIEW_APPS = ()
APPS_SETTINGS = []


def load_apps(APPS_DIR):
    with lock:
        from cartoview.apps_handler.utils import create_apps_dir
        from cartoview.apps_handler.config import CartoviewApp
        global CARTOVIEW_APPS
        global APPS_SETTINGS
        create_apps_dir(APPS_DIR)
github cartologic / cartoview / cartoview / api / views / connections.py View on Github external
from cartoview.log_handler import get_logger
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse
from django.utils.translation import gettext_lazy as _
from rest_framework import permissions, status, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.views import APIView

from ..permissions import AuthPermission, IsOwnerOrReadOnly
from ..serializers.connections import (ServerSerializer,
                                       SimpleAuthConnectionSerializer,
                                       TokenAuthConnectionSerializer)

logger = get_logger(__name__)


class AuthConnectionViewSet(viewsets.ModelViewSet):
    permission_classes = (permissions.IsAuthenticated, AuthPermission,)

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        queryset = queryset.filter(owner=request.user)
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)
github cartologic / cartoview / cartoview / app_manager / management / commands / install_app.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import print_function

from django.core.management.base import BaseCommand

from cartoview.app_manager.installer import AppInstaller
from cartoview.app_manager.models import App, AppStore
from cartoview.log_handler import get_logger
from packaging import version

logger = get_logger(__name__)


def compare_version(v1, v2):
    return version.parse(v1) < version.parse(v2)


class Command(BaseCommand):
    help = 'Install App'

    def add_arguments(self, parser):
        parser.add_argument(
            '-n', '--name', dest='name', help='Name Of The App To Install')
        parser.add_argument(
            '-av',
            '--app_version',
            type=str,
github cartologic / cartoview / cartoview / app_manager / installer.py View on Github external
from django.conf import settings
from django.db import transaction
from django.db.models import Max
from future import standard_library

from cartoview.apps_handler.config import CartoviewApp
from cartoview.log_handler import get_logger
from cartoview.store_api.api import StoreAppResource, StoreAppVersion
from .decorators import restart_enabled, rollback_on_failure
from .exceptions import AppAlreadyInstalledException
from .models import App, AppStore, AppType
from ..apps_handler.req_installer import (ReqFileException,
                                          ReqFilePermissionException,
                                          ReqInstaller)

logger = get_logger(__name__)
install_app_batch = getattr(settings, 'INSTALL_APP_BAT', None)
standard_library.install_aliases()
importlib.reload(pkg_resources)

lock = threading.RLock()


class RestartHelper(object):
    @classmethod
    def django_reload(cls):
        try:
            from django.utils.autoreload import restart_with_reloader
            restart_with_reloader()
            from .utils import populate_apps
            populate_apps()
        except Exception as e:
github cartologic / cartoview / cartoview / app_manager / os_utils.py View on Github external
# -*- coding: utf-8 -*-
import os
import stat

from cartoview.log_handler import get_logger

world_permission = 0o777
logger = get_logger(__name__)


def create_direcotry(path, mode=0o777):
    # please read the following section
    # https://docs.python.org/2/library/os.html#mkdir-modebits
    if not os.path.exists(path):
        try:
            previous_mask = os.umask(0)
            os.makedirs(path, mode=mode)
        except OSError as e:
            logger.error(e.message)
        finally:
            # set the previous mask back
            os.umask(previous_mask)
github cartologic / cartoview / cartoview / geonode_oauth / utils.py View on Github external
# -*- coding: utf-8 -*-
import requests
from allauth.socialaccount.models import SocialToken
from cartoview.log_handler import get_logger
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.utils import timezone
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

logger = get_logger(__name__)


def requests_retry_session(retries=3,
                           backoff_factor=1,
                           status_forcelist=(502, 503, 504),
                           session=None):
    session = session or requests.Session()
    retry = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=backoff_factor,
        status_forcelist=status_forcelist,
        method_whitelist=frozenset(['GET', 'POST', 'PUT', 'DELETE', 'HEAD']))
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
github cartologic / cartoview / cartoview / apps_handler / apps.py View on Github external
# -*- coding: utf-8 -*-

import os

import portalocker
import yaml
from django.apps import AppConfig
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError

from cartoview.log_handler import get_logger

pending_yaml = settings.PENDING_APPS

logger = get_logger(__name__)


class AppsHandlerConfig(AppConfig):
    name = 'cartoview.apps_handler'
    verbose_name = "Apps Handler"

    def delete_application_on_fail(self, appname):
        from cartoview.app_manager.installer import AppInstaller
        AppInstaller(appname).uninstall(restart=True)

    def reset(self):
        with open(pending_yaml, 'w+') as f:
            portalocker.lock(f, portalocker.LOCK_EX)
            yaml.dump([], f)

    def execute_pending(self):
github cartologic / cartoview / cartoview / connections / utils.py View on Github external
# -*- coding: utf-8 -*-
from functools import lru_cache
from urllib.parse import parse_qsl, unquote_plus, urlparse

from cartoview.log_handler import get_logger
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import gettext_lazy as _

from . import SUPPORTED_SERVERS
from .exceptions import ConnectionTypeException

logger = get_logger(__name__)


class URL(object):
    def __init__(self, url):
        parts = urlparse(url)
        _query = frozenset(parse_qsl(parts.query))
        _path = unquote_plus(parts.path)
        parts = parts._replace(query=_query, path=_path)
        self.parts = parts

    def __eq__(self, other):
        return self.parts == other.parts

    @classmethod
    def compare_netloc(cls, source_url, target_url):
        source = URL(source_url)
github cartologic / cartoview / cartoview / app_manager / apps_operations.py View on Github external
# -*- coding: utf-8 -*-

import json
import os

from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError

from cartoview.log_handler import get_logger

logger = get_logger(__name__)


class AppsHandler(object):
    def __init__(self):
        pass

    def delete_application_on_fail(self, appname):
        from cartoview.app_manager.installer import AppInstaller
        AppInstaller(appname).uninstall(restart=True)

    def get_pending_apps(self, app_name):
        app = {"name": app_name, "makemigrations": False, "migrate": True}
        DEFAULT_APPS = [
            app,
        ]
        apps = DEFAULT_APPS
github cartologic / cartoview / cartoview / app_manager / models.py View on Github external
from guardian.shortcuts import assign_perm
from taggit.managers import TaggableManager
from cartoview.log_handler import get_logger
from cartoview.base_resource.models import BaseModel
from cartoview.fields import ListField
from cartoview.layers.validators import validate_projection
from cartoview.maps.models import Map
from cartoview.validators import ListValidator

APPS_PERMISSIONS = (
    ("install_app", _("Install App")),
    ("uninstall_app", _("Uninstall App")),
    ("change_state", _("Change App State (active, suspend)")),
)

logger = get_logger(__name__)


class AppTypeManager(models.Manager):
    def without_apps_duplication(self):
        return super(AppTypeManager, self).get_queryset().distinct("apps")


class AppType(models.Model):
    name = models.CharField(max_length=200, unique=True)
    objects = AppTypeManager()

    class Meta:
        ordering = ["-name"]

    def __str__(self):
        return self.name