Add a basic framework for giftwrap
Start to flesh this thing out a bit. This commit adds a CLI as well as some of the builder and builder_spec classes. This is obviously meant to be a beginning to something - not a full feature.
This commit is contained in:
parent
a72767d7f1
commit
a02c6013ee
|
@ -0,0 +1,42 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014, Craig Tracey <craigtracey@gmail.com>
|
||||
# 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
|
|
@ -0,0 +1,35 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014, Craig Tracey <craigtracey@gmail.com>
|
||||
# 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)
|
|
@ -0,0 +1,65 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014, Craig Tracey <craigtracey@gmail.com>
|
||||
# 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()
|
|
@ -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
|
Loading…
Reference in New Issue