subdirectory support for ServiceControllerResource (WIP)
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index c871c7e..dc8e5ae 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -102,6 +102,7 @@
                                 help_text="The Service Controller this resource is associated with")
 
     name = StrippedCharField(max_length=30, help_text="Object Name")
+    subdirectory = StrippedCharField(max_length=1024, help_text="optional subdirectory", null=True, blank=True)
     kind = StrippedCharField(choices=KIND_CHOICES, max_length=30)
     format = StrippedCharField(choices=FORMAT_CHOICES, max_length=30)
     url = StrippedCharField(max_length=1024, help_text="URL of resource", null=True, blank=True)
diff --git a/xos/synchronizers/onboarding/xosbuilder.py b/xos/synchronizers/onboarding/xosbuilder.py
index ffb66ee..4fa05f2 100644
--- a/xos/synchronizers/onboarding/xosbuilder.py
+++ b/xos/synchronizers/onboarding/xosbuilder.py
@@ -38,7 +38,12 @@
                      "rest_tenant": "%s/api/tenant/" % (xos_base),
                      "private_key": "%s/services/%s/keys" % (xos_base, service_name),
                      "public_key": "%s/services/%s/keys/" % (xos_base, service_name)}
-        return base_dirs[scr.kind]
+        dest_dir = base_dirs[scr.kind]
+
+        if scr.subdirectory:
+            dest_dir = os.path.join(dest_dir, scr.subdirectory)
+
+        return dest_dir
 
     def get_build_fn(self, scr):
         dest_dir = self.get_dest_dir(scr)
diff --git a/xos/tosca/resources/servicecontroller.py b/xos/tosca/resources/servicecontroller.py
index d821b56..fd603c3 100644
--- a/xos/tosca/resources/servicecontroller.py
+++ b/xos/tosca/resources/servicecontroller.py
@@ -19,21 +19,37 @@
         if values:
             for i,value in enumerate(values.split(",")):
                 value = value.strip()
+                subdirectory = None
 
                 name=kind
                 if i>0:
                     name = "%s_%d" %( name, i)
 
+                if (" " in value):
+                    parts=value.split():
+                    for part in parts[:-1]:
+                       if ":" in part:
+                           (lhs, rhs) = part.split(1)
+                           if lhs=="subdirectory":
+                               subdirectory=rhs
+                           else:
+                               raise Exception("Malformed value %s" % value)
+                       else:
+                           raise Exception("Malformed value %s" % value)
+                    value = parts[-1]
+
+
                 scr = ServiceControllerResource.objects.filter(service_controller=obj, name=name, kind=kind, format=format)
                 if scr:
                     scr=scr[0]
-                    if scr.url != value:
+                    if (scr.url != value) or (scr.subdirectory!=subdirectory):
                         self.info("updating resource %s" % kind)
                         scr.url = value
+                        scr.subdirectory = subdirectory
                         scr.save()
                 else:
                     self.info("adding resource %s" % kind)
-                    scr = ServiceControllerResource(service_controller=obj, name=name, kind=kind, format=format, url=value)
+                    scr = ServiceControllerResource(service_controller=obj, name=name, kind=kind, format=format, url=value, subdirectory=subdirectory)
                     scr.save()
 
     def postprocess(self, obj):