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
=== added file 'lib/lp/archivepublisher/tests/publishing-meta-data-files.txt'
--- lib/lp/archivepublisher/tests/publishing-meta-data-files.txt 1970-01-01 00:00:00 +0000
+++ lib/lp/archivepublisher/tests/publishing-meta-data-files.txt 2010-06-17 14:00:53 +0000
@@ -0,0 +1,65 @@
1Publishing Meta-Data Custom Files
2=================================
3
4Meta-data custom files are published, unmodified, to a special area
5outside the actual archive directory. This is so that the files can be
6seen even when the archive is private, and allows commercial customers
7to browse contents for potential later purchase.
8
9We can demonstrate this publishing behaviour by creating a
10PackageUploadCustom object for a meta-data upload:
11
12 >>> from canonical.launchpad.interfaces.librarian import (
13 ... ILibraryFileAliasSet)
14 >>> from lp.archiveuploader.tests import mock_logger
15 >>> from lp.registry.interfaces.distribution import IDistributionSet
16 >>> from lp.soyuz.interfaces.publishing import PackagePublishingPocket
17 >>> from lp.soyuz.interfaces.queue import PackageUploadCustomFormat
18 >>> from lp.soyuz.model.queue import PackageUploadCustom
19 >>> from cStringIO import StringIO
20
21 >>> bat = getUtility(IDistributionSet)['ubuntutest']['breezy-autotest']
22 >>> ppa = factory.makeArchive(distribution=bat.distribution)
23 >>> package_upload = bat.createQueueEntry(
24 ... pocket=PackagePublishingPocket.RELEASE, changesfilename="test",
25 ... changesfilecontent="test",
26 ... archive=ppa)
27 >>> content = "test"
28 >>> test_file = getUtility(
29 ... ILibraryFileAliasSet).create(
30 ... "testmeta", len(content), StringIO(content), "text/plain")
31 >>> custom_upload = PackageUploadCustom()
32 >>> custom_upload.customformat = PackageUploadCustomFormat.META_DATA
33 >>> custom_upload.packageupload = package_upload
34 >>> custom_upload.libraryfilealias = test_file
35 >>> # commit so that the file is put in the librarian.
36 >>> import transaction
37 >>> transaction.commit()
38
39Now we can publish the custom upload:
40
41 >>> custom_upload.publish(logger=mock_logger)
42 DEBUG: Publishing custom testmeta to ubuntutest/breezy-autotest
43
44The custom file is just called "testmeta" with the contents "test". It will
45be published in a location of the scheme:
46
47/<person_name>/meta/<ppa_name>/<filename>
48
49 >>> import os
50 >>> from lp.archivepublisher.config import getPubConfig
51 >>> pub_config = getPubConfig(ppa)
52 >>> ppa_root = pub_config.distroroot
53 >>> final_destination = os.path.join(
54 ... ppa_root, ppa.owner.name, "meta", ppa.name)
55 >>> published_file = os.path.join(
56 ... final_destination, "testmeta")
57
58 >>> os.path.exists(published_file)
59 True
60
61 >>> with open(published_file, 'rb') as fp:
62 ... content = fp.read()
63
64 >>> print content
65 test
066
=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
--- lib/lp/archiveuploader/nascentuploadfile.py 2010-05-12 08:17:20 +0000
+++ lib/lp/archiveuploader/nascentuploadfile.py 2010-06-17 14:00:53 +0000
@@ -260,6 +260,8 @@
260 'raw-ddtp-tarball': PackageUploadCustomFormat.DDTP_TARBALL,260 'raw-ddtp-tarball': PackageUploadCustomFormat.DDTP_TARBALL,
261 'raw-translations-static':261 'raw-translations-static':
262 PackageUploadCustomFormat.STATIC_TRANSLATIONS,262 PackageUploadCustomFormat.STATIC_TRANSLATIONS,
263 'meta-data' :
264 PackageUploadCustomFormat.META_DATA,
263 }265 }
264266
265 @property267 @property
266268
=== added file 'lib/lp/archiveuploader/tests/meta-data-custom-files.txt'
--- lib/lp/archiveuploader/tests/meta-data-custom-files.txt 1970-01-01 00:00:00 +0000
+++ lib/lp/archiveuploader/tests/meta-data-custom-files.txt 2010-06-17 14:00:53 +0000
@@ -0,0 +1,21 @@
1Meta-Data Custom files
2======================
3
4Meta-data custom files are files that contain more information about the
5source package they're being uploaded with, such as descriptions and
6pricing. This information is used by the Software Centre to display
7better descriptions about packages than would normally be found in the
8package itself.
9
10When the CustomUploadFile object is created with the right section name,
11its custom_type property returns the right DBEnum,
12PackageUploadCustomFormat.META_DATA.
13
14 >>> from lp.archiveuploader.nascentuploadfile import CustomUploadFile
15 >>> custom_upload_file = CustomUploadFile(
16 ... filepath="", digest="", size=1, priority_name="", policy=None,
17 ... component_and_section="main/meta-data", logger=None)
18
19 >>> print custom_upload_file.custom_type.name
20 META_DATA
21
022
=== modified file 'lib/lp/soyuz/interfaces/queue.py'
--- lib/lp/soyuz/interfaces/queue.py 2010-03-17 12:14:36 +0000
+++ lib/lp/soyuz/interfaces/queue.py 2010-06-17 14:00:53 +0000
@@ -605,6 +605,17 @@
605 reside in the librarian for later retrieval using the webservice.605 reside in the librarian for later retrieval using the webservice.
606 """606 """
607607
608 def publish_META_DATA(logger):
609 """Publish this custom item as a meta-data file.
610
611 This method writes the meta-data custom file to the archive in
612 the location matching this schema:
613 /<person>/meta/<ppa_name>/<filename>
614
615 It's not written to the main archive location because that could be
616 protected by htaccess in the case of private archives.
617 """
618
608619
609class IPackageUploadSet(Interface):620class IPackageUploadSet(Interface):
610 """Represents a set of IPackageUploads"""621 """Represents a set of IPackageUploads"""
@@ -742,3 +753,10 @@
742753
743 A tarball containing raw (Gnome) help file translations.754 A tarball containing raw (Gnome) help file translations.
744 """)755 """)
756
757 META_DATA = DBItem(5, """
758 meta-data
759
760 A file containing meta-data about the package, mainly for use in
761 the Software Center.
762 """)
745763
=== modified file 'lib/lp/soyuz/model/queue.py'
--- lib/lp/soyuz/model/queue.py 2010-05-14 04:51:42 +0000
+++ lib/lp/soyuz/model/queue.py 2010-06-17 14:00:53 +0000
@@ -1747,6 +1747,33 @@
1747 debug(logger, "Skipping publishing of static translations.")1747 debug(logger, "Skipping publishing of static translations.")
1748 return1748 return
17491749
1750 def publish_META_DATA(self, logger=None):
1751 """See `IPackageUploadCustom`."""
1752 # In the future this could use the existing custom upload file
1753 # processing which deals with versioning, etc., but that's too
1754 # complicated for our needs right now. Also, the existing code
1755 # assumes that everything is a tarball and tries to unpack it.
1756
1757 archive = self.packageupload.archive
1758 # See the XXX near the import for getPubConfig.
1759 archive_config = getPubConfig(archive)
1760 meta_root = os.path.join(
1761 archive_config.distroroot, archive.owner.name)
1762 dest_dir = os.path.join(
1763 meta_root, "meta", archive.name)
1764 dest_file = os.path.join(
1765 dest_dir, self.libraryfilealias.filename)
1766 if not os.path.isdir(dest_dir):
1767 os.makedirs(dest_dir, 0755)
1768
1769 # At this point we now have a directory of the format:
1770 # <person_name>/meta/<ppa_name>
1771 # We're ready to copy the file out of the librarian into it.
1772
1773 file_obj = file(dest_file, "wb")
1774 self.libraryfilealias.open()
1775 copy_and_close(self.libraryfilealias, file_obj)
1776
17501777
1751class PackageUploadSet:1778class PackageUploadSet:
1752 """See `IPackageUploadSet`"""1779 """See `IPackageUploadSet`"""