Source code for meta_package_manager.managers.chocolatey
# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.## This program is Free Software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.from__future__importannotationsimportrefromtypingimportIteratorfromextra_platformsimportWINDOWSfrommeta_package_manager.baseimportPackage,PackageManagerfrommeta_package_manager.capabilitiesimportversion_not_implemented
[docs]classChoco(PackageManager):name="Chocolatey"homepage_url="https://chocolatey.org"platforms=WINDOWSrequirement="2.0.0""""``2.0.0`` is the first version which is not requiring the ``--local-only`` option, which has been entirely removed. Source: `choco options and switches <https://docs.chocolatey.org/en-us/guides/upgrading-to-chocolatey-v2-v6#the-list-command-now-lists-local-packages-only-and-the-local-only-and-lo-options-have-been-removed>`_. """post_args=("--no-progress","--no-color")""" .. code-block:: shell-session ► choco --version 0.11.0 """@propertydefinstalled(self)->Iterator[Package]:"""Fetch installed packages. .. code-block:: shell-session ► choco list --limit-output --no-progress --no-color adobereader|11.0.10 ccleaner|5.03.5128 chocolatey|0.9.9.2 ConEmu|14.9.23.0 gimp|2.8.14.1 git|1.9.5.20150114 """output=self.run_cli("list","--limit-output")regexp=re.compile(r"(.+)\|(.+)")forpackageinoutput.splitlines():match=regexp.match(package)ifmatch:package_id,installed_version=match.groups()yieldself.package(id=package_id,installed_version=installed_version)@propertydefoutdated(self)->Iterator[Package]:"""Fetch outdated packages. .. code-block:: shell-session ► choco outdated --limit-output --no-progress --no-color 7zip.commandline|16.02.0.20170209|16.02.0.20170209|false 7zip.portable|18.1|18.1|false atom|1.23.3|1.24.0|false autohotkey.portable|1.1.28.00|1.1.28.00|false bulkrenameutility|3.0.0.1|3.0.0.1|false bulkrenameutility.install|3.0.0.1|3.0.0.1|false calibre|3.17.0|3.17.0|false chocolatey|0.10.8|0.10.8|false """output=self.run_cli("outdated","--limit-output")regexp=re.compile(r"(.+)\|(.+)\|(.+)\|.+")forpackageinoutput.splitlines():match=regexp.match(package)ifmatch:package_id,installed_version,latest_version=match.groups()yieldself.package(id=package_id,latest_version=latest_version,installed_version=installed_version,)
[docs]defupgrade_all_cli(self)->tuple[str,...]:"""Generates the CLI to upgrade all packages (default) or only the one provided as parameter. .. code-block:: shell-session ► choco upgrade all --yes --limit-output --no-progress --no-color """returnself.build_cli("upgrade","all","--yes","--limit-output")
@version_not_implementeddefupgrade_one_cli(self,package_id:str,version:str|None=None,)->tuple[str,...]:"""Generates the CLI to upgrade all packages (default) or only the one provided as parameter. .. code-block:: shell-session ► choco upgrade ccleaner --yes --limit-output --no-progress --no-color """returnself.build_cli("upgrade",package_id,"--yes","--limit-output")