= Source Package Publishing Views = The default view for SourcePackagePublishingHistory offers a convenience property that can be used to display files that are related to that publication; this includes binary and source files. The property returns a sorted list of dictionaries with URLs, filenames and filesizes. >>> from zope.component import getMultiAdapter >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest >>> from lp.testing import celebrity_logged_in We'll create SourcePackagePublishingHistory entries for alsa-utils and foobar in ubuntu to test with: >>> from lp.soyuz.tests.test_publishing import ( ... SoyuzTestPublisher) >>> from lp.soyuz.enums import ( ... PackagePublishingStatus) >>> with celebrity_logged_in('admin'): ... stp = SoyuzTestPublisher() ... stp.prepareBreezyAutotest() ... alsa_pub = stp.getPubSource(sourcename='alsa-utils-test') ... foo_pub = stp.getPubSource(sourcename='foobar-test', ... status=PackagePublishingStatus.DELETED) The base class BasePublishingRecordView provides a few helper methods and properties for querying the publishing history record: If the publishing record does not include a removal comment, then the view property returns 'None provided.' >>> view = getMultiAdapter( ... (foo_pub, LaunchpadTestRequest()), name="+listing-compact") >>> view.wasDeleted() True >>> print view.context.removal_comment None >>> view.removal_comment u'None provided.' Otherwise the removal comment will be returned >>> login('foo.bar@canonical.com') >>> foo_pub.removal_comment = "It had to go." >>> print view.context.removal_comment It had to go. >>> print view.removal_comment It had to go. The SourcePackagePublishingView implements the 'published_source_and_binary_files' property which returns a list of dictionaries containing: * url: the librarian file url; * class: either 'source' or 'binary' CSS class; * filesize: the filesize stored in librarian; * filename: the filename to be presented to user; for each file related with the alsa-utils source publication in ubuntu. >>> view = getMultiAdapter( ... (alsa_pub, LaunchpadTestRequest()), ... name="+listing-archive-detailed") >>> view.published_source_and_binary_files [{'url': u'http://launchpad.dev/ubuntutest/+archive/primary/+files/alsa-utils-test_666.dsc', 'class': 'source', 'filesize': 28, 'filename': u'alsa-utils-test_666.dsc'}] 'iceweasel' source in Celso's PPA contains binary files that can be inspected. >>> from lp.registry.interfaces.person import IPersonSet >>> cprov = getUtility(IPersonSet).getByName("cprov") >>> iceweasel_source_pub = cprov.archive.getPublishedSources( ... 'iceweasel').first() >>> ppa_source_view = getMultiAdapter( ... (iceweasel_source_pub, LaunchpadTestRequest()), ... name="+listing-archive-detailed") >>> ppa_source_view.published_source_and_binary_files [{'url': u'http://launchpad.dev/~cprov/+archive/ppa/+files/firefox_0.9.2.orig.tar.gz', 'class': 'source', 'filesize': 9922560, 'filename': u'firefox_0.9.2.orig.tar.gz'}, {'url': u'http://launchpad.dev/~cprov/+archive/ppa/+files/iceweasel-1.0.dsc', 'class': 'source', 'filesize': 123, 'filename': u'iceweasel-1.0.dsc'}, {'url': u'http://launchpad.dev/~cprov/+archive/ppa/+files/mozilla-firefox_0.9_i386.deb', 'class': 'binary', 'filesize': 3, 'filename': u'mozilla-firefox_0.9_i386.deb'}] Yet using SourcePackagePublishingView classes we can verify how it allows the template to find out if it is a source or a binary publication. Continuing to use the 'iceweasel' source publication in Celso's PPA. >>> source_details_view = getMultiAdapter( ... (iceweasel_source_pub, LaunchpadTestRequest()), ... name="+record-details") We probe the 'is_source' and 'is_binary' properties. >>> print source_details_view.is_source True >>> print source_details_view.is_binary False Similarly, we use one of the 'iceweasel' binaries published in Celso's PPA to see how the same mechanism works for BinaryPackagePublishingHistoryView. >>> iceweasel_binary_pub = iceweasel_source_pub.getPublishedBinaries()[0] >>> binary_details_view = getMultiAdapter( ... (iceweasel_binary_pub, LaunchpadTestRequest()), ... name="+record-details") >>> print binary_details_view.is_source False >>> print binary_details_view.is_binary True Make sure the 'timestamp_map' class attribute in BasePublishingRecordView covers all PackagePublishingStatus values. This test will fail if we add a new value to the PackagePublishingStatus enumeration but neglect to update BasePublishingRecordView.timestamp_map accordingly. >>> from lp.soyuz.browser.publishing import ( ... BasePublishingRecordView) >>> for pps in PackagePublishingStatus.items: ... print '%s -> %s' % ( ... pps, BasePublishingRecordView.timestamp_map[pps]) Pending -> datecreated Published -> datepublished Superseded -> datesuperseded Deleted -> dateremoved Obsolete -> scheduleddeletiondate Any key that's not in the PackagePublishingStatus enumeration will cause an exception to be thrown. >>> print BasePublishingRecordView.timestamp_map['key_not_there'] Traceback (most recent call last): ... KeyError: 'key_not_there' == SourcePublishingRecordView == The SourcePublishingRecordView includes a build_status_summary property that returns a dict summary of the build status for the context record: >>> src_pub_record_view = create_initialized_view( ... iceweasel_source_pub, ... name="+listing-compact") Create a small function for displaying the results: >>> def print_build_summary(summary): ... print "%s\n%s\nRelevant builds:\n%s" % ( ... summary['status'].title, ... summary['status'].description, ... "\n".join( ... " - %s" % build.title for build in summary['builds']) ... ) >>> print_build_summary(src_pub_record_view.build_status_summary) FULLYBUILT_PENDING All builds were built successfully but have not yet been published. Relevant builds: - i386 build of iceweasel 1.0 in ubuntu warty RELEASE The view also helps templates to decide on the icon that should be used to summarize the current state of the context's associated builds: >>> print src_pub_record_view.build_status_img_src /@@/build-success-publishing As well as some helpers to determine the publishing status from templates: >>> src_pub_record_view.builds_successful_and_published False >>> src_pub_record_view.builds_successful_and_pending True >>> for build in src_pub_record_view.pending_builds: ... print build.title i386 build of iceweasel 1.0 in ubuntu warty RELEASE