File: amo-changelog

package info (click to toggle)
mozilla-devscripts 0.39
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 364 kB
  • sloc: python: 1,054; sh: 106; perl: 35; makefile: 31
file content (61 lines) | stat: -rwxr-xr-x 2,258 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python

# Copyright (c) 2014, Jakub Wilk <jwilk@debian.org>
# Copyright (c) 2014, Ximin Luo <infinity0@pwned.gg>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from __future__ import print_function

import argparse
import os
import sys
import urllib2
import xml.etree.cElementTree as etree

URL_TEMPLATE = "https://addons.mozilla.org/en-US/addon/{ext}/versions/format:rss"


def main():
    parser = argparse.ArgumentParser(
        description="fetch Version History of an addon from the Mozilla Extensions website.")
    parser.add_argument("extension",
                        help="Extension short-name, as used on addons.mozilla.org.")
    options = parser.parse_args()

    url = URL_TEMPLATE.format(ext=options.extension)
    try:
        fp = urllib2.urlopen(url)
    except urllib2.HTTPError as error:
        print("%s: For extension '%s', error fetching '%s': %s" %
              (os.path.basename(sys.argv[0]), options.extension, url, error),
              file=sys.stderr)
        return 1
    try:
        for _, element in etree.iterparse(fp):
            if element.tag != "item":
                continue
            title = element.find("title").text.encode("utf-8")
            print(title)
            print("=" * len(title))
            descel = element.find("description")
            if descel is not None and descel.text:
                print(descel.text.rstrip("\n").encode("utf-8"))
            else:
                print("[no description]")
            print("")
    finally:
        fp.close()

if __name__ == "__main__":
    sys.exit(main())