git @ Cat's Eye Technologies Chrysoberyl / 438b934
Transition away from monolithic `chrysoberyl` utility. Chris Pressey 6 years ago
3 changed file(s) with 64 addition(s) and 120 deletion(s). Raw diff Collapse all Expand all
+0
-12
bin/chrysoberyl less more
0 #!/usr/bin/env python
1
2 from os.path import realpath, dirname, join
3 import sys
4
5 sys.path.insert(0, join(dirname(realpath(sys.argv[0])), '..', 'src'))
6
7 from chrysoberyl import commands
8
9
10 if __name__ == '__main__':
11 commands.perform(sys.argv[1:])
0 #!/usr/bin/env python
1 # encoding: UTF-8
2
3 import json
4 #from optparse import OptionParser
5 import os
6 import re
7 import sys
8
9 #sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..', 'src'))
10
11 #from chrysoberyl import commands
12
13
14 def create_shelf_catalog():
15 """Create a shelf catalogue from distribution nodes.
16
17 """
18
19 with open('distribution/distributions.json', 'r') as f:
20 distributions = json.loads(f.read())
21
22 infos = {}
23 for (key, node) in sorted(distributions.iteritems()):
24 repo = node.get('github')
25 if not repo:
26 #print "# skipping {}".format(key)
27 continue
28 repo = repo.replace('catseye/', '')
29 releases = node.get('releases', [])
30 new_style = node.get('tag-style', 'old') == 'new'
31 tag = 'master'
32 fixed_tag = node.get('fixed-tag', None)
33 if fixed_tag == 'OMIT':
34 continue
35 if fixed_tag is not None:
36 tag = fixed_tag
37 elif releases:
38 version = releases[-1]['version']
39 revision = releases[-1]['revision']
40 if new_style:
41 tag = '%s-%s' % (version, revision)
42 if revision == '0.0':
43 tag = version
44 else:
45 version = re.sub(r'\.', r'_', str(version))
46 revision = re.sub(r'\.', r'_', str(revision))
47 tag = 'rel_%s_%s' % (version, revision)
48 if revision == '0_0':
49 tag = 'rel_%s' % version
50 key = repo.lower() if os.getenv('LOWERCASE_REPOS') else repo
51 infos[key] = (repo, tag)
52
53 lines = []
54 for (key, (repo, tag)) in sorted(infos.iteritems()):
55 lines.append('%s@%s' % (key, tag))
56
57 for line in sorted(lines):
58 sys.stdout.write(line.encode('utf-8'))
59 sys.stdout.write('\n')
60
61
62 if __name__ == '__main__':
63 create_shelf_catalog()
+0
-108
src/chrysoberyl/commands.py less more
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)