0 | |
# encoding: UTF-8
|
1 | |
|
2 | |
"""Parse command line and execute the command(s) given on it.
|
3 | |
|
4 | |
"""
|
5 | |
|
6 | |
import codecs
|
7 | |
import json
|
8 | |
from optparse import OptionParser
|
9 | |
import os
|
10 | |
import re
|
11 | |
import sys
|
12 | |
|
13 | |
|
14 | |
### command functions ###
|
15 | |
|
16 | |
|
17 | |
# NOTE:
|
18 | |
# `mkdistjson` has been run 'permanently' and, going forward, this
|
19 | |
# script will load from that JSON.
|
20 | |
|
21 | |
# TODO `mkdistmap` will need to be replaced by a script which, using Feedmark,
|
22 | |
# reads the articles and injects into each distribution a link to the
|
23 | |
# appropriate section of the article. This need only be done once; the
|
24 | |
# link will be saved in the new distribution JSON.
|
25 | |
|
26 | |
# project has been replaced by `shelf_cast`.
|
27 | |
|
28 | |
# TODO `check_releases` should be replaced by a script which dumps all
|
29 | |
# tags from all git repos and sees if there are any that do not correspond
|
30 | |
# with any distribution in here.
|
31 | |
|
32 | |
# TODO `check_distfiles` should be replaced by a script which looks at
|
33 | |
# all the distfile URLs in here and tries to fetch each of them and reports
|
34 | |
# if any can't be.
|
35 | |
|
36 | |
|
37 | |
def catalogue(distributions):
|
38 | |
"""Create a shelf catalogue from distribution nodes.
|
39 | |
|
40 | |
"""
|
41 | |
|
42 | |
infos = {}
|
43 | |
for (key, node) in sorted(distributions.iteritems()):
|
44 | |
repo = node.get('github')
|
45 | |
if not repo:
|
46 | |
#print "# skipping {}".format(key)
|
47 | |
continue
|
48 | |
repo = repo.replace('catseye/', '')
|
49 | |
releases = node.get('releases', [])
|
50 | |
new_style = node.get('tag-style', 'old') == 'new'
|
51 | |
tag = 'master'
|
52 | |
fixed_tag = node.get('fixed-tag', None)
|
53 | |
if fixed_tag == 'OMIT':
|
54 | |
continue
|
55 | |
if fixed_tag is not None:
|
56 | |
tag = fixed_tag
|
57 | |
elif releases:
|
58 | |
version = releases[-1]['version']
|
59 | |
revision = releases[-1]['revision']
|
60 | |
if new_style:
|
61 | |
tag = '%s-%s' % (version, revision)
|
62 | |
if revision == '0.0':
|
63 | |
tag = version
|
64 | |
else:
|
65 | |
version = re.sub(r'\.', r'_', str(version))
|
66 | |
revision = re.sub(r'\.', r'_', str(revision))
|
67 | |
tag = 'rel_%s_%s' % (version, revision)
|
68 | |
if revision == '0_0':
|
69 | |
tag = 'rel_%s' % version
|
70 | |
key = repo.lower() if os.getenv('LOWERCASE_REPOS') else repo
|
71 | |
infos[key] = (repo, tag)
|
72 | |
|
73 | |
lines = []
|
74 | |
for (key, (repo, tag)) in sorted(infos.iteritems()):
|
75 | |
lines.append('%s@%s' % (key, tag))
|
76 | |
|
77 | |
for line in sorted(lines):
|
78 | |
sys.stdout.write(line.encode('utf-8'))
|
79 | |
sys.stdout.write('\n')
|
80 | |
|
81 | |
|
82 | |
### driver ###
|
83 | |
|
84 | |
COMMANDS = {
|
85 | |
'catalogue': catalogue,
|
86 | |
}
|
87 | |
|
88 | |
|
89 | |
def usage():
|
90 | |
message = "chrysoberyl {option} {<command>}\n\n"
|
91 | |
message += "where each <command> is one of the following. All commands\n"
|
92 | |
message += "will be executed in the sequence in which they were given.\n"
|
93 | |
for command in sorted(COMMANDS.keys()):
|
94 | |
message += "\n %s - " % command
|
95 | |
message += COMMANDS[command].__doc__.rstrip()
|
96 | |
return message
|
97 | |
|
98 | |
|
99 | |
def perform(args):
|
100 | |
optparser = OptionParser(usage().rstrip())
|
101 | |
options, args = optparser.parse_args(args)
|
102 | |
|
103 | |
with open('distribution/distributions.json', 'r') as f:
|
104 | |
distributions = json.loads(f.read())
|
105 | |
|
106 | |
for command in args:
|
107 | |
COMMANDS[command](distributions)
|