Skip to content

Commit

Permalink
Merge pull request #351 from rullmann/feature-snap-support
Browse files Browse the repository at this point in the history
Feature snap support
  • Loading branch information
trehn committed Jul 9, 2017
2 parents aadad09 + f288712 commit 97f81ba
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bundlewrap/items/pkg_snap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from pipes import quote

from bundlewrap.items.pkg import Pkg


class SnapPkg(Pkg):
"""
A package installed by snap.
"""
BLOCK_CONCURRENT = ["pkg_snap"]
BUNDLE_ATTRIBUTE_NAME = "pkg_snap"
ITEM_TYPE_NAME = "pkg_snap"

def pkg_all_installed(self):
result = self.node.run("snap list")
for line in result.stdout.decode('utf-8').strip().split("\n"):
yield "{}:{}".format(self.ITEM_TYPE_NAME, line.split()[0].split(" ")[0])

def pkg_install(self):
self.node.run("snap install {}".format(quote(self.name)))

def pkg_installed(self):
result = self.node.run(
"snap list {}".format(quote(self.name)),
may_fail=True,
)
return result.return_code == 0

def pkg_remove(self):
self.node.run("snap remove {}".format(quote(self.name)))
24 changes: 24 additions & 0 deletions docs/content/items/pkg_snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# snap package items

Handles packages installed by `snap` command.

pkg_snap = {
"foopkg": {
"installed": True, # default
},
"bar": {
"installed": False,
},
}

<br>

## Attribute reference

See also: [The list of generic builtin item attributes](../repo/bundles.md#builtin-item-attributes)

<br>

### installed

`True` when the package is expected to be present on the system; `False` if it should be removed.
1 change: 1 addition & 0 deletions docs/content/repo/bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This table lists all item types included in BundleWrap along with the bundle att
<tr><td><a href="../../items/pkg_dnf">pkg_dnf</a></td><td><code>pkg_dnf</code></td><td>Installs and removes packages with dnf</td></tr>
<tr><td><a href="../../items/pkg_pacman">pkg_pacman</a></td><td><code>pkg_pacman</code></td><td>Installs and removes packages with pacman</td></tr>
<tr><td><a href="../../items/pkg_pip">pkg_pip</a></td><td><code>pkg_pip</code></td><td>Installs and removes Python packages with pip</td></tr>
<tr><td><a href="../../items/pkg_snap">pkg_snap</a></td><td><code>pkg_snap</code></td><td>Installs and removes packages with snap</td></tr>
<tr><td><a href="../../items/pkg_yum">pkg_yum</a></td><td><code>pkg_yum</code></td><td>Installs and removes packages with yum</td></tr>
<tr><td><a href="../../items/pkg_zypper">pkg_zypper</a></td><td><code>pkg_zypper</code></td><td>Installs and removes packages with zypper</td></tr>
<tr><td><a href="../../items/postgres_db">postgres_db</a></td><td><code>postgres_dbs</code></td><td>Manages Postgres databases</td></tr>
Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pages:
- pkg_dnf: items/pkg_dnf.md
- pkg_pacman: items/pkg_pacman.md
- pkg_pip: items/pkg_pip.md
- pkg_snap: items/pkg_snap.md
- pkg_yum: items/pkg_yum.md
- pkg_zypper: items/pkg_zypper.md
- postgres_db: items/postgres_db.md
Expand Down

0 comments on commit 97f81ba

Please sign in to comment.