Commit 45138fcd authored by Joseph Nuthalapati's avatar Joseph Nuthalapati Committed by James Valleroy

packages: Button to refresh package lists

- This is a fallback solution to manually refresh package lists on AWS images
  since they come with no apt package lists.
- This can also be occasionally useful for people running the testing
  distribution where packages might be frequently added and removed.
Signed-off-by: Joseph Nuthalapati's avatarJoseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent 76185484
Pipeline #11988 failed with stages
in 8 minutes and 4 seconds
......@@ -14,18 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Framework for installing and updating distribution packages
"""
from django.utils.translation import ugettext as _
import logging
import subprocess
import threading
from plinth import actions
from django.utils.translation import ugettext as _
from plinth import actions
logger = logging.getLogger(__name__)
......@@ -90,6 +89,14 @@ class Transaction(object):
logger.exception('Error installing package: %s', exception)
raise
def refresh_package_lists(self):
"""Refresh apt package lists."""
try:
self._run_apt_command(['update'])
except subprocess.CalledProcessError as exception:
logger.exception('Error updating package lists: %s', exception)
raise
def _run_apt_command(self, arguments):
"""Run apt-get and update progress."""
self._reset_status()
......@@ -151,3 +158,9 @@ def is_package_manager_busy():
return True
except actions.ActionError:
return False
def refresh_package_lists():
"""To be run in case apt package lists are outdated."""
transaction = Transaction(None, None)
transaction.refresh_package_lists()
......@@ -77,10 +77,13 @@
{% blocktrans trimmed %}
This application is currently not available in your distribution.
{% endblocktrans %}
<button type="submit" class="btn btn-default btn-sm" name="refresh-packages">
<span class="glyphicon glyphicon-refresh"></span> Check again
</button>
</div>
{% endif %}
<input type="submit" class="btn btn-md btn-primary"
<input type="submit" class="btn btn-md btn-primary" name="install"
{% if package_manager_is_busy or setup_helper.has_unavailable_packages %}
disabled="disabled"
{% endif %}
......@@ -92,6 +95,7 @@
</form>
{% else %}
{% if setup_helper.current_operation.step == 'pre' %}
......
......@@ -181,16 +181,22 @@ class SetupView(TemplateView):
context['package_manager_is_busy'] = package.is_package_manager_busy()
return context
def post(self, *args, **kwargs):
"""Handle installing/upgrading applications.
Start the application setup, and refresh the page every few
seconds to keep displaying the status.
"""
self.kwargs['setup_helper'].run_in_thread()
# Give a moment for the setup process to start and show
# meaningful status.
time.sleep(1)
return self.render_to_response(self.get_context_data())
def dispatch(self, request, *args, **kwargs):
if request.method == 'POST':
if 'install' in request.POST:
# Handle installing/upgrading applications.
# Start the application setup, and refresh the page every few
# seconds to keep displaying the status.
self.kwargs['setup_helper'].run_in_thread()
# Give a moment for the setup process to start and show
# meaningful status.
time.sleep(1)
return self.render_to_response(self.get_context_data())
elif 'refresh-packages' in request.POST:
# Refresh apt package lists
package.refresh_package_lists()
return self.render_to_response(self.get_context_data())
else:
return super(SetupView, self).dispatch(request, *args, **kwargs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment