Permalink
Browse files

XPI views moved out from jetpack

  • Loading branch information...
zalun committed Dec 10, 2010
1 parent 470eb15 commit 0f16f5681fcbd98d7cd0c3acf07439669a2603a6
View
@@ -22,7 +22,8 @@
from jetpack.managers import PackageManager
from jetpack.errors import SelfDependencyException, FilenameExistException, \
UpdateDeniedException, SingletonCopyException, DependencyException
-from jetpack.xpi_utils import sdk_copy, xpi_build, xpi_remove
+from utils import xpi
+#xpi.sdk_copy, xpi.build, xpi.remove
PERMISSION_CHOICES = (
@@ -761,9 +762,9 @@ def build_xpi(self):
# TODO: consider SDK staying per PackageRevision...
if os.path.isdir(sdk_dir):
- xpi_remove(sdk_dir)
+ xpi.remove(sdk_dir)
- sdk_copy(sdk_source, sdk_dir)
+ xpi.sdk_copy(sdk_source, sdk_dir)
self.export_keys(sdk_dir)
self.export_files_with_dependencies('%s/packages' % sdk_dir)
@@ -780,8 +781,8 @@ def build_xpi_test(self, modules=[]):
sdk_source = self.sdk.get_source_dir()
# This SDK is always different! - working on unsaved data
if os.path.isdir(sdk_dir):
- xpi_remove(sdk_dir)
- sdk_copy(sdk_source, sdk_dir)
+ xpi.remove(sdk_dir)
+ xpi.sdk_copy(sdk_source, sdk_dir)
self.export_keys(sdk_dir)
packages_dir = '%s/packages' % sdk_dir
@@ -800,7 +801,7 @@ def build_xpi_test(self, modules=[]):
self.export_attachments(
'%s/%s' % (package_dir, self.package.get_data_dir()))
self.export_dependencies(packages_dir)
- return (xpi_build(sdk_dir,
+ return (xpi.build(sdk_dir,
'%s/packages/%s' % (
sdk_dir,
self.package.get_unique_package_name()
View
@@ -2,11 +2,11 @@
from celery.decorators import task
-from jetpack import xpi_utils
+from utils import xpi
log = commonware.log.getLogger('f.tasks')
@task(rate_limit='10/s')
def xpi_build(sdk_dir, package_dir):
- xpi_utils.xpi_build(sdk_dir, package_dir)
+ xpi.build(sdk_dir, package_dir)
View
@@ -133,18 +133,4 @@
url(r'^library/remove_dependency/(?P<id_number>[-\w]+)/revision/(?P<revision_number>\d+)/$',
'package_remove_library',
{'type_id': 'l'}, name='jp_library_revision_remove_library'),
-
-
- # test Add-on's PackageRevision
- url(r'^addon/test/(?P<id_number>[-\w]+)/revision/(?P<revision_number>\d+)/$',
- 'package_test_xpi', name='jp_addon_revision_test'),
- url(r'^addon/xpi/(?P<id_number>[-\w]+)/revision/(?P<revision_number>\d+)/$',
- 'package_download_xpi', name='jp_addon_revision_xpi'),
-
- # get and remove created XPI
- url(r'^addon/test_xpi/(?P<sdk_name>.*)/(?P<pkg_name>.*)/(?P<filename>.*)/$',
- 'test_xpi', name='jp_test_xpi'),
- url(r'^addon/download_xpi/(?P<sdk_name>.*)/(?P<pkg_name>.*)/(?P<filename>.*)/$',
- 'download_xpi', name='jp_download_xpi'),
- url(r'^addon/rm_xpi/(?P<sdk_name>.*)/$', 'remove_xpi', name='jp_rm_xpi'),
)
View
@@ -26,10 +26,8 @@
from jetpack.models import Package, PackageRevision, Module, Attachment, SDK
from jetpack.package_helpers import get_package_revision
-from jetpack.xpi_utils import xpi_remove
from jetpack.errors import FilenameExistException
-
log = commonware.log.getLogger('f.jetpack')
@@ -667,119 +665,3 @@ def get_revisions_list_html(r, id_number):
# ---------------------------- XPI ---------------------------------
-def package_test_xpi(r, id_number, revision_number=None):
- """
- Test XPI from data saved in the database
- """
- revision = get_object_with_related_or_404(PackageRevision,
- package__id_number=id_number, package__type='a',
- revision_number=revision_number)
-
- # support temporary data
- if r.POST.get('live_data_testing', False):
- modules = []
- for mod in revision.modules.all():
- if r.POST.get(mod.filename, False):
- code = r.POST.get(mod.filename, '')
- if mod.code != code:
- mod.code = code
- modules.append(mod)
- (stdout, stderr) = revision.build_xpi_test(modules)
-
- else:
- # XXX: added test as build_xpi doesn't return
- (stdout, stderr) = revision.build_xpi_test()
-
- if stderr and not settings.DEBUG:
- # XXX: this should also log the error in file
- xpi_remove(revision.get_sdk_dir())
-
- # return XPI url and cfx command stdout and stderr
- return render_to_response('json/test_xpi_created.json', {
- 'stdout': stdout,
- 'stderr': stderr,
- 'test_xpi_url': reverse('jp_test_xpi', args=[
- revision.get_sdk_name(),
- revision.package.get_unique_package_name(),
- revision.package.name
- ]),
- 'download_xpi_url': reverse('jp_download_xpi', args=[
- revision.get_sdk_name(),
- revision.package.get_unique_package_name(),
- revision.package.name
- ]),
- 'rm_xpi_url': reverse('jp_rm_xpi', args=[revision.get_sdk_name()]),
- 'addon_name': '"%s (%s)"' % (
- revision.package.full_name, revision.get_version_name())
- }, context_instance=RequestContext(r))
- # mimetype='application/json')
-
-
-def package_download_xpi(r, id_number, revision_number=None):
- """
- Download XPI. This package is built asynchronously and we assume it works.
- and let ``download_xpi`` handle the case where the file is not ready.
- """
- revision = get_object_with_related_or_404(PackageRevision,
- package__id_number=id_number, package__type='a',
- revision_number=revision_number)
-
- # If this is a retry, we won't rebuild... we'll just wait.
- retry = r.GET.get('retry')
- retry_url = reverse('jp_addon_revision_xpi',
- args=[id_number, revision_number]) + '?retry=1'
-
- if not retry:
- revision.build_xpi()
-
- return download_xpi(r,
- revision.get_sdk_name(),
- revision.package.get_unique_package_name(),
- revision.package.name,
- retry=retry,
- retry_url=retry_url,
- )
-
-
-def test_xpi(r, sdk_name, pkg_name, filename):
- """
- return XPI file for testing
- """
- path = '%s-%s/packages/%s' % (settings.SDKDIR_PREFIX, sdk_name, pkg_name)
- _file = '%s.xpi' % filename
- mimetype = 'text/plain; charset=x-user-defined'
-
- try:
- xpi = open(os.path.join(path, _file), 'rb').read()
- except Exception, err:
- log.critical('Error creating Add-on: %s' % str(err))
- return HttpResponseServerError
-
- return HttpResponse(xpi, mimetype=mimetype)
-
-
-def download_xpi(r, sdk_name, pkg_name, filename, retry=False, retry_url=None):
- """Return XPI file for testing."""
- path = '%s-%s/packages/%s' % (settings.SDKDIR_PREFIX, sdk_name, pkg_name)
- f = '%s.xpi' % filename
- # Return file if it exists?
- if os.path.isfile(os.path.join(path, f)):
- r = serve(r, f, path, show_indexes=False)
- r['Content-Type'] = 'application/octet-stream'
- r['Content-Disposition'] = 'attachment; filename="%s.xpi"' % filename
- elif retry:
- r = render_to_response('retry_download.html', dict(url=retry_url),
- RequestContext(r))
- else:
- r = HttpResponseRedirect(retry_url)
-
- return r
-
-
-def remove_xpi(r, sdk_name):
- " remove whole temporary SDK on request "
- # Validate sdk_name
- if not validator.is_valid('alphanum_plus', sdk_name):
- return HttpResponseForbidden("{'error': 'Wrong name'}")
- xpi_remove('%s-%s' % (settings.SDKDIR_PREFIX, sdk_name))
- return HttpResponse('{}', mimetype='application/json')
View
No changes.
View
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
@@ -9,7 +9,7 @@
from django.conf import settings
from jetpack.models import Module, Package, PackageRevision, SDK
-from jetpack.xpi_utils import sdk_copy, xpi_build
+from utils import xpi
from jetpack.cron import find_files, clean_tmp
@@ -138,16 +138,16 @@ def test_addon_export_with_attachment(self):
self.failUnless(os.path.isfile(self.attachment_file_name))
def test_copying_sdk(self):
- sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
+ xpi.sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
self.failUnless(os.path.isdir(self.SDKDIR))
def test_minimal_xpi_creation(self):
" xpi build from an addon straight after creation "
- sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
+ xpi.sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
self.addonrev.export_keys(self.SDKDIR)
self.addonrev.export_files_with_dependencies(
'%s/packages' % self.SDKDIR)
- out = xpi_build(self.SDKDIR,
+ out = xpi.build(self.SDKDIR,
'%s/packages/%s' % (
self.SDKDIR, self.addon.get_unique_package_name()))
# assert no error output
@@ -163,11 +163,11 @@ def test_addon_with_other_modules(self):
filename='test_filename',
author=self.author
)
- sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
+ xpi.sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
self.addonrev.export_keys(self.SDKDIR)
self.addonrev.export_files_with_dependencies(
'%s/packages' % self.SDKDIR)
- out = xpi_build(self.SDKDIR,
+ out = xpi.build(self.SDKDIR,
'%s/packages/%s' % (
self.SDKDIR, self.addon.get_unique_package_name()))
# assert no error output
@@ -188,11 +188,11 @@ def test_xpi_with_empty_dependency(self):
librev = PackageRevision.objects.filter(
package__id_number=lib.id_number)[0]
self.addonrev.dependency_add(librev)
- sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
+ xpi.sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
self.addonrev.export_keys(self.SDKDIR)
self.addonrev.export_files_with_dependencies(
'%s/packages' % self.SDKDIR)
- out = xpi_build(self.SDKDIR,
+ out = xpi.build(self.SDKDIR,
'%s/packages/%s' % (
self.SDKDIR, self.addon.get_unique_package_name()))
# assert no error output
@@ -205,11 +205,11 @@ def test_xpi_with_empty_dependency(self):
def test_xpi_with_dependency(self):
" addon has one dependency with a file "
self.addonrev.dependency_add(self.librev)
- sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
+ xpi.sdk_copy(self.addonrev.sdk.get_source_dir(), self.SDKDIR)
self.addonrev.export_keys(self.SDKDIR)
self.addonrev.export_files_with_dependencies(
'%s/packages' % self.SDKDIR)
- out = xpi_build(self.SDKDIR,
+ out = xpi.build(self.SDKDIR,
'%s/packages/%s' % (
self.SDKDIR, self.addon.get_unique_package_name()))
# assert no error output
View
@@ -0,0 +1,18 @@
+" XPI URL definitions "
+
+from django.conf.urls.defaults import url, patterns
+
+urlpatterns = patterns('xpi.views',
+ # test Add-on's PackageRevision
+ url(r'^prepare_test/(?P<id_number>[-\w]+)/revision/(?P<revision_number>\d+)/$',
+ 'prepare_test', name='jp_addon_revision_test'),
+ url(r'^prepare_download/(?P<id_number>[-\w]+)/revision/(?P<revision_number>\d+)/$',
+ 'prepare_download', name='jp_addon_revision_xpi'),
+
+ # get and remove created XPI
+ url(r'^test/(?P<sdk_name>.*)/(?P<pkg_name>.*)/(?P<filename>.*)/$',
+ 'get_test', name='jp_test_xpi'),
+ url(r'^download/(?P<sdk_name>.*)/(?P<pkg_name>.*)/(?P<filename>.*)/$',
+ 'get_download', name='jp_download_xpi'),
+ url(r'^remove/(?P<sdk_name>.*)/$', 'clean', name='jp_rm_xpi'),
+)
Oops, something went wrong.

0 comments on commit 0f16f56

Please sign in to comment.