Comment 4 for bug 240580

Revision history for this message
danigm (danigm) wrote :

I attach a bzr diff modificated to show only the changes that are interesting.

I make some modifies to loggerhead to show like I want, and the code is merged with style and other own modification that make it difficult.

I will explain how it work:

First it's needed that loggerhead.history could export:

--- loggerhead/history.py 2008-12-28 05:10:10 +0000
+++ loggerhead/history.py 2009-01-08 23:54:47 +0000
@@ -51,6 +51,7 @@
 import bzrlib.textfile
 import bzrlib.tsort
 import bzrlib.ui
+import bzrlib.export

 # bzrlib's UIFactory is not thread-safe
 uihack = threading.local()
@@ -919,3 +920,8 @@
                 lineno += 1

         self.log.debug('annotate: %r secs' % (time.time() - z))
+
+ def export(self, revid, dest):
+ rev_tree = self._branch.repository.revision_tree(revid)
+ bzrlib.export.export(rev_tree, dest)
+ return dest

Then I add this to download_ui controller:
=== modified file 'loggerhead/controllers/download_ui.py'
--- loggerhead/controllers/download_ui.py 2008-12-05 18:52:44 +0000
+++ loggerhead/controllers/download_ui.py 2009-01-08 23:54:47 +0000
@@ -25,10 +25,26 @@
 from paste.request import path_info_pop

 from loggerhead.controllers import TemplatedBranchView
+import os

 log = logging.getLogger("loggerhead.controllers")

+class TGZ(TemplatedBranchView):
+ def get_values(self, path, kwargs, headers):
+ history = self._history
+ revid = self.get_revid()
+
+ revno = history.get_revno(revid)
+ filename = '%s_%s.tgz' % (history._branch_nick, revno)
+ rpath = os.getcwd()+ '/loggerhead/static/downloads/' + filename
+
+ if not os.path.exists(rpath):
+ history.export(revid, rpath)
+
+ return {'download': '/static/downloads/'+filename}
+
+
 class DownloadUI (TemplatedBranchView):

     def __call__(self, environ, start_response):

Then I modify The loggerhead.controllers.__init__.py to make a HTTPRedirect when is a download. This redirect the navigator to the real filename that is placed in os.getcwd()+ '/loggerhead/static/downloads/' + filename. It need to be changed because you need to run loggerhead inside the directory, instead of use os.getcwd you can use a config variable.

Then I modify loggerhead.apps.branch.py to add TGZ page and respond to redirection raising instead of returning.

And finally I modify the templates to show a download button.

Now I will try to create a launchpad branch of loggerhead applying that changes.