$search
00001 # Software License Agreement (BSD License) 00002 # 00003 # Copyright (c) 2009, Willow Garage, Inc. 00004 # All rights reserved. 00005 # 00006 # Redistribution and use in source and binary forms, with or without 00007 # modification, are permitted provided that the following conditions 00008 # are met: 00009 # 00010 # * Redistributions of source code must retain the above copyright 00011 # notice, this list of conditions and the following disclaimer. 00012 # * Redistributions in binary form must reproduce the above 00013 # copyright notice, this list of conditions and the following 00014 # disclaimer in the documentation and/or other materials provided 00015 # with the distribution. 00016 # * Neither the name of Willow Garage, Inc. nor the names of its 00017 # contributors may be used to endorse or promote products derived 00018 # from this software without specific prior written permission. 00019 # 00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 # POSSIBILITY OF SUCH DAMAGE. 00032 # 00033 # Revision $Id: package_header.py 11472 2010-10-12 02:08:53Z kwc $ 00034 # $Author: kwc $ 00035 00036 import os 00037 import sys 00038 import codecs 00039 import traceback 00040 00041 import yaml 00042 00043 from .core import Repo 00044 00045 def generate_repo_header(ctx, repo, stack_files, package_files): 00046 """ 00047 Generate repo.yaml files for MoinMoin Repo macros 00048 00049 @param stack_files: list of stack.yaml files related to this repo 00050 @return: list of generate files (a single repo.yaml file) 00051 @rtype: [str] 00052 """ 00053 if repo.name is None: 00054 sys.stderr.write("Invalid repo file (repo.name is None), ignoring\n") 00055 return [] 00056 00057 repo_data = { 00058 'name': repo.name, 00059 'vcs': { 00060 'type': repo.type, 00061 'uri': repo.uri, 00062 }, 00063 'stacks': {}, 00064 'packages': {}, 00065 } 00066 for f in stack_files: 00067 name = os.path.basename(os.path.dirname(f)) 00068 if os.path.isfile(f): 00069 with open(f) as yaml_f: 00070 # trim down metadata as repo files can be very large 00071 d = yaml.load(yaml_f) 00072 for k in ['depends', 'depends_on', 'repository', 'review_notes', 'review_status', 'vcs']: 00073 try: 00074 del d[k] 00075 except: 00076 pass 00077 repo_data['stacks'][name] = d 00078 00079 for f in package_files: 00080 name = os.path.basename(os.path.dirname(f)) 00081 if os.path.isfile(f): 00082 with open(f) as yaml_f: 00083 # trim down metadata as repo files can be very large. This 00084 # metadata is available elsewhere. 00085 d = yaml.load(yaml_f) 00086 for k in ['depends', 'depends_on', 'siblings', 'msgs', 'srvs', 'dependency_tree', 'repository', 'review_notes', 'review_status', 'api_documentation', 'description', 'vcs']: 00087 try: 00088 del d[k] 00089 except: 00090 pass 00091 repo_data['packages'][name] = d 00092 00093 filename = os.path.join(ctx.docdir, repo.name, 'repo.yaml') 00094 filename_dir = os.path.dirname(filename) 00095 if not os.path.isdir(filename_dir): 00096 os.makedirs(filename_dir) 00097 00098 with open(filename, 'w') as f: 00099 print "generating repo header %s"%(filename) 00100 f.write(yaml.safe_dump(repo_data, default_style="'")) 00101 00102 return [filename_dir]