Skip to content

Commit

Permalink
Merge 4069800 into 8eea73a
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamkaram committed Jan 31, 2019
2 parents 8eea73a + 4069800 commit 834f06f
Show file tree
Hide file tree
Showing 112 changed files with 1,258 additions and 18,093 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
node_modules
.DS_Store
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ deploy:
on:
tags: true
all_branches: true
condition: $TRAVIS_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+
condition: $TRAVIS_TAG =~ ^v([0-9]+\.?){2,3}(b[0-9]+|rc[0-9]+){0,1}
notifications:
email:
- hisham.karam@cartologic.com
- hishamwaleedkaram@gmail.com
- ahmednosman@cartologic.com
- ahmedNourElDeen@cartologic.com
55 changes: 17 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
FROM ubuntu:16.04
FROM python:2.7-slim
LABEL "MAINTAINER"="Cartologic Development Team"
ENV TERM xterm
RUN apt-get update
RUN apt-get install locales -y
RUN locale-gen en_US.UTF-8 && update-locale
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get install software-properties-common python-software-properties -y
RUN add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get update && apt-get install -y \
gcc gettext \
python-pip libpq-dev \
sqlite3 git gdal-bin lsof psmisc \
python-gdal python-psycopg2 \
python-imaging python-lxml \
python-dev libgdal-dev libgeoip-dev \
python-ldap libxml2 libxml2-dev libxslt-dev \
libmemcached-dev libsasl2-dev zlib1g-dev \
python-pylibmc python-setuptools \
curl build-essential build-essential python-dev \
--no-install-recommends
RUN mkdir /code
WORKDIR /code
RUN pip install --upgrade pip
RUN pip install --ignore-installed geoip django-geonode-client \
geonode==2.8rc11 django-jsonfield django-jsonfield-compat \
cartoview==1.8.3 cherrypy==11.0.0 cheroot==5.8.3 \
django-autocomplete-light==2.3.3 --no-cache-dir
RUN pip install git+https://github.com/GeoNode/django-osgeo-importer.git
RUN apt autoremove --purge -y && apt autoclean -y
RUN rm -rf ~/.cache/pip
RUN rm -rf /var/lib/apt/lists/* && apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN echo "Yes, do as I say!" | apt-get remove --force-yes login \
&& dpkg --remove --force-depends wget unzip
ENV PYTHONUNBUFFERED 1
ARG GEONODE_DEV=true
ARG GEONODE_SHA1=992daf724e83cdb0c1eb776d147eba841ad02cd9
ARG APP_DIR=/usr/src/carto_app
# include GDAL HEADER Files
# CPATH specifies a list of directories to be searched as if specified with -I,
# but after any paths given with -I options on the command line.
# This environment variable is used regardless of which language is being preprocessed.
ENV CPATH "$CPATH:/usr/include/gdal:/usr/include"
COPY scripts/docker/setup.sh ./
COPY . /cartoview
RUN chmod +x setup.sh
RUN ./setup.sh
# switch to project dir
VOLUME ${APP_DIR}
WORKDIR ${APP_DIR}
CMD ["/bin/bash"]
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<img src="https://cartologic.github.io/img/cartoview-logo.png"/>
</p>

| WARNING: be careful this version(1.10.x) of Cartoview is compatibile with geonode 2.10.x only,if you want to install another version please take alook on [this section](https://github.com/cartologic/cartoview/blob/hisham-dev/README.md#previous-versions) |
| --- |

---
## What is Cartoview?
- CartoView is a GIS Web Mapping Application Market.
Expand Down Expand Up @@ -43,7 +46,7 @@

## How To Add Cartoview To Existing Geonode:
- install cartoview with pip:
- `pip install cartoview==1.8.5 --no-cache-dir`
- `pip install cartoview --no-cache-dir`
- open geonode `settings.py` and add the following lines at the end of the file:
```python
from cartoview import settings as cartoview_settings
Expand Down Expand Up @@ -84,3 +87,9 @@
```sh
paver run_test
```
___
# Previous Versions
| Cartoview Version | Geonode Version | docs Link |
|-------------------|-----------------|---------------------------------------------------------------------------------|
| 1.8.x | 2.8.x | [Here](https://github.com/cartologic/cartoview/blob/1.8.x/README.md) |
| 1.6.x | 2.6.x | [Here](https://github.com/cartologic/cartoview/blob/2.6.x_compatible/README.md) |
2 changes: 1 addition & 1 deletion cartoview/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = (1, 8, 6, 'unstable', 0)
__version__ = (1, 10, 0, 'beta', 0)
__compatible_with__ = []


Expand Down
15 changes: 7 additions & 8 deletions cartoview/app_manager/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .utils import resolve_appinstance
from django.conf import settings
from django.utils.translation import ugettext as _

from .exceptions import AppAlreadyInstalledException
from .utils import resolve_appinstance

PERMISSION_MSG_DELETE = _("You are not permitted to delete this Instance")
PERMISSION_MSG_GENERIC = _("You do not have permissions for this Instance.")
PERMISSION_MSG_MODIFY = _("You are not permitted to modify this Instance")
Expand Down Expand Up @@ -40,9 +42,6 @@ def restart_enabled(func):
def wrap(*args, **kwargs):
if not getattr(settings, "CARTOVIEW_TEST", False):
return func(*args, **kwargs)
else:
pass

return wrap


Expand All @@ -52,8 +51,8 @@ def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except BaseException as e:
if hasattr(this, '_rollback'):
this._rollback()
raise e

if not isinstance(e, AppAlreadyInstalledException):
if hasattr(this, '_rollback'):
this._rollback()
raise e
return wrap
2 changes: 2 additions & 0 deletions cartoview/app_manager/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class AppAlreadyInstalledException(BaseException):
message = "Application is already installed."
40 changes: 24 additions & 16 deletions cartoview/app_manager/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import threading
import zipfile
from io import BytesIO
from os import R_OK, access
from sys import executable, exit
from threading import Timer

Expand All @@ -25,9 +24,12 @@
from cartoview.log_handler import get_logger
from cartoview.store_api.api import StoreAppResource, StoreAppVersion

from ..apps_handler.req_installer import (ReqFileException,
ReqFilePermissionException,
ReqInstaller)
from .decorators import restart_enabled, rollback_on_failure
from .exceptions import AppAlreadyInstalledException
from .models import App, AppStore, AppType
from .req_installer import ReqInstaller

logger = get_logger(__name__)
install_app_batch = getattr(settings, 'INSTALL_APP_BAT', None)
Expand Down Expand Up @@ -118,10 +120,6 @@ def get_property_value(self, p):
return getattr(self, p, None)


class AppAlreadyInstalledException(BaseException):
message = "Application is already installed."


class AppInstaller(object):
def __init__(self, name, store_id=None, version=None, user=None):
self.user = user
Expand Down Expand Up @@ -179,14 +177,20 @@ def _request_rest_data(self, *args):
@rollback_on_failure
def extract_move_app(self, zipped_app):
extract_to = tempfile.mkdtemp()
libs_dir = None
zipped_app.extractall(extract_to)
if self.upgrade and os.path.exists(self.app_dir):
# move old version to temporary dir so that we can restore in
# case of failure
old_version_temp_dir = tempfile.mkdtemp()
shutil.move(self.app_dir, old_version_temp_dir)
self.old_app_temp_dir = os.path.join(extract_to, self.name)
shutil.move(self.old_app_temp_dir, settings.APPS_DIR)
old_lib_dir = os.path.join(old_version_temp_dir, 'libs')
if os.path.isdir(old_lib_dir) and os.path.exists(old_lib_dir):
libs_dir = old_lib_dir
self.new_app_dir = os.path.join(extract_to, self.name)
shutil.move(self.new_app_dir, settings.APPS_DIR)
if libs_dir:
shutil.copy(libs_dir, self.app_dir)
# delete temp extract dir
shutil.rmtree(extract_to)

Expand Down Expand Up @@ -245,7 +249,6 @@ def _rollback(self):
CartoApps.delete_app(self.name)
self.delete_app_dir()

@rollback_on_failure
def install(self, restart=True):
with lock:
self.upgrade = False
Expand Down Expand Up @@ -277,12 +280,14 @@ def install(self, restart=True):

@rollback_on_failure
def _install_requirements(self):
# TODO:add requirement file name as settings var
req_file = os.path.join(self.app_dir, "req.txt")
libs_dir = os.path.join(self.app_dir, "libs")
if os.path.exists(req_file) and access(req_file, R_OK):
req_installer = ReqInstaller(req_file, target=libs_dir)
try:
libs_dir = os.path.join(self.app_dir, 'libs')
req_installer = ReqInstaller(self.app_dir, target=libs_dir)
req_installer.install_all()
except BaseException as e:
if not (isinstance(e, ReqFileException) or
isinstance(e, ReqFilePermissionException)):
raise e

@rollback_on_failure
def check_then_finlize(self, restart, installed_apps):
Expand Down Expand Up @@ -355,8 +360,11 @@ def uninstall(self, restart=True):
if app_installer.version else {}
if self.name in dependencies.keys():
app_installer.uninstall(restart=False)
installer = importlib.import_module('%s.installer' % self.name)
installer.uninstall()
try:
installer = importlib.import_module('%s.installer' % self.name)
installer.uninstall()
except ImportError as e:
logger.error(e.message)
self.completely_remove()
uninstalled = True
if restart:
Expand Down
10 changes: 8 additions & 2 deletions cartoview/app_manager/management/commands/install_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import print_function

from django.core.management.base import BaseCommand
from pkg_resources import parse_version

from cartoview.app_manager.installer import AppInstaller
from cartoview.app_manager.models import App, AppStore
Expand All @@ -10,6 +11,10 @@
logger = get_logger(__name__)


def compare_version(v1, v2):
return parse_version(v1) < parse_version(v2)


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

Expand All @@ -29,8 +34,9 @@ def handle(self, *args, **options):
store = AppStore.objects.get(is_default=True)
q = App.objects.filter(name=app_name)
try:
if q.count() == 0 or (q.first()
and q.first().version < app_version):
if q.count() == 0 or (q.first() and
compare_version(q.first().version,
app_version)):
installer = AppInstaller(app_name, store.id, app_version)
installer.install()
except Exception as ex:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import requests
from cartoview.app_manager.installer import AppJson, remove_unwanted
from cartoview.app_manager.models import App
Expand Down
28 changes: 28 additions & 0 deletions cartoview/app_manager/migrations/0010_auto_20181118_1333.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-18 13:33
from __future__ import unicode_literals

from django.db import migrations
import django.db.models.manager


class Migration(migrations.Migration):

dependencies = [
('app_manager', '0009_auto_20180920_1659'),
]

operations = [
migrations.AlterModelManagers(
name='appinstance',
managers=[
('objects', django.db.models.manager.Manager()),
('base_objects', django.db.models.manager.Manager()),
],
),
migrations.RenameField(
model_name='appinstance',
old_name='map',
new_name='related_map',
),
]
Loading

0 comments on commit 834f06f

Please sign in to comment.