00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
00084
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]