Skip to content

Commit

Permalink
pep8 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Jul 19, 2015
1 parent ec4d2e3 commit f413155
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
49 changes: 33 additions & 16 deletions fabric_package_management/apt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fabric.api import hide, run, settings, sudo, settings
from fabric.api import hide, run, settings, sudo
from fabric.context_managers import shell_env
from fabric.contrib.files import exists

Expand All @@ -13,6 +13,7 @@ def _run_cmd(func, cmd, verbose):
with settings(hide('everything')):
return func(cmd)


def install(packages, assume_yes=True, no_install_recommends=False,
install_suggests=False, use_sudo=True, verbose=True):
"""
Expand All @@ -26,7 +27,8 @@ def install(packages, assume_yes=True, no_install_recommends=False,
dependency for installing. (Default: `False`)
assume_yes (bool): If `True`, Apt will assume "yes" as answer to all
prompts and run non-interactively. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
if not isinstance(packages, str):
Expand Down Expand Up @@ -61,7 +63,8 @@ def update(use_sudo=True, verbose=True):
Update Apt's package index files on the remote host.
Args:
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
func = use_sudo and sudo or run
Expand All @@ -77,7 +80,8 @@ def upgrade(assume_yes=True, use_sudo=True, verbose=True):
Args:
assume_yes (bool): If `True`, Apt will assume "yes" as answer to all
prompts and run non-interactively. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
if assume_yes:
Expand All @@ -90,6 +94,7 @@ def upgrade(assume_yes=True, use_sudo=True, verbose=True):

return _run_cmd(func, cmd, verbose)


def dist_upgrade(assume_yes=True, use_sudo=True, verbose=True):
"""
Same as `upgrade`, but Apt will attempt to intelligently handle changing
Expand All @@ -98,7 +103,8 @@ def dist_upgrade(assume_yes=True, use_sudo=True, verbose=True):
Args:
assume_yes (bool): If `True`, Apt will assume "yes" as answer to all
prompts and run non-interactively. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
if assume_yes:
Expand All @@ -123,7 +129,8 @@ def remove(packages, purge=False, assume_yes=True, use_sudo=True,
(Default: `False`)
assume_yes (bool): If `True`, Apt will assume "yes" as answer to all
prompts and run non-interactively. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
if not isinstance(packages, str):
Expand All @@ -150,7 +157,8 @@ def clean(use_sudo=True, verbose=True):
Clears out retrieved package files.
Args:
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
func = use_sudo and sudo or run
Expand All @@ -165,7 +173,8 @@ def autoclean(use_sudo=True, verbose=True):
be downloaded.
Args:
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""
func = use_sudo and sudo or run
Expand All @@ -180,7 +189,8 @@ def autoremove(assume_yes=True, use_sudo=True, verbose=True):
Args:
assume_yes (bool): If `True`, Apt will assume "yes" as answer to all
prompts and run non-interactively. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""

Expand All @@ -194,6 +204,7 @@ def autoremove(assume_yes=True, use_sudo=True, verbose=True):

return _run_cmd(func, cmd, verbose)


def source(package, download_only=False, use_sudo=False, verbose=True):
"""
Download a given source package.
Expand All @@ -202,7 +213,8 @@ def source(package, download_only=False, use_sudo=False, verbose=True):
package (str): The source package to download.
download_only (bool): If `True`, the source package will not be
unpacked. (Default: `False`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `False`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `False`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""

Expand All @@ -225,7 +237,8 @@ def build_dep(package, assume_yes=True, use_sudo=True, verbose=True):
package (str): The package whose build dependencies will be installed.
assume_yes (bool): If `True`, Apt will assume "yes" as answer to all
prompts and run non-interactively. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `True`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `True`)
verbose (bool): If `False`, hide all output. (Default: `True`)
"""

Expand All @@ -247,11 +260,14 @@ def reboot_required(use_sudo=False, verbose=False):
Returns `True` if a reboot is required, `False` if not.
Args:
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `False`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `False`)
verbose (bool): If `False`, hide all output. (Default: `False`)
"""
return exists('/var/run/reboot-required', use_sudo=use_sudo,
verbose=verbose)
return exists('/var/run/reboot-required',
use_sudo=use_sudo,
verbose=verbose)


def installed(package, use_sudo=True):
"""
Expand All @@ -261,12 +277,13 @@ def installed(package, use_sudo=True):
Args:
package (str): The package to check if installed.
use_sudo (bool): If `True`, will use `sudo` instead of `run`. (Default: `False`)
use_sudo (bool): If `True`, will use `sudo` instead of `run`.
(Default: `False`)
"""
func = use_sudo and sudo or run
cmd = "dpkg -s {0}".format(package)
with settings(warn_only=True):
installed = _run_cmd(func, cmd, verbose=False)
if installed.find("install ok installed") > -1:
return True
return False
return False
19 changes: 11 additions & 8 deletions tests/test_apt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest, os
import unittest
import os

from fabric.api import settings, task, run
from fabric.api import settings
from fabric.operations import local
from fabric.context_managers import cd
from fabric.contrib.files import exists
Expand Down Expand Up @@ -129,7 +130,8 @@ def test_remove(self):
'apt-get remove --yes --purge htop')
htop = exists('/usr/bin/htop')
self.assertFalse(htop)
json = exists('/usr/lib/python2.7/dist-packages/simplejson/__init__.py')
json = exists(
'/usr/lib/python2.7/dist-packages/simplejson/__init__.py')
self.assertFalse(json)

def test_build_dep(self):
Expand All @@ -141,7 +143,8 @@ def test_build_dep(self):
self.assertTrue(build_dep.succeeded)
self.assertEqual(build_dep.command,
'apt-get build-dep --yes python-libcloud')
json = exists('/usr/lib/python2.7/dist-packages/simplejson/__init__.py')
json = exists(
'/usr/lib/python2.7/dist-packages/simplejson/__init__.py')
self.assertTrue(json)

def test_autoremove(self):
Expand Down Expand Up @@ -185,10 +188,10 @@ def test_clean(self):
self.assertEqual(clean.command, 'apt-get clean')

def test_installed(self):
with settings(host_string=self.container_host,
with settings(host_string=self.container_host,
user='root',
password='functionaltests'):

self.assertFalse(apt.installed('rolldice'))
apt.install('rolldice')
self.assertTrue(apt.installed('rolldice'))
self.assertFalse(apt.installed('rolldice'))
apt.install('rolldice')
self.assertTrue(apt.installed('rolldice'))

0 comments on commit f413155

Please sign in to comment.