15 | 15 |
from chrysoberyl.loader import (
|
16 | 16 |
load_chrysoberyl_dirs, load_config, overlay_yaml
|
17 | 17 |
)
|
18 | |
from chrysoberyl.objects import Universe
|
|
18 |
from chrysoberyl.objects import Universe, get_distname
|
19 | 19 |
from chrysoberyl.renderer import Renderer
|
20 | 20 |
from chrysoberyl.transformer import transform_dates
|
21 | 21 |
|
|
30 | 30 |
shelf = None
|
31 | 31 |
|
32 | 32 |
|
33 | |
### helper functions ###
|
34 | |
|
35 | |
|
36 | |
def github_repos(space):
|
37 | |
"""Generator which yields information about every git repository
|
38 | |
on Github referenced by some distribution in Chrysoberyl.
|
39 | |
|
40 | |
Information is a triple of the distribution key, the Github user
|
41 | |
(or organization) name, and the repository name.
|
42 | |
|
43 | |
"""
|
44 | |
for key, node in space.iteritems():
|
45 | |
if node['type'] != 'Distribution':
|
46 | |
continue
|
47 | |
if 'github' not in node:
|
48 | |
continue
|
49 | |
(user, repo) = node['github'].split('/')
|
50 | |
yield (key, user, repo)
|
51 | |
|
52 | |
|
53 | |
def get_distname(node):
|
54 | |
if 'github' in node:
|
55 | |
match = re.match(r'^catseye/(.*?)$', node['github'])
|
56 | |
return match.group(1).lower()
|
57 | |
urls = [release['url'] for release in node['releases']]
|
58 | |
distnames = set()
|
59 | |
for url in urls:
|
60 | |
match = re.match(r'^http:\/\/.*\/(.*?)\-', url)
|
61 | |
if not match:
|
62 | |
raise ValueError(url)
|
63 | |
distnames.add(match.group(1))
|
64 | |
if len(distnames) == 1:
|
65 | |
return distnames.pop()
|
66 | |
raise ValueError(distnames)
|
67 | |
|
68 | |
|
69 | 33 |
### command functions ###
|
70 | 34 |
|
71 | 35 |
def mkdistmap(universe, options, config):
|
72 | 36 |
"""Create a mapping between nodes and distributions."""
|
73 | 37 |
space = universe['node'] # FIXME hardcoded
|
74 | 38 |
dist = {}
|
75 | |
for (key, user, repo) in github_repos(space):
|
|
39 |
for (key, user, repo) in space.github_repos():
|
76 | 40 |
dist[key] = (user, repo)
|
77 | 41 |
|
78 | 42 |
repo_to_node = {}
|
|
107 | 71 |
config[space.name]['template_dirs'],
|
108 | 72 |
config[space.name]['output_dir'],
|
109 | 73 |
config[space.name]['checkout_dir'],
|
|
74 |
config[space.name]['projection_dir'],
|
110 | 75 |
options.sleek_node_links,
|
111 | 76 |
options.render_nodes,
|
112 | 77 |
)
|
|
146 | 111 |
"""
|
147 | 112 |
space = universe['node'] # FIXME hardcoded
|
148 | 113 |
lines = []
|
149 | |
for (key, user, repo) in github_repos(space):
|
|
114 |
for (key, user, repo) in space.github_repos():
|
150 | 115 |
source = shelf.make_source_from_spec('github.com/%s/%s' % (user, repo))
|
151 | 116 |
tag = source.get_latest_release_tag() or 'tip'
|
152 | 117 |
lines.append('bb:%s/%s@%s' % (user, repo, tag))
|
|
162 | 127 |
|
163 | 128 |
def checkout(universe, options, config):
|
164 | 129 |
"""Clone (or update, if they already exist) all git repos
|
165 | |
into a local directory.
|
|
130 |
into a local directory. Then, project a copy of all the files in
|
|
131 |
the repository into a plain, non-version-controlled directory in
|
|
132 |
the projection directory, at (TODO) the latest tag specified in data.
|
166 | 133 |
|
167 | 134 |
"""
|
168 | 135 |
space_key = 'node' # FIXME hardcoded
|
169 | 136 |
space = universe[space_key]
|
170 | |
lines = []
|
|
137 |
|
|
138 |
checkout_dir = os.path.abspath(config[space_key]['checkout_dir'])
|
171 | 139 |
try:
|
172 | |
os.makedirs(config[space_key]['checkout_dir'])
|
|
140 |
os.makedirs(checkout_dir)
|
173 | 141 |
except OSError:
|
174 | 142 |
pass
|
175 | |
for (key, user, repo) in sorted(github_repos(space)):
|
176 | |
repo_path = os.path.join(config[space_key]['checkout_dir'], repo)
|
|
143 |
|
|
144 |
projection_dir = os.path.abspath(config[space_key]['projection_dir'])
|
|
145 |
try:
|
|
146 |
os.makedirs(projection_dir)
|
|
147 |
except OSError:
|
|
148 |
pass
|
|
149 |
|
|
150 |
cwd = os.getcwd()
|
|
151 |
for (key, user, repo) in sorted(space.github_repos()):
|
|
152 |
repo_path = os.path.join(checkout_dir, repo)
|
177 | 153 |
if os.path.exists(repo_path):
|
178 | |
cwd = os.getcwd()
|
179 | 154 |
os.chdir(repo_path)
|
180 | 155 |
command = "git pull origin master"
|
181 | 156 |
print command
|
|
187 | 162 |
)
|
188 | 163 |
print command
|
189 | 164 |
os.system(command)
|
|
165 |
|
|
166 |
os.chdir(repo_path)
|
|
167 |
distname = get_distname(space[key])
|
|
168 |
proj_path = os.path.join(projection_dir, distname)
|
|
169 |
command = "git archive --format=tar --prefix=%s/ HEAD | (cd %s && tar xf -)" % (
|
|
170 |
distname, projection_dir
|
|
171 |
)
|
|
172 |
print command
|
|
173 |
os.system(command)
|
|
174 |
|
|
175 |
os.chdir(cwd)
|
190 | 176 |
|
191 | 177 |
|
192 | 178 |
def check_releases(universe, options, config):
|
|
237 | 223 |
|
238 | 224 |
passes = 0
|
239 | 225 |
space = universe['node'] # FIXME hardcoded
|
240 | |
for (key, user, repo) in sorted(github_repos(space)):
|
|
226 |
for (key, user, repo) in sorted(space.github_repos()):
|
241 | 227 |
if key in ('The Dipple', 'Illgol: Grand Mal',):
|
242 | 228 |
continue
|
243 | 229 |
|
|
325 | 311 |
return v_name
|
326 | 312 |
|
327 | 313 |
commands = []
|
328 | |
for (key, user, repo) in github_repos(space):
|
|
314 |
for (key, user, repo) in space.github_repos():
|
329 | 315 |
for release in space[key]['releases']:
|
330 | 316 |
url = release['url']
|
331 | 317 |
match = re.match(r'^http\:\/\/catseye\.tc\/distfiles\/(.*?)$', url)
|