Merge lp:~vds/ubuntuone-windows-installer/fix_rss into lp:ubuntuone-windows-installer/beta

Proposed by Vincenzo Di Somma
Status: Merged
Approved by: Rick McBride
Approved revision: 17
Merged at revision: 65
Proposed branch: lp:~vds/ubuntuone-windows-installer/fix_rss
Merge into: lp:ubuntuone-windows-installer/beta
Diff against target: 173 lines (+101/-45)
2 files modified
utils/rss_templates.py (+37/-0)
utils/upload_new_update.py (+64/-45)
To merge this branch: bzr merge lp:~vds/ubuntuone-windows-installer/fix_rss
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+31272@code.launchpad.net

Description of the change

Switched from manifest to rss.

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote :

I believe that each item of the RSS feed must have its own uuid, otherwise there use of an uuid does not make any sense, right?

review: Needs Fixing
Revision history for this message
Vincenzo Di Somma (vds) wrote :

Yes, but as it is only for tests there will always be one element right?

Revision history for this message
Manuel de la Peña (mandel) wrote :

> Yes, but as it is only for tests there will always be one element right?

Yes you are right, we can leave it like this for the time being until we move the content and the RSS somewhere else. Can you put a # TODO so that we remember to do it?

Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
Rick McBride (rmcbride) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'utils/__init__.py'
2=== added file 'utils/rss_templates.py'
3--- utils/rss_templates.py 1970-01-01 00:00:00 +0000
4+++ utils/rss_templates.py 2010-07-29 12:24:49 +0000
5@@ -0,0 +1,37 @@
6+# Copyright 2010 Canonical Ltd. All rights reserved.
7+"""
8+Parameters:
9+
10+ - lastBuildDate
11+ - pubDate format
12+ - version
13+ - enclosure url
14+ - enclosure lenght
15+ - sha
16+
17+"""
18+
19+from string import Template
20+
21+
22+RSS_TEMPLATE = Template("""
23+<rss version="2.0" xmlns:as="http://appsyndication.org/schemas/appsyn">
24+ <channel>
25+ <title>Ubuntu One Windows Client</title>
26+ <generator>WiX Toolset's ClickThrough for Isolated Applications</generator>
27+ <lastBuildDate>$lastBuildDate</lastBuildDate>
28+ <ttl>1440</ttl>
29+ <as:application type="application/vnd.ms-msi">7bb74cea-a4a3-4904-9706-8f4dc764b368</as:application>
30+ <item>
31+ <guid isPermaLink="false">urn:msi:7bb74cea-a4a3-4904-9706-8f4dc764b368/$version</guid>
32+ <pubDate>$pubDate</pubDate>
33+ <title>Ubuntu One Windows Client</title>
34+ <description>Ubuntu One Windows Client</description>
35+ <as:application type="application/vnd.ms-msi">58cdea62-96b2-482b-b046-d884583c8ccd</as:application>
36+ <as:version>$version</as:version>
37+ <enclosure url="$url" length="$lenght" type="application/octet-stream" />
38+ <as:digest algorithm="sha256">$sha</as:digest>
39+ </item>
40+ </channel>
41+</rss>
42+""")
43
44=== modified file 'utils/upload_new_update.py'
45--- utils/upload_new_update.py 2010-07-09 10:11:58 +0000
46+++ utils/upload_new_update.py 2010-07-29 12:24:49 +0000
47@@ -3,62 +3,81 @@
48
49 """This utilities release an Ubuntu One windows update."""
50
51+import os
52+import time
53+import hashlib
54 import sys
55-from zipfile import ZipFile
56-from xml.dom.minidom import parseString
57+
58 import boto
59 from boto.s3.key import Key
60-
61-
62-MANIFEST_NAME = 'ubuntuone.manifest'
63-PACKAGES_BUCKET_PREFIX = 'vds'
64-MANIFEST_BUCKET = 'vds_manifest'
65-
66-def upload_package(name, version, conn, package_filename):
67- """Creates the bucket and upload the package"""
68- new_bucket_name = '%s-%s-%s' % (PACKAGES_BUCKET_PREFIX, name, version)
69- new_bucket_name = new_bucket_name.lower()
70- bucket = conn.create_bucket(new_bucket_name)
71- print 'New bucket created: %s' % new_bucket_name
72- k = Key(bucket)
73- k.key = package_filename
74- k.set_contents_from_filename(package_filename)
75- print 'Package uploaded: %s' % package_filename
76- bucket.set_acl('public-read', package_filename)
77- print 'Making package public: %s' % package_filename
78-
79-
80-def update_manifest(conn, manifest):
81- bucket = conn.create_bucket((MANIFEST_BUCKET))
82- k = Key(bucket)
83- k.key = 'manifest'
84- k.set_contents_from_string(manifest)
85- print 'Manifest updated'
86- bucket.set_acl('public-read', 'manifest')
87- print 'Making manifest public'
88-
89-
90-def main(package_filename):
91+from boto.exception import S3ResponseError
92+
93+from rss_templates import RSS_TEMPLATE
94+
95+
96+
97+BUCKET = 'u1wintest'
98+RSS_FILE_NAME = 'rss'
99+
100+
101+def upload_package(bucket, filename):
102+ """Upload the package"""
103+ try:
104+ print 'Removing %s...' % filename
105+ bucket.delete_key(filename)
106+ except S3ResponseError:
107+ print 'No previous upload.'
108+ print 'Uploading %s...' % filename
109+ k = Key(bucket)
110+ k.key = filename
111+ k.set_contents_from_filename(filename)
112+ bucket.set_acl('public-read', filename)
113+ print "Uploaded!"
114+
115+
116+def upload_rss(bucket, filename, rss_params):
117+ """Upload the RSS"""
118+ now = time.strftime('%d %b %Y %H:%M:%S %Z')
119+ rss_params['lastBuildDate'] = rss_params['pubDate'] = now
120+ fd = open(filename,'r')
121+ rss_params['sha'] = hashlib.sha1(fd.read()).hexdigest()
122+ rss_params['lenght'] = os.path.getsize(filename)
123+ try:
124+ print 'Removing rss...'
125+ bucket.delete_key(RSS_FILE_NAME)
126+ except S3ResponseError:
127+ print 'No previous upload'
128+ print 'Generating new rss...'
129+ rss = RSS_TEMPLATE.substitute(rss_params)
130+ print 'Uploading new rss...'
131+ k = Key(bucket)
132+ k.key = RSS_FILE_NAME
133+ k.set_contents_from_string(rss)
134+ bucket.set_acl('public-read', RSS_FILE_NAME)
135+ print "Uploaded!"
136+
137+
138+def main(filename, rss_params):
139 """ """
140- # prepare to upload
141- packagezip = ZipFile(package_filename, 'r')
142- manifest = packagezip.read(MANIFEST_NAME)
143- manifest_dom = parseString(manifest)
144- identity = manifest_dom.getElementsByTagName('assemblyIdentity')[0]
145- name = identity.getAttribute('name')
146- version = identity.getAttribute('version')
147 # connect to S3
148 print 'Connecting to S3...'
149 conn = boto.connect_s3()
150 print 'Connected!'
151- upload_package(name, version, conn, package_filename)
152- update_manifest(conn, manifest)
153+ bucket = conn.get_bucket(BUCKET)
154+ upload_package(bucket, filename)
155+ upload_rss(bucket, filename, rss_params)
156
157
158 if __name__ == '__main__':
159 argv = sys.argv
160 #FIXME check we have AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in the env
161- if len (argv) != 2:
162- print "Usage: upload_new_update.py package_file"
163+ if len (argv) != 4:
164+ print "Usage: upload_new_update.py package_file version url"
165+ print "example:"
166+ print 'python upload_new_update.py u1client.msi 0.0.2 "/u1wintest"'
167 sys.exit()
168- sys.exit(main(package_filename=argv[1]))
169+ package_filename = argv[1]
170+ rss_params = {}
171+ rss_params['version'] = argv[2]
172+ rss_params['url'] = argv[3]
173+ sys.exit(main(filename=argv[1], rss_params=rss_params))

Subscribers

People subscribed via source and target branches