Merge lp:~julian-edwards/launchpad/metadata-type-bug-595038 into lp:launchpad

Proposed by Julian Edwards
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 11036
Proposed branch: lp:~julian-edwards/launchpad/metadata-type-bug-595038
Merge into: lp:launchpad
Diff against target: 179 lines (+133/-0)
5 files modified
lib/lp/archivepublisher/tests/publishing-meta-data-files.txt (+65/-0)
lib/lp/archiveuploader/nascentuploadfile.py (+2/-0)
lib/lp/archiveuploader/tests/meta-data-custom-files.txt (+21/-0)
lib/lp/soyuz/interfaces/queue.py (+18/-0)
lib/lp/soyuz/model/queue.py (+27/-0)
To merge this branch: bzr merge lp:~julian-edwards/launchpad/metadata-type-bug-595038
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Review via email: mp+27837@code.launchpad.net

Description of the change

= Summary =
Add meta-data custom upload type for use by the Software Center.

== Implementation details ==
This branch defines a new custom upload type, META_DATA, which is defined by a
file's section being "meta-data".

The file's format is of no concern to Soyuz, it simply lives in the librarian
and is published to an area outside of the repo so that if the repo is
private, the meta-data is still accessible.

== Tests ==
bin/test -cvvt publishing-meta-data-files.txt -t meta-data-custom-files.txt

== Demo and Q/A ==
We need to make a source package with a meta-data custom file attached and
upload. It should get accepted as normal and published appropriately.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/soyuz/model/queue.py
  lib/lp/soyuz/interfaces/queue.py
  lib/lp/archivepublisher/tests/publishing-meta-data-files.txt
  lib/lp/archiveuploader/nascentuploadfile.py
  lib/lp/archiveuploader/tests/meta-data-custom-files.txt

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

lib/lp/archiveuploader/tests/meta-data-custom-files.txt uses the British spelling of "Software Centre".

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Nice, surprising to see how easy it is to add another custom file type.

The enum value "META_DATA" doesn't really describe to me what this data is about to me, as everything that is not the package itself (changes, dsc files) could be considered metadata. CATALOGUE perhaps, or something that explicitly refers to software center?

review: Needs Information (code)
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Thanks for the review Jelmer.

I think CATALOGUE is another can of worms, because the US spelling is CATALOG. I also don't think changing the enum name itself will help a lot, to be honest, but the doctest and the enum text should be very clear and easy to understand. Is there anything in those you think can be improved?

J

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Oops, I hadn't realized catalogue was also UK English. :-) The enum value name was a minor issue, I think it's sufficiently documented and fine to land as is.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'lib/lp/archivepublisher/tests/publishing-meta-data-files.txt'
2--- lib/lp/archivepublisher/tests/publishing-meta-data-files.txt 1970-01-01 00:00:00 +0000
3+++ lib/lp/archivepublisher/tests/publishing-meta-data-files.txt 2010-06-17 14:00:53 +0000
4@@ -0,0 +1,65 @@
5+Publishing Meta-Data Custom Files
6+=================================
7+
8+Meta-data custom files are published, unmodified, to a special area
9+outside the actual archive directory. This is so that the files can be
10+seen even when the archive is private, and allows commercial customers
11+to browse contents for potential later purchase.
12+
13+We can demonstrate this publishing behaviour by creating a
14+PackageUploadCustom object for a meta-data upload:
15+
16+ >>> from canonical.launchpad.interfaces.librarian import (
17+ ... ILibraryFileAliasSet)
18+ >>> from lp.archiveuploader.tests import mock_logger
19+ >>> from lp.registry.interfaces.distribution import IDistributionSet
20+ >>> from lp.soyuz.interfaces.publishing import PackagePublishingPocket
21+ >>> from lp.soyuz.interfaces.queue import PackageUploadCustomFormat
22+ >>> from lp.soyuz.model.queue import PackageUploadCustom
23+ >>> from cStringIO import StringIO
24+
25+ >>> bat = getUtility(IDistributionSet)['ubuntutest']['breezy-autotest']
26+ >>> ppa = factory.makeArchive(distribution=bat.distribution)
27+ >>> package_upload = bat.createQueueEntry(
28+ ... pocket=PackagePublishingPocket.RELEASE, changesfilename="test",
29+ ... changesfilecontent="test",
30+ ... archive=ppa)
31+ >>> content = "test"
32+ >>> test_file = getUtility(
33+ ... ILibraryFileAliasSet).create(
34+ ... "testmeta", len(content), StringIO(content), "text/plain")
35+ >>> custom_upload = PackageUploadCustom()
36+ >>> custom_upload.customformat = PackageUploadCustomFormat.META_DATA
37+ >>> custom_upload.packageupload = package_upload
38+ >>> custom_upload.libraryfilealias = test_file
39+ >>> # commit so that the file is put in the librarian.
40+ >>> import transaction
41+ >>> transaction.commit()
42+
43+Now we can publish the custom upload:
44+
45+ >>> custom_upload.publish(logger=mock_logger)
46+ DEBUG: Publishing custom testmeta to ubuntutest/breezy-autotest
47+
48+The custom file is just called "testmeta" with the contents "test". It will
49+be published in a location of the scheme:
50+
51+/<person_name>/meta/<ppa_name>/<filename>
52+
53+ >>> import os
54+ >>> from lp.archivepublisher.config import getPubConfig
55+ >>> pub_config = getPubConfig(ppa)
56+ >>> ppa_root = pub_config.distroroot
57+ >>> final_destination = os.path.join(
58+ ... ppa_root, ppa.owner.name, "meta", ppa.name)
59+ >>> published_file = os.path.join(
60+ ... final_destination, "testmeta")
61+
62+ >>> os.path.exists(published_file)
63+ True
64+
65+ >>> with open(published_file, 'rb') as fp:
66+ ... content = fp.read()
67+
68+ >>> print content
69+ test
70
71=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
72--- lib/lp/archiveuploader/nascentuploadfile.py 2010-05-12 08:17:20 +0000
73+++ lib/lp/archiveuploader/nascentuploadfile.py 2010-06-17 14:00:53 +0000
74@@ -260,6 +260,8 @@
75 'raw-ddtp-tarball': PackageUploadCustomFormat.DDTP_TARBALL,
76 'raw-translations-static':
77 PackageUploadCustomFormat.STATIC_TRANSLATIONS,
78+ 'meta-data' :
79+ PackageUploadCustomFormat.META_DATA,
80 }
81
82 @property
83
84=== added file 'lib/lp/archiveuploader/tests/meta-data-custom-files.txt'
85--- lib/lp/archiveuploader/tests/meta-data-custom-files.txt 1970-01-01 00:00:00 +0000
86+++ lib/lp/archiveuploader/tests/meta-data-custom-files.txt 2010-06-17 14:00:53 +0000
87@@ -0,0 +1,21 @@
88+Meta-Data Custom files
89+======================
90+
91+Meta-data custom files are files that contain more information about the
92+source package they're being uploaded with, such as descriptions and
93+pricing. This information is used by the Software Centre to display
94+better descriptions about packages than would normally be found in the
95+package itself.
96+
97+When the CustomUploadFile object is created with the right section name,
98+its custom_type property returns the right DBEnum,
99+PackageUploadCustomFormat.META_DATA.
100+
101+ >>> from lp.archiveuploader.nascentuploadfile import CustomUploadFile
102+ >>> custom_upload_file = CustomUploadFile(
103+ ... filepath="", digest="", size=1, priority_name="", policy=None,
104+ ... component_and_section="main/meta-data", logger=None)
105+
106+ >>> print custom_upload_file.custom_type.name
107+ META_DATA
108+
109
110=== modified file 'lib/lp/soyuz/interfaces/queue.py'
111--- lib/lp/soyuz/interfaces/queue.py 2010-03-17 12:14:36 +0000
112+++ lib/lp/soyuz/interfaces/queue.py 2010-06-17 14:00:53 +0000
113@@ -605,6 +605,17 @@
114 reside in the librarian for later retrieval using the webservice.
115 """
116
117+ def publish_META_DATA(logger):
118+ """Publish this custom item as a meta-data file.
119+
120+ This method writes the meta-data custom file to the archive in
121+ the location matching this schema:
122+ /<person>/meta/<ppa_name>/<filename>
123+
124+ It's not written to the main archive location because that could be
125+ protected by htaccess in the case of private archives.
126+ """
127+
128
129 class IPackageUploadSet(Interface):
130 """Represents a set of IPackageUploads"""
131@@ -742,3 +753,10 @@
132
133 A tarball containing raw (Gnome) help file translations.
134 """)
135+
136+ META_DATA = DBItem(5, """
137+ meta-data
138+
139+ A file containing meta-data about the package, mainly for use in
140+ the Software Center.
141+ """)
142
143=== modified file 'lib/lp/soyuz/model/queue.py'
144--- lib/lp/soyuz/model/queue.py 2010-05-14 04:51:42 +0000
145+++ lib/lp/soyuz/model/queue.py 2010-06-17 14:00:53 +0000
146@@ -1747,6 +1747,33 @@
147 debug(logger, "Skipping publishing of static translations.")
148 return
149
150+ def publish_META_DATA(self, logger=None):
151+ """See `IPackageUploadCustom`."""
152+ # In the future this could use the existing custom upload file
153+ # processing which deals with versioning, etc., but that's too
154+ # complicated for our needs right now. Also, the existing code
155+ # assumes that everything is a tarball and tries to unpack it.
156+
157+ archive = self.packageupload.archive
158+ # See the XXX near the import for getPubConfig.
159+ archive_config = getPubConfig(archive)
160+ meta_root = os.path.join(
161+ archive_config.distroroot, archive.owner.name)
162+ dest_dir = os.path.join(
163+ meta_root, "meta", archive.name)
164+ dest_file = os.path.join(
165+ dest_dir, self.libraryfilealias.filename)
166+ if not os.path.isdir(dest_dir):
167+ os.makedirs(dest_dir, 0755)
168+
169+ # At this point we now have a directory of the format:
170+ # <person_name>/meta/<ppa_name>
171+ # We're ready to copy the file out of the librarian into it.
172+
173+ file_obj = file(dest_file, "wb")
174+ self.libraryfilealias.open()
175+ copy_and_close(self.libraryfilealias, file_obj)
176+
177
178 class PackageUploadSet:
179 """See `IPackageUploadSet`"""