mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
actions: test case for is-package-manager-busy command
comments, import optimization and YAPF formatting. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
3 files changed
+54
-52
No files matched your search
+12
-10
@@ -15,16 +15,15 @@
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Wrapper to handle package installation with apt-get.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from importlib import import_module
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from importlib import import_module
|
||||
|
||||
from plinth import cfg
|
||||
|
||||
@@ -41,8 +40,8 @@ def parse_arguments():
|
||||
subparser = subparsers.add_parser('install', help='install packages')
|
||||
subparser.add_argument(
|
||||
'module', help='name of module for which package is being installed')
|
||||
subparser.add_argument(
|
||||
'packages', nargs='+', help='list of packages to install')
|
||||
subparser.add_argument('packages', nargs='+',
|
||||
help='list of packages to install')
|
||||
subparsers.add_parser('is-package-manager-busy',
|
||||
help='Return whether package manager is busy')
|
||||
|
||||
@@ -53,8 +52,9 @@ def parse_arguments():
|
||||
def _run_apt_command(arguments):
|
||||
"""Run apt-get with provided arguments."""
|
||||
# Ask apt-get to output its progress to file descriptor 3.
|
||||
command = ['apt-get', '--assume-yes', '--quiet=2', '--option',
|
||||
'APT::Status-Fd=3'] + arguments
|
||||
command = [
|
||||
'apt-get', '--assume-yes', '--quiet=2', '--option', 'APT::Status-Fd=3'
|
||||
] + arguments
|
||||
|
||||
# Duplicate stdout to file descriptor 3 for this process.
|
||||
os.dup2(1, 3)
|
||||
@@ -63,9 +63,9 @@ def _run_apt_command(arguments):
|
||||
# so that regular output is ignored.
|
||||
env = os.environ.copy()
|
||||
env['DEBIAN_FRONTEND'] = 'noninteractive'
|
||||
process = subprocess.run(
|
||||
command, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
|
||||
close_fds=False, env=env)
|
||||
process = subprocess.run(command, stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, close_fds=False,
|
||||
env=env)
|
||||
sys.exit(process.returncode)
|
||||
|
||||
|
||||
@@ -99,7 +99,9 @@ def _assert_managed_packages(module, packages):
|
||||
|
||||
|
||||
def subcommand_is_package_manager_busy(_):
|
||||
"""Return whether package manager is busy."""
|
||||
"""Return whether package manager is busy.
|
||||
This command uses the `lsof` command to check whether the dpkg lock file
|
||||
is open which indicates that the package manager is busy"""
|
||||
try:
|
||||
subprocess.check_output(['lsof', LOCK_FILE])
|
||||
except subprocess.CalledProcessError:
|
||||
|
||||
Reference in new issue
Block a user