diff --git a/giftwrap/build_spec.py b/giftwrap/build_spec.py new file mode 100644 index 0000000..b77ac07 --- /dev/null +++ b/giftwrap/build_spec.py @@ -0,0 +1,42 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2014, Craig Tracey +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations + +import yaml + +DEFAULT_PROJECT_PATH = '/opt/openstack' + + +class BuildSpec(object): + + def __init__(self, manifest): + self._spec = yaml.load(manifest) + self._project_path = None + self._projects = None + + @property + def project_path(self): + if not self._project_path: + if 'project_path' in self._spec.keys(): + self._project_path = self._spec['project_path'] + else: + self._project_path = DEFAULT_PROJECT_PATH + return self._project_path + + @property + def projects(self): + if 'projects' in self._spec.keys() and not self._projects: + self._projects = self._spec['projects'] + return self._projects diff --git a/giftwrap/builder.py b/giftwrap/builder.py new file mode 100644 index 0000000..ff81a11 --- /dev/null +++ b/giftwrap/builder.py @@ -0,0 +1,35 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2014, Craig Tracey +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations + +import os +import sys + +from giftwrap.shell import LOG + + +class Builder(object): + + def __init__(self, spec): + self._spec = spec + + def build(self): + """ this is where all the magic happens """ + + try: + os.makedirs(self._spec.project_path) + except Exception as e: + LOG.fatal("Oops. Something went wrong. Error was:\n%s", e) + sys.exit(-1) diff --git a/giftwrap/shell.py b/giftwrap/shell.py new file mode 100644 index 0000000..bf966f3 --- /dev/null +++ b/giftwrap/shell.py @@ -0,0 +1,65 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2014, Craig Tracey +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations + +import argparse +import logging +import sys + +from giftwrap.build_spec import BuildSpec + +LOG = logging.getLogger(__name__) +log_handler = logging.StreamHandler() +LOG.addHandler(log_handler) + +from giftwrap.builder import Builder + + +def build(args): + """ the entry point for all build subcommand tasks """ + if not args.manifest: + LOG.fatal("build command requires a manifest") + sys.exit(-1) + + try: + manifest = None + with open(args.manifest, 'r') as fh: + manifest = fh.read() + buildspec = BuildSpec(manifest) + builder = Builder(buildspec) + builder.build() + except Exception as e: + LOG.fatal("Unable to parse manifest %s. Error: %s", args.manifest, e) + sys.exit(-1) + + +def main(): + """ the entry point for all things giftwrap """ + parser = argparse.ArgumentParser() + + subparsers = parser.add_subparsers(title='subcommands', + description='valid subcommands', + help='additional help') + build_subcmd = subparsers.add_parser('build', + description='build giftwrap packages') + build_subcmd.add_argument('-m', '--manifest') + build_subcmd.set_defaults(func=build) + + args = parser.parse_args() + args.func(args) + + +if __name__ == '__main__': + main() diff --git a/sample.yml b/sample.yml new file mode 100644 index 0000000..66a6626 --- /dev/null +++ b/sample.yml @@ -0,0 +1,9 @@ +--- +package_path: '/opt/openstack/' + +projects: + - name: nova + url: https://github.com/openstack/nova + + - name: keystone + url: https://github.com/openstack/keystone diff --git a/setup.cfg b/setup.cfg index 8057092..ca2f25d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,9 +18,9 @@ classifier = setup-hooks = pbr.hooks.setup_hook -# [entry_points] -# console_scripts = -# giftwrap = giftwrap.shell:main +[entry_points] +console_scripts = + giftwrap = giftwrap.shell:main [files] packages =