Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #193 from zalun/download_all

ability to download_all files with one click
  • Loading branch information...
commit 80812ff5db6add7254da99f9392cf41efc5e4e4b 2 parents 0b4e95f + ac95800
@clouserw clouserw authored
View
15 apps/jetpack/models.py
@@ -1341,7 +1341,7 @@ def get_sdk_revision(self):
return self.sdk.kit_lib if self.sdk.kit_lib else self.sdk.core_lib
def export_source(self, modules=None, attachments=None, tstart=None,
- temp_dir=None, package_overrides=None):
+ temp_dir=None, package_overrides=None):
"""
Export source of the PackageRevision and all it's dependencies
@@ -1391,6 +1391,15 @@ def export_source(self, modules=None, attachments=None, tstart=None,
statsd.timing('export.attachments', t3)
log.debug("[export] attachments exported (time %dms)" % t3)
+ # export commit message
+ #self.message
+ #self.commit_message
+ commit_msg_path = os.path.join(package_dir, 'commit_message')
+ with codecs.open(commit_msg_path, mode='w', encoding='utf-8') as f:
+ f.write("%s\n--\n%s" % (self.version_name, self.commit_message))
+ if (self.message):
+ f.write("\n--\n%s" % self.message)
+
# XPI: copying to local from memory/db/files
self.export_dependencies(temp_dir)
t4 = (time.time() - (t3 / 1000) - tstart) * 1000
@@ -1847,6 +1856,10 @@ def get_view_on_amo_url(self):
settings.AMO_SITE_PROTOCOL, settings.AMO_SITE_DOMAIN,
self.amo_slug)
+ def get_all_zipped_url(self):
+ " returns a url to zip_all view "
+ return reverse('jp_package_zip', args=[self.pk])
+
def get_edit_on_amo_url(self, step=5):
" returns the url to resume an incomplete add-on "
if not self.amo_slug:
View
3  apps/jetpack/templates/edit.html
@@ -95,6 +95,9 @@
<li id="zip" title="Download Source" class="UI_Editor_Menu_Button Icon_zip">
<a href="{{ revision.get_prepare_zip_url() }}"><span></span></a>
</li>
+ <li id="zipall" title="Download all versions" class="UI_Editor_Menu_Button Icon_zip">
+ <a href="{{ revision.package.get_all_zipped_url() }}"><span></span></a>
+ </li>
<li class="UI_Editor_Menu_Separator"></li>
<li title="Save" class="UI_Editor_Menu_Button Icon_save">
<a id="package-save" href="#"><span></span></a>
View
3  apps/jetpack/templates/view.html
@@ -84,6 +84,9 @@
<li id="zip" title="Download Source" class="UI_Editor_Menu_Button Icon_zip">
<a href="{{ revision.get_prepare_zip_url() }}"><span></span></a>
</li>
+ <li id="zipall" title="Download all versions" class="UI_Editor_Menu_Button Icon_zip">
+ <a href="{{ revision.package.get_all_zipped_url() }}"><span></span></a>
+ </li>
<li class="UI_Editor_Menu_Separator"></li>
{% endif %}
{% if revision.package.public_permission != 2 and user.is_authenticated %}
View
4 apps/jetpack/urls.py
@@ -101,7 +101,7 @@
url(r'^package/remove_attachment/(?P<revision_id>\d+)/$',
'remove_attachment', name='jp_package_revision_remove_attachment'),
- # rename attachment
+ # rename attachment
url(r'^package/rename_attachment/(?P<revision_id>\d+)/$',
'rename_attachment', name='jp_package_revision_rename_attachment'),
@@ -143,4 +143,6 @@
'get_zip', name='jp_revision_download_zip'),
url(r'^revision/check_zip/(?P<hashtag>[a-zA-Z0-9]+)/$',
'check_zip', name='jp_revision_check_zip'),
+ url(r'^package/zip/(?P<pk>\d+)/$',
+ 'all_zip', name='jp_package_zip'),
)
View
26 apps/jetpack/views.py
@@ -10,8 +10,10 @@
import time
import waffle
+from contextlib import closing
from simplejson import JSONDecodeError
from statsd import statsd
+from zipfile import ZipFile, ZIP_DEFLATED
from django.contrib import messages
from django.core.urlresolvers import reverse
@@ -1313,3 +1315,27 @@ def check_zip(r, hashtag):
if os.path.isfile(path):
return HttpResponse('{"ready": true}')
return HttpResponse('{"ready": false}')
+
+
+@never_cache
+def all_zip(request, pk):
+ """Zip all and return a file."""
+ if not pk:
+ log.critical("[zip] No package_id provided")
+ return
+ package = Package.objects.get(pk=pk)
+ zips = []
+ # Zip all revisions of the package
+ for revision in package.revisions.all():
+ zips.append(revision.zip_source(hashtag=revision.get_cache_hashtag()))
+ # Zip all zipped revisions into one file
+ zip_targetname = "package-%d.zip" % package.pk
+ zip_targetpath = os.path.join(settings.XPI_TARGETDIR, zip_targetname)
+ with closing(ZipFile(zip_targetpath, 'w', ZIP_DEFLATED)) as z:
+ for fn in zips:
+ z.write(fn)
+ log.info('[zipall:%s] Downloading All zipped' % pk)
+
+ response = serve(request, zip_targetpath, '/', show_indexes=False)
+ response['Content-Disposition'] = ('attachment; filename="%s"' % zip_targetname)
+ return response
2  vendor
@@ -1 +1 @@
-Subproject commit c9e5405789630c273dca1916b007033bac7f507a
+Subproject commit 5bccd4720b81b6135c06dc773da1cddadfde5ca4
Please sign in to comment.
Something went wrong with that request. Please try again.