def download_installer(request, build_id, platform): """ <Purpose> Initiates a download of an installer. <Arguments> request: A Django request. build_id: The build ID of the file to download. platform: The platform for which to build the installer. <Exceptions> None. <Side Effects> None. <Returns> A Django response which initiates a download through a redirect. """ manager = BuildManager(build_id=build_id) # Invalid build IDs should results in an error. if not os.path.isdir(manager.get_build_directory()): raise Http404 if not manager.installer_exists(platform): manager.package(platform) installer_url = manager.get_static_urls()[platform] return HttpResponseRedirect(installer_url)
def get_urls(self, build_id): """ <Purpose> Allows XML-RPC clients request the URLs for builds other than their own. <Arguments> build_id: The build ID of a previously generated custom installer. <Exceptions> ValidationError if improper build_id is passed. <Side Effects> None. <Returns> A dictionary which contains URLs pointing to the installers, and a dictionary of user cryptographic keys. """ validations.validate_build_id(build_id) manager = BuildManager(build_id=build_id) if not os.path.isdir(manager.get_build_directory()): raise validations.ValidationError('Given build ID does not exist.') return manager.get_urls()
def download_installers_page(request, build_id): """ <Purpose> Renders the installer package download page. <Arguments> request: A Django request. build_id: The build ID of the results to display. <Exceptions> None. <Side Effects> None. <Returns> A Django response. """ manager = BuildManager(build_id=build_id) # Invalid build IDs should results in an error. if not os.path.isdir(manager.get_build_directory()): raise Http404 # Compile the list of links of where to find the installers and cryptographic # key archives. installer_links = manager.get_urls() # If there is a query string appended to the current URL, we don't want that # in the share-this-URL box. share_url = request.build_absolute_uri().split('?')[0] # Only show the progress bar if the user has built this installer himself. # Otherwise, we assume the user has shared this link with a friend. step = None user_built = False if 'build_results' in request.session: if build_id in request.session['build_results']: step = 'installers' user_built = True # If we serve a fast_lane_build we don't show the breadcrumbs if 'fast_lane_build' in request.session['build_results'][build_id]: step = False return render(request, 'download_installers.html', { 'build_id': build_id, 'installers': installer_links, 'share_url': share_url, 'step': step, 'user_built': user_built, })
def download_installers_page(request, build_id): """ <Purpose> Renders the installer package download page. <Arguments> request: A Django request. build_id: The build ID of the results to display. <Exceptions> None. <Side Effects> None. <Returns> A Django response. """ manager = BuildManager(build_id=build_id) # Invalid build IDs should results in an error. if not os.path.isdir(manager.get_build_directory()): raise Http404 # Compile the list of links of where to find the installers and cryptographic # key archives. installer_links = manager.get_urls() # If there is a query string appended to the current URL, we don't want that # in the share-this-URL box. share_url = request.build_absolute_uri().split('?')[0] # Only show the progress bar if the user has built this installer himself. # Otherwise, we assume the user has shared this link with a friend. step = None user_built = False if 'build_results' in request.session: if build_id in request.session['build_results']: step = 'installers' user_built = True # If we serve a fast_lane_build we don't show the breadcrumbs if 'fast_lane_build' in request.session['build_results'][build_id]: step = False return render( request, 'download_installers.html', { 'build_id': build_id, 'installers': installer_links, 'share_url': share_url, 'step': step, 'user_built': user_built, })
def download_keys(request, build_id, key_type): """ <Purpose> Initiates a download of a key bundle. <Arguments> request: A Django request. build_id: The build ID of the file to download. key_type: The type of key bundle to return ('public' or 'private'). <Exceptions> None. <Side Effects> None. <Returns> A Django response which initiates a download through a redirect. """ manager = BuildManager(build_id=build_id) # Invalid build IDs should results in an error. if not os.path.isdir(manager.get_build_directory()): raise Http404 key_filenames = packager.package_keys( request.session['build_results'][build_id]['users']) # Generally, it is undesirable to serve files directly through django, but # the key bundles should be very small and still download quickly. bundle_filename = key_filenames[key_type] # FileResponse is a subclass of StreamingHttpResponse optimized # for binary files requires Django >1.8 response = FileResponse(open(bundle_filename), content_type='application/zip') response['Content-Disposition'] = 'attachment; filename=' + os.path.split( bundle_filename)[1] response['Content-Length'] = os.path.getsize(bundle_filename) # The HTML form will not give access to the installers until the user has # downloaded the private keys. keys_downloaded = request.session['build_results'][build_id].get( 'keys_downloaded', dict()) keys_downloaded[key_type] = True request.session['build_results'][build_id][ 'keys_downloaded'] = keys_downloaded request.session.save() return response
def download_keys(request, build_id, key_type): """ <Purpose> Initiates a download of a key bundle. <Arguments> request: A Django request. build_id: The build ID of the file to download. key_type: The type of key bundle to return ('public' or 'private'). <Exceptions> None. <Side Effects> None. <Returns> A Django response which initiates a download through a redirect. """ manager = BuildManager(build_id=build_id) # Invalid build IDs should results in an error. if not os.path.isdir(manager.get_build_directory()): raise Http404 key_filenames = packager.package_keys(request.session['build_results'][build_id]['users']) # Generally, it is undesirable to serve files directly through django, but # the key bundles should be very small and still download quickly. bundle_filename = key_filenames[key_type] # FileResponse is a subclass of StreamingHttpResponse optimized # for binary files requires Django >1.8 response = FileResponse(open(bundle_filename), content_type='application/zip') response['Content-Disposition'] = 'attachment; filename=' + os.path.split(bundle_filename)[1] response['Content-Length'] = os.path.getsize(bundle_filename) # The HTML form will not give access to the installers until the user has # downloaded the private keys. keys_downloaded = request.session['build_results'][build_id].get('keys_downloaded', dict()) keys_downloaded[key_type] = True request.session['build_results'][build_id]['keys_downloaded'] = keys_downloaded request.session.save() return response