예제 #1
0
def load_apps(APPS_DIR):
    create_apps_dir(APPS_DIR)
    if APPS_DIR not in sys.path:
        sys.path.append(APPS_DIR)
    apps_file_path = os.path.join(APPS_DIR, "apps.yml")
    apps_config = AppsConfig(apps_file_path)
    CARTOVIEW_APPS = ()
    for app_config in apps_config:
        if app_config.active:
            try:
                # ensure that the folder is python module
                app_module = importlib.import_module(app_config.name)
                app_dir = os.path.dirname(app_module.__file__)
                app_settings_file = os.path.join(app_dir, 'settings.py')
                if os.path.exists(app_settings_file):
                    # By doing this instead of import, app/settings.py can
                    # refer to local variables from settings.py without
                    # circular imports.
                    execfile(app_settings_file)
                if app_config.name not in CARTOVIEW_APPS:
                    # app_config.name.__str__() because Django don't like
                    # unicode_literals
                    CARTOVIEW_APPS += (app_config.name.__str__(), )
            except Exception as e:
                print(e.message)
                logger.error(e.message)

    return CARTOVIEW_APPS
예제 #2
0
 def handle(self, *args, **options):
     apps_file_path = os.path.join(settings.APPS_DIR, "apps.yml")
     apps_config = AppsConfig(apps_file_path)
     user = Profile.objects.filter(is_superuser=True).first()
     for app_config in apps_config:
         app_name = app_config.name
         query = App.objects.filter(name=app_name)
         if app_config.active and query.count() == 0:
             try:
                 # ensure that the folder is python module
                 importlib.import_module(app_name)
                 app = App(title=app_name, name=app_name, status="Alpha", license=None,
                           version='1.0.0', installed_by=user, store=None, single_instance=False)
                 single = False
                 try:
                     installer = importlib.import_module(
                         '%s.installer' % app_name)
                     single = installer.info.get('single_instance', False)
                 except:
                     print(
                         '%-15s installer.py not found so this app will be marked as Multiple Instance' % (app_name))
                 app.single_instance = single
                 app.save()
                 category, created = AppType.objects.get_or_create(
                     name='app_manager_loader')
                 
                 app.category.add(category)
                 app.tags.add(*['cartoview', ])
                 app.save()
                 print('%-15s loaded Successfully' % (app_name))
             except Exception as e:
                 print('Failed to load %-5s may be app folder not found error: %-10s' %
                       (app_name, e.message))
예제 #3
0
    '[%(asctime)s] p%(process)s  { %(name)s %(pathname)s:%(lineno)d} \
                            %(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
# BASE_DIR must be defined in project.settings
APPS_DIR = os.path.abspath(os.path.join(BASE_DIR, "apps"))
if not os.path.exists(APPS_DIR):
    os.makedirs(APPS_DIR)
if APPS_DIR not in sys.path:
    sys.path.append(APPS_DIR)

apps_file_path = os.path.join(APPS_DIR, "apps.yml")
PENDING_APPS = os.path.join(APPS_DIR, "pendingOperation.yml")
apps_config = AppsConfig(apps_file_path)
CARTOVIEW_APPS = ()
for app_config in apps_config:
    if app_config.active:
        try:
            # ensure that the folder is python module
            app_module = importlib.import_module(app_config.name)
            app_dir = os.path.dirname(app_module.__file__)
            app_settings_file = os.path.join(app_dir, 'settings.py')
            if os.path.exists(app_settings_file):
                # By doing this instead of import, app/settings.py can refer to
                # local variables from settings.py without circular imports.
                execfile(app_settings_file)
            if app_config.name not in CARTOVIEW_APPS:
                # app_config.name.__str__() because Django don't like unicode_literals
                CARTOVIEW_APPS += (app_config.name.__str__(), )