fix missing __init__ file; cleanup DOS newlines
Change-Id: I6934be3efa063a226049bdf133da97fb361de42e
diff --git a/xos/tools/corebuilder/corebuilder.py b/xos/tools/corebuilder/corebuilder.py
index 01ea525..ac99b01 100644
--- a/xos/tools/corebuilder/corebuilder.py
+++ b/xos/tools/corebuilder/corebuilder.py
@@ -45,13 +45,13 @@
import argparse
import os
-import pdb
-import shutil
-import sys
-import tempfile
-import traceback
-import urlparse
-
+import pdb
+import shutil
+import sys
+import tempfile
+import traceback
+import urlparse
+
from toscaparser.tosca_template import ToscaTemplate
BUILD_DIR = "/opt/xos_corebuilder/BUILD"
@@ -81,9 +81,9 @@
class XOSCoreBuilder(object):
def __init__(self, recipe_list, parent_dir=None):
# TOSCA will look for imports using a relative path from where the
- # template file is located, so we have to put the template file
- # in a specific place.
- if not parent_dir:
+ # template file is located, so we have to put the template file
+ # in a specific place.
+ if not parent_dir:
parent_dir = os.getcwd()
self.parent_dir = parent_dir
@@ -155,68 +155,68 @@
def execute_recipe(self, tosca_yaml):
tmp_pathname = None
- try:
- (tmp_handle, tmp_pathname) = tempfile.mkstemp(dir=self.parent_dir, suffix=".yaml")
- os.write(tmp_handle, tosca_yaml)
- os.close(tmp_handle)
-
- template = ToscaTemplate(tmp_pathname)
- except:
- traceback.print_exc()
- raise
- finally:
- if tmp_pathname:
- os.remove(tmp_pathname)
-
- # Only one model (ServiceController aka Library), so no need to sort
- # dependencies...
-
- for nodetemplate in template.nodetemplates:
- self.execute_nodetemplate(nodetemplate)
-
- def execute_nodetemplate(self, nodetemplate):
- if nodetemplate.type == "tosca.nodes.ServiceController":
- self.execute_servicecontroller(nodetemplate)
- elif nodetemplate.type == "tosca.nodes.Library":
- # Library works just like ServiceController
- self.execute_servicecontroller(nodetemplate)
- else:
- raise CoreBuilderUnknownResourceException("Nodetemplate %s's type %s is not a known resource" % (nodetemplate.name, nodetemplate.type))
-
- def execute_servicecontroller(self, nodetemplate):
- service_name = nodetemplate.name
- if "#" in service_name:
- service_name = service_name.split("#")[1]
-
- base = self.get_property_default(nodetemplate, "base_url", None)
-
- copyin_resources = ("xproto", "models", "admin", "admin_template", "django_library", "tosca_custom_types", "tosca_resource",
- "rest_service", "rest_tenant", "private_key", "public_key", "vendor_js")
-
- for k in copyin_resources:
- v = self.get_property_default(nodetemplate, k, None)
- if not v:
- continue
-
- # Private keys should not be installed to core, only synchronizers
- if (k=="private_key"):
- continue
-
- # Public keys should be volume mounted in /opt/cord_profile
- if (k=="public_key"):
- continue
-
- # If the ServiceController has models, then add it to the list of
- # django apps.
- if (k in ["models","xproto"] and service_name!="core"):
- self.app_names.append(service_name)
-
- # filenames can be comma-separated
- for src_fn in v.split(","):
- src_fn = src_fn.strip()
-
- # parse the "subdirectory:name" syntax
- subdirectory = ""
+ try:
+ (tmp_handle, tmp_pathname) = tempfile.mkstemp(dir=self.parent_dir, suffix=".yaml")
+ os.write(tmp_handle, tosca_yaml)
+ os.close(tmp_handle)
+
+ template = ToscaTemplate(tmp_pathname)
+ except:
+ traceback.print_exc()
+ raise
+ finally:
+ if tmp_pathname:
+ os.remove(tmp_pathname)
+
+ # Only one model (ServiceController aka Library), so no need to sort
+ # dependencies...
+
+ for nodetemplate in template.nodetemplates:
+ self.execute_nodetemplate(nodetemplate)
+
+ def execute_nodetemplate(self, nodetemplate):
+ if nodetemplate.type == "tosca.nodes.ServiceController":
+ self.execute_servicecontroller(nodetemplate)
+ elif nodetemplate.type == "tosca.nodes.Library":
+ # Library works just like ServiceController
+ self.execute_servicecontroller(nodetemplate)
+ else:
+ raise CoreBuilderUnknownResourceException("Nodetemplate %s's type %s is not a known resource" % (nodetemplate.name, nodetemplate.type))
+
+ def execute_servicecontroller(self, nodetemplate):
+ service_name = nodetemplate.name
+ if "#" in service_name:
+ service_name = service_name.split("#")[1]
+
+ base = self.get_property_default(nodetemplate, "base_url", None)
+
+ copyin_resources = ("xproto", "models", "admin", "admin_template", "django_library", "tosca_custom_types", "tosca_resource",
+ "rest_service", "rest_tenant", "private_key", "public_key", "vendor_js")
+
+ for k in copyin_resources:
+ v = self.get_property_default(nodetemplate, k, None)
+ if not v:
+ continue
+
+ # Private keys should not be installed to core, only synchronizers
+ if (k=="private_key"):
+ continue
+
+ # Public keys should be volume mounted in /opt/cord_profile
+ if (k=="public_key"):
+ continue
+
+ # If the ServiceController has models, then add it to the list of
+ # django apps.
+ if (k in ["models","xproto"] and service_name!="core"):
+ self.app_names.append(service_name)
+
+ # filenames can be comma-separated
+ for src_fn in v.split(","):
+ src_fn = src_fn.strip()
+
+ # parse the "subdirectory:name" syntax
+ subdirectory = ""
if (" " in src_fn):
parts=src_fn.split()
for part in parts[:-1]:
@@ -228,57 +228,59 @@
raise CoreBuilderMalformedValueException("Malformed value %s in resource %s of recipe %s" % (v, k, nodetemplate.name))
else:
raise CoreBuilderMalformedValueException("Malformed value %s in resource %s of recipe %s" % (v, k, nodetemplate.name))
- src_fn = parts[-1]
-
- # apply base_url to src_fn
- if base:
- src_fn = urlparse.urljoin(base, src_fn)
-
- # ensure that it's a file:// url
- if not src_fn.startswith("file://"):
- raise CoreBuilderMalformedUrlException("Resource `%s: %s` of recipe %s does not start with file://" % (k, src_fn, nodetemplate.name))
- src_fn = src_fn[7:]
-
- src_fn = self.fixup_path(src_fn)
-
- if not os.path.exists(src_fn):
- raise CoreBuilderMissingResourceException("Resource '%s: %s' of recipe %s does not exist" % (k, src_fn, nodetemplate.name))
-
- dest_dir = self.get_dest_dir(k, service_name)
- dest_fn = os.path.join(dest_dir, subdirectory, os.path.basename(src_fn))
-
- self.resources.append( (k, src_fn, dest_fn, service_name) )
-
- # add __init__.py files anywhere that we created a new
- # directory.
- if k in ["admin", "models", "rest_service", "rest_tenant"]:
- if dest_dir not in self.inits:
- self.inits.append(dest_dir)
-
- if subdirectory:
- dir = dest_dir
- for part in subdirectory.split("/"):
- dir = os.path.join(dir, part)
- if dir not in self.inits:
- self.inits.append(dir)
-
- def build(self):
- # Destroy anything in the old build directory
- if os.path.exists(BUILD_DIR):
- for dir in os.listdir(BUILD_DIR):
- shutil.rmtree(os.path.join(BUILD_DIR, dir))
-
- # Copy all of the resources into the build directory
- for (kind, src_fn, dest_fn, service_name) in self.resources:
- build_dest_fn = os.path.join(BUILD_DIR, dest_fn)
- makedirs_if_noexist(os.path.dirname(build_dest_fn))
+ src_fn = parts[-1]
+
+ # apply base_url to src_fn
+ if base:
+ src_fn = urlparse.urljoin(base, src_fn)
+
+ # ensure that it's a file:// url
+ if not src_fn.startswith("file://"):
+ raise CoreBuilderMalformedUrlException("Resource `%s: %s` of recipe %s does not start with file://" % (k, src_fn, nodetemplate.name))
+ src_fn = src_fn[7:]
+
+ src_fn = self.fixup_path(src_fn)
+
+ if not os.path.exists(src_fn):
+ raise CoreBuilderMissingResourceException("Resource '%s: %s' of recipe %s does not exist" % (k, src_fn, nodetemplate.name))
+
+ dest_dir = self.get_dest_dir(k, service_name)
+ dest_fn = os.path.join(dest_dir, subdirectory, os.path.basename(src_fn))
+
+ self.resources.append( (k, src_fn, dest_fn, service_name) )
+
+ # Add __init__.py files anywhere that we created a new
+ # directory.
+ # NOTE: omitting core, out of concern it could interfere with
+ # core's __init__.py file.
+ if ((k in ["admin", "models", "rest_service", "rest_tenant", "xproto"]) and (service_name!="core")):
+ if dest_dir not in self.inits:
+ self.inits.append(dest_dir)
+
+ if subdirectory:
+ dir = dest_dir
+ for part in subdirectory.split("/"):
+ dir = os.path.join(dir, part)
+ if dir not in self.inits:
+ self.inits.append(dir)
+
+ def build(self):
+ # Destroy anything in the old build directory
+ if os.path.exists(BUILD_DIR):
+ for dir in os.listdir(BUILD_DIR):
+ shutil.rmtree(os.path.join(BUILD_DIR, dir))
+
+ # Copy all of the resources into the build directory
+ for (kind, src_fn, dest_fn, service_name) in self.resources:
+ build_dest_fn = os.path.join(BUILD_DIR, dest_fn)
+ makedirs_if_noexist(os.path.dirname(build_dest_fn))
if (os.path.isdir(src_fn)):
if (not os.path.isdir(build_dest_fn)):
shutil.copytree(src_fn, build_dest_fn, symlinks=True)
else:
os.system('cp -R %s/*.xproto %s/attic %s/*header.py %s'%(src_fn, src_fn, src_fn, build_dest_fn))
else:
- shutil.copyfile(src_fn, build_dest_fn)
+ shutil.copyfile(src_fn, build_dest_fn)
if (kind=='xproto'):
# Invoke xproto toolchain in the destination directory
@@ -297,24 +299,24 @@
if (os.system('make -C %s -f %s PREFIX=%s'%(build_dest_fn, makefile_name, xosgen_path))):
raise Exception('xproto build failed!')
-
- # Create the __init__.py files
- for fn in self.inits:
- build_dest_fn = os.path.join(BUILD_DIR, fn, "__init__.py")
- makedirs_if_noexist(os.path.dirname(build_dest_fn))
- file(build_dest_fn, "w").write("")
-
- # Generate the migration list
- mig_list_fn = os.path.join(BUILD_DIR, "opt/xos/xos", "xosbuilder_migration_list")
- makedirs_if_noexist(os.path.dirname(mig_list_fn))
- file(mig_list_fn, "w").write("\n".join(self.app_names)+"\n")
-
- # Generate the app list
- app_list_fn = os.path.join(BUILD_DIR, "opt/xos/xos", "xosbuilder_app_list")
- makedirs_if_noexist(os.path.dirname(app_list_fn))
- file(app_list_fn, "w").write("\n".join(["services.%s" % x for x in self.app_names])+"\n")
-
-def parse_args():
+
+ # Create the __init__.py files
+ for fn in self.inits:
+ build_dest_fn = os.path.join(BUILD_DIR, fn, "__init__.py")
+ makedirs_if_noexist(os.path.dirname(build_dest_fn))
+ file(build_dest_fn, "w").write("")
+
+ # Generate the migration list
+ mig_list_fn = os.path.join(BUILD_DIR, "opt/xos/xos", "xosbuilder_migration_list")
+ makedirs_if_noexist(os.path.dirname(mig_list_fn))
+ file(mig_list_fn, "w").write("\n".join(self.app_names)+"\n")
+
+ # Generate the app list
+ app_list_fn = os.path.join(BUILD_DIR, "opt/xos/xos", "xosbuilder_app_list")
+ makedirs_if_noexist(os.path.dirname(app_list_fn))
+ file(app_list_fn, "w").write("\n".join(["services.%s" % x for x in self.app_names])+"\n")
+
+def parse_args():
parser = argparse.ArgumentParser()
_help = 'enable verbose logging'
@@ -333,29 +335,29 @@
args = parser.parse_args()
return args
-
-def main():
- global options
-
- options = parse_args()
-
- try:
- builder = XOSCoreBuilder(options.recipe_names)
- builder.build()
- except CoreBuilderException, e:
- if options.verbose:
- traceback.print_exc()
- else:
- print >> sys.stderr, "Error:", str(e)
- sys.exit(-1)
-
-if __name__ == "__main__":
- main()
-
-
-
-
-
-
+def main():
+ global options
+
+ options = parse_args()
+
+ try:
+ builder = XOSCoreBuilder(options.recipe_names)
+ builder.build()
+ except CoreBuilderException, e:
+ if options.verbose:
+ traceback.print_exc()
+ else:
+ print >> sys.stderr, "Error:", str(e)
+ sys.exit(-1)
+
+if __name__ == "__main__":
+ main()
+
+
+
+
+
+
+