mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
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 <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
76185484d7
commit
45138fcdf0
@ -14,18 +14,17 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Framework for installing and updating distribution packages
|
Framework for installing and updating distribution packages
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from plinth import actions
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -90,6 +89,14 @@ class Transaction(object):
|
|||||||
logger.exception('Error installing package: %s', exception)
|
logger.exception('Error installing package: %s', exception)
|
||||||
raise
|
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):
|
def _run_apt_command(self, arguments):
|
||||||
"""Run apt-get and update progress."""
|
"""Run apt-get and update progress."""
|
||||||
self._reset_status()
|
self._reset_status()
|
||||||
@ -151,3 +158,9 @@ def is_package_manager_busy():
|
|||||||
return True
|
return True
|
||||||
except actions.ActionError:
|
except actions.ActionError:
|
||||||
return False
|
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 %}
|
{% blocktrans trimmed %}
|
||||||
This application is currently not available in your distribution.
|
This application is currently not available in your distribution.
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
|
<button type="submit" class="btn btn-default btn-sm" name="refresh-packages">
|
||||||
|
<span class="glyphicon glyphicon-refresh"></span> Check again
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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 %}
|
{% if package_manager_is_busy or setup_helper.has_unavailable_packages %}
|
||||||
disabled="disabled"
|
disabled="disabled"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -92,6 +95,7 @@
|
|||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
{% if setup_helper.current_operation.step == 'pre' %}
|
{% if setup_helper.current_operation.step == 'pre' %}
|
||||||
|
|||||||
@ -181,16 +181,22 @@ class SetupView(TemplateView):
|
|||||||
context['package_manager_is_busy'] = package.is_package_manager_busy()
|
context['package_manager_is_busy'] = package.is_package_manager_busy()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def post(self, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
"""Handle installing/upgrading applications.
|
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()
|
||||||
|
|
||||||
Start the application setup, and refresh the page every few
|
# Give a moment for the setup process to start and show
|
||||||
seconds to keep displaying the status.
|
# meaningful status.
|
||||||
"""
|
time.sleep(1)
|
||||||
self.kwargs['setup_helper'].run_in_thread()
|
return self.render_to_response(self.get_context_data())
|
||||||
|
|
||||||
# Give a moment for the setup process to start and show
|
elif 'refresh-packages' in request.POST:
|
||||||
# meaningful status.
|
# Refresh apt package lists
|
||||||
time.sleep(1)
|
package.refresh_package_lists()
|
||||||
|
return self.render_to_response(self.get_context_data())
|
||||||
return self.render_to_response(self.get_context_data())
|
else:
|
||||||
|
return super(SetupView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user