Commit e3dcc489 authored by Anze Vavpetic's avatar Anze Vavpetic

added support for including external clowdflows packages (e.g., installable using pip)

parent 406ea607
......@@ -43,7 +43,12 @@ INSTALLED_APPS_WORKFLOWS_SUB = (
#'workflows.vipercharts',
#'workflows.MUSE',
#'workflows.hbp',
)
)
INSTALLED_APPS_EXTERNAL_PACKAGES = (
#'rdm.db',
#'rdm.wrappers'
)
BROKER_URL = 'django://'
......
......@@ -178,6 +178,7 @@ INSTALLED_APPS_DEFAULT = (
)
INSTALLED_APPS_WORKFLOWS_SUB = ()
INSTALLED_APPS_EXTERNAL_PACKAGES = ()
TEST_RUNNER = 'discover_runner.DiscoverRunner'
......@@ -225,4 +226,5 @@ except NameError:
INSTALLED_APPS = \
INSTALLED_APPS_DEFAULT +\
INSTALLED_APPS_WORKFLOWS_SUB
INSTALLED_APPS_WORKFLOWS_SUB +\
INSTALLED_APPS_EXTERNAL_PACKAGES
......@@ -72,8 +72,10 @@ def serialize_category(c):
return data
def export_package(package_name,writer):
style = color_style()
if package_name in settings.INSTALLED_APPS_EXTERNAL_PACKAGES:
raise CommandError("You cannot export external packages.")
if 'workflows.'+package_name not in settings.INSTALLED_APPS:
raise CommandError("Package not found in INSTALLED_APPS.")
......
......@@ -16,11 +16,19 @@ class Command(BaseCommand):
def handle(self, *args, **options):
packages = []
extern_packages = []
for app in settings.INSTALLED_APPS:
if 'workflows.' in app:
packages.append(app)
package_name = app.split('workflows.')[1]
packages.append(package_name)
elif app in settings.INSTALLED_APPS_EXTERNAL_PACKAGES:
print app
extern_packages.append(app)
for package in packages:
package_name = package.split('workflows.')[1]
self.stdout.write("Importing package "+package_name+"\n")
import_package(package_name,self.stdout)
\ No newline at end of file
self.stdout.write("Importing package "+package+"\n")
import_package(package,self.stdout)
for package in extern_packages:
self.stdout.write("Importing external package "+package+"\n")
import_package(package,self.stdout, external=True)
......@@ -6,6 +6,7 @@ from optparse import make_option
import uuid
import os
import sys
import inspect
from django.conf import settings
import json
from .export_package import serialize_category, serialize_widget
......@@ -29,9 +30,16 @@ def parsewidgetdata(widget_data):
raise CommandError("Wrong data in widget files!")
return widget, inputs, outputs, options
def import_package(package_name,writer):
def import_package(package_name,writer,external=False):
style = color_style()
package_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),'../../'+package_name+"/package_data/")
if external:
module = __import__(package_name)
if '.' in package_name:
cf_module = package_name.split('.')[-1]
module = getattr(module, cf_module)
package_directory = os.path.join(os.path.dirname(inspect.getfile(module)), 'package_data/')
else:
package_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),'../../'+package_name+"/package_data/")
widgets_directory = os.path.join(package_directory,"widgets")
deprecated_widgets_directory = os.path.join(package_directory,"deprecated_widgets")
categories_directory = os.path.join(package_directory,"categories")
......@@ -193,12 +201,13 @@ class Command(BaseCommand):
raise CommandError('Argument "package_name" is required.')
package_name = args[0]
external = package_name in settings.INSTALLED_APPS_EXTERNAL_PACKAGES
if 'workflows.'+package_name not in settings.INSTALLED_APPS:
if 'workflows.'+package_name not in settings.INSTALLED_APPS and not external:
raise CommandError("Package not found in INSTALLED_APPS.")
writer = self.stdout
import_package(package_name,writer)
import_package(package_name,writer,external=external)
writer.write('Thanks for using the new import command. You rock.\n')
from mothra.settings import INSTALLED_APPS
from mothra.settings import INSTALLED_APPS, INSTALLED_APPS_EXTERNAL_PACKAGES
appName = 'workflows'
def get_installed_apps():
return list(get_local_installed_apps()) + list(get_extern_installed_apps())
def get_local_installed_apps():
return [name[len(appName)+1:] for name in INSTALLED_APPS if name.startswith(appName+'.') and len(name)>len(appName)+1]
def get_extern_installed_apps():
return INSTALLED_APPS_EXTERNAL_PACKAGES
#Following functions deal with imports of libraries as dicts
def import_all_packages_libs_as_dict(libName):
pckLibs = {}
......@@ -13,7 +19,10 @@ def import_all_packages_libs_as_dict(libName):
return pckLibs
def import_package_lib_as_dict(packageName, libName):
return dynamic_import_globals_as_dict(appName+"."+packageName + "." + libName, packageName)
if packageName in get_local_installed_apps():
return dynamic_import_globals_as_dict(appName+"."+packageName + "." + libName, packageName)
else:
return dynamic_import_globals_as_dict(packageName + "." + libName, packageName)
def dynamic_import_globals_as_dict(name, package):
try:
......@@ -30,7 +39,11 @@ def import_all_packages_libs(libName, localSetAttrFunc):
import_package_lib(pck, libName, localSetAttrFunc)
def import_package_lib(packageName, libName, localSetAttrFunc):
dynamic_import_globals(appName+"."+packageName + "." + libName, packageName, localSetAttrFunc)
if packageName in get_local_installed_apps():
dynamic_import_globals(appName+"."+packageName + "." + libName, packageName, localSetAttrFunc)
else:
# External CF package
dynamic_import_globals(packageName + "." + libName, packageName, localSetAttrFunc)
def dynamic_import_globals(name, package, localSetAttrFunc):
m = None
......@@ -49,5 +62,4 @@ def dynamic_import_globals(name, package, localSetAttrFunc):
g = globals()
for name in all_names:
#g[name] = m.__dict__.get(name)
#print name
localSetAttrFunc(name, m.__dict__.get(name), package)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment