|
| 1 | +''' |
| 2 | +Manage pkgin packages. |
| 3 | +''' |
| 4 | + |
| 5 | +from pyinfra.api import operation |
| 6 | +from pyinfra.facts.pkgin import PkginPackages |
| 7 | + |
| 8 | +from .util.packaging import ensure_packages |
| 9 | + |
| 10 | + |
| 11 | +@operation |
| 12 | +def upgrade(state=None, host=None): |
| 13 | + ''' |
| 14 | + Upgrades all pkgin packages. |
| 15 | + ''' |
| 16 | + |
| 17 | + yield 'pkgin -y upgrade' |
| 18 | + |
| 19 | +_upgrade = upgrade # noqa: E305 |
| 20 | + |
| 21 | + |
| 22 | +@operation |
| 23 | +def update(state=None, host=None): |
| 24 | + ''' |
| 25 | + Updates pkgin repositories. |
| 26 | + ''' |
| 27 | + |
| 28 | + yield 'pkgin -y update' |
| 29 | + |
| 30 | +_update = update # noqa: E305 |
| 31 | + |
| 32 | + |
| 33 | +@operation |
| 34 | +def packages( |
| 35 | + packages=None, present=True, latest=False, |
| 36 | + update=False, upgrade=False, |
| 37 | + state=None, host=None, |
| 38 | +): |
| 39 | + ''' |
| 40 | + Add/remove/update pkgin packages. |
| 41 | +
|
| 42 | + + packages: list of packages to ensure |
| 43 | + + present: whether the packages should be installed |
| 44 | + + latest: whether to upgrade packages without a specified version |
| 45 | + + update: run ``pkgin update`` before installing packages |
| 46 | + + upgrade: run ``pkgin upgrade`` before installing packages |
| 47 | +
|
| 48 | + Examples: |
| 49 | +
|
| 50 | + .. code:: python |
| 51 | +
|
| 52 | + # Update package list and install packages |
| 53 | + pkgin.packages( |
| 54 | + name='Install tmux and Vim', |
| 55 | + packages=['tmux', 'vim'], |
| 56 | + update=True, |
| 57 | + ) |
| 58 | +
|
| 59 | + # Install the latest versions of packages (always check) |
| 60 | + pkgin.packages( |
| 61 | + name='Install latest Vim', |
| 62 | + packages=['vim'], |
| 63 | + latest=True, |
| 64 | + ) |
| 65 | + ''' |
| 66 | + |
| 67 | + if update: |
| 68 | + yield _update(state=state, host=host) |
| 69 | + |
| 70 | + if upgrade: |
| 71 | + yield _upgrade(state=state, host=host) |
| 72 | + |
| 73 | + # TODO support glob for specific versions (it isn't as simple |
| 74 | + # as apt's, as pkgin supports something like 'mysql-server>=5.6<5.7') |
| 75 | + yield ensure_packages( |
| 76 | + host, packages, host.get_fact(PkginPackages), present, |
| 77 | + install_command='pkgin -y install', |
| 78 | + uninstall_command='pkgin -y remove', |
| 79 | + upgrade_command='pkgin -y upgrade', |
| 80 | + latest=latest, |
| 81 | + ) |
0 commit comments