def load_apps_urls(): with apps_orm.session() as session: carto_apps = session.query(CartoApps).filter( CartoApps.active == True).all() # noqa for carto_app in carto_apps: import_app_rest(carto_app.name) urlpatterns.append(app_url(carto_app.name))
def add_carto_app(self): with apps_orm.session() as session: if not CartoApps.app_exists(self.name): carto_app = CartoApps(name=self.name, active=True, order=self.get_app_order(), pending=True) session.add(carto_app) session.commit() else: carto_app = session.query(CartoApps).filter( CartoApps.name == self.name).update({"pending": True}) session.commit()
def handle(self, *args, **options): with apps_orm.session() as session: carto_apps = session.query(CartoApps).filter( CartoApps.active == True).all() # noqa user = Profile.objects.filter(is_superuser=True).first() for carto_app in carto_apps: app_name = carto_app.name query = App.objects.filter(name=app_name) if 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, order=carto_app.order, single_instance=False) single = False try: installer = importlib.import_module('%s.installer' % app_name) single = getattr(installer.info, 'single_instance', False) except BaseException: logger.error( ('%-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() logger.info('%-15s loaded Successfully' % (app_name)) except Exception as e: logger.error(('Failed to load %-5s may be ' + 'app folder not found error: %-10s') % (app_name, e.message))
def execute_pending(self): with apps_orm.session() as session: pending_apps = session.query(CartoApps).filter( CartoApps.pending == True).all() # noqa for app in pending_apps: try: if not settings.DEBUG: call_command("collectstatic", interactive=False, ignore=['node_modules', '.git']) call_command("migrate", app.name, interactive=False) CartoApps.set_app_pending(app.name, False) except CommandError as e: error = e.message logger.error(error) if "you cannot selectively sync unmigrated apps"\ not in error: self.delete_application_on_fail(app.name)
def load_apps(APPS_DIR): global CARTOVIEW_APPS global APPS_SETTINGS 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) logger.info("Loading Cartoview Apps.....") with apps_orm.session() as session: carto_apps = session.query(CartoApps).filter( CartoApps.active == True).all() for app in carto_apps: try: logger.info("Check if {} Healthy.\n".format(app.name)) # ensure that the folder is python module app_module = importlib.import_module(app.name) app_dir = os.path.dirname(app_module.__file__) app_settings_file = os.path.join(app_dir, 'settings.py') libs_dir = os.path.join(app_dir, 'libs') 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. app_settings_file = os.path.realpath(app_settings_file) APPS_SETTINGS += (app_settings_file, ) # execfile(app_settings_file) if os.path.exists(libs_dir) and libs_dir not in sys.path: logger.info("Install {} libs folder to the system.\n".format( app.name)) sys.path.append(libs_dir) logger.info("add {} to INSTALLED_APPS.\n".format(app.name)) if app.name not in CARTOVIEW_APPS: # app_config.name.__str__() because Django don't like # unicode_literals CARTOVIEW_APPS += (app.name.__str__(), ) except Exception as e: print(e.message) logger.error(e.message)