aboutsummaryrefslogtreecommitdiff
path: root/releaselog.py
blob: c535a080430d40f521c56df38da945e37db24629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals

import sys
from optparse import OptionParser
from releaselog.input import ReleaseLogFile, ReleaseLogURL

# Set utf-8 as the default encoding for Python 2.7. 
try:
    reload(sys)
    sys.setdefaultencoding('utf-8')
except:
    pass

def main():
    usage = '%prog [OPTIONS] ARG'
    version = '%prog 1.0'
    description = """Read release logs in various formats"""
    parser = OptionParser(usage=usage,
                          version=version,
                          description=description)
    parser.add_option('-T', '--type',
                      action='store', type='string', dest='logtype',
                      default='GNU',
                      help='set log type')
    parser.add_option('-f', '--from', '--start',
                      action='store', type='int', dest='start',
                      help='start from this entry')
    parser.add_option('-t', '--to', '--stop',
                      action='store', type='int', dest='stop',
                      help='end on this entry')
    parser.add_option('-n', '--count',
                      action='store', type='int', dest='count',
                      help='read at most that much entries')
    parser.add_option('-u', '--url',
                      action="store_true", dest='url',
                      help='treat ARG as URL')
    parser.add_option('-l', '--list',
                      action="store_true", dest='list',
                      help="list supported formats")
    (options, args) = parser.parse_args()

    if options.list:
        for f in ReleaseLogFile.formats():
            if len(f) > 1:
                print("%s; %s" % (f[0], ', '.join(f[1:])))
            else:
                print("%s" % f[0])
        sys.exit(0)
    
    if len(args) != 1:
        parser.error("bad number of arguments")

    release_log = ReleaseLogURL if options.url else ReleaseLogFile
    cl = release_log(options.logtype, args[0],
                     start=options.start,
                     stop=options.stop,
                     count=options.count)
    for r in cl:
        print(r)
        print('\n'.join(r.descr))
    
if __name__ == '__main__':
    main()

Return to:

Send suggestions and report system problems to the System administrator.