summaryrefslogtreecommitdiff
path: root/tools/announce-wrangler.py
blob: cf9248642b7f310fdd4d0e4c0447a114dc69f81b (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import commands
import xml.dom.minidom
import glob
import wordpresslib # http://www.blackbirdblog.it/programmazione/progetti/28
import ConfigParser
import os
import re

doaps = glob.glob("*.doap")

if len(doaps)==0:
    print 'Please run this from the top-level directory.'

description=str(xml.dom.minidom.parse(doaps[0]).getElementsByTagName('shortdesc')[0].firstChild.toxml().strip())

program_name = doaps[0][:-5]
print program_name

markup = {
    'text': {
        'open': '  *',
        'newline': '   ',
        'close': '',
        },
    'html': {
        'open': '<li>',
        'newline': '',
        'close': '</li>',
        },
}

def text_list(list, type):
    result = []
    for entry in list:
        result.append(markup[type]['open'])
        for word in entry.split():
            if len(result[-1]+word)>75:
                result.append(markup[type]['newline'])
            result[-1] = result[-1] + ' ' + word
        if result[-1].strip()=='':
            result = result[:-1]
        result[-1] = result[-1] + markup[type]['close']
    return '\n'.join(result)

news = file('NEWS')
news_entry = []
header_count = 0

while header_count<2:
    line = news.readline().replace('\n', '')
    news_entry.append(line)
    if line.startswith('='):
        header_count = header_count + 1

news.close()

version = news_entry[0]
news_entry = news_entry[2:-2]

print version
majorminor = '.'.join(version.split('.')[:2])
md5s = commands.getoutput('ssh master.gnome.org md5sum /ftp/pub/GNOME/sources/metacity/%s/%s-%s.tar*' % (majorminor, program_name, version)).split()
if len(md5s)!=4:
    print 'WARNING: There were not two known tarballs'

md5_values = {}

for i in range(0, len(md5s), 2):
    a = md5s[i+1]
    md5_values[a[a.rindex('.'):]] = md5s[i]

print md5_values

changes = []
translations = ''

reading_changes = False
reading_translations = False
for line in news_entry:
    line = line.replace('(#', '(GNOME bug ').strip()
    if line.startswith('-'):
        changes.append(line[2:])
        reading_changes = True
    elif reading_changes:
        if line=='':
            reading_changes = False
        else:
            changes[-1] = changes[-1] + ' ' + line
    elif line=='Translations':
        reading_translations = True
    elif reading_translations:
        translations = translations + ' ' + line

translations = translations[1:]

text_links = []
for i in ('.bz2', '.gz'):
    text_links.append('%s http://download.gnome.org/sources/metacity/%s/%s-%s.tar%s' % (
            md5_values[i], majorminor, program_name, version, i))

text_version = """\
What is it ?
============
%s

What's changed ?
================
%s

Translations:
%s

Where can I get it ?
====================
%s""" % (text_list([description], 'text'),
                text_list(changes, 'text'),
                text_list([translations], 'text'),
                text_list(text_links, 'text'))

print "============ x8 x8 x8 ===== SEND THIS TO gnome-announce-list"
print text_version
print "============ x8 x8 x8 ===== ENDS"

translations = re.sub('\((.*)\)',
                      '(<a href="http://svn.gnome.org/viewvc/metacity/trunk/po/\\1.po">\\1</a>)',
                      translations)

html_version = """\
<b>What is it ?</b><br />
<ul>%s</ul>

<b>What's changed ?</b><br />
<ul>%s</ul>

<i>Translations:</i><br />
<ul>%s</ul>

<b>Where can I get it ?</b><br />
<ul>%s</ul>""" % (text_list([description], 'html'),
                text_list(changes, 'html'),
                text_list([translations], 'html'),
                text_list(text_links, 'html'))

cp = ConfigParser.ConfigParser()
cp.read(os.environ['HOME']+'/.config/metacity/tools.ini')

wp = wordpresslib.WordPressClient(
    cp.get('release-wrangler', 'blogurl'),
    cp.get('release-wrangler', 'bloguser'),
    cp.get('release-wrangler', 'blogpass'))
wp.selectBlog(cp.getint('release-wrangler', 'blognumber'))
post = wordpresslib.WordPressPost()
post.title = '%s %s released' % (program_name, version)
post.description = html_version
# appears to have been turned off-- ask jdub
#idPost = wp.newPost(post, False)

print html_version