"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/modules/opkg.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

opkg.py  (salt-3002.1):opkg.py  (salt-3002.2)
skipping to change at line 18 skipping to change at line 18
<module-provider-override>`. <module-provider-override>`.
.. versionadded: 2016.3.0 .. versionadded: 2016.3.0
.. note:: .. note::
For version comparison support on opkg < 0.3.4, the ``opkg-utils`` package For version comparison support on opkg < 0.3.4, the ``opkg-utils`` package
must be installed. must be installed.
""" """
import copy import copy
import errno import errno
import logging import logging
import os import os
import re import re
from pathlib import Path from pathlib import Path
import salt.utils.args import salt.utils.args
import salt.utils.data import salt.utils.data
import salt.utils.files import salt.utils.files
import salt.utils.itertools import salt.utils.itertools
import salt.utils.path import salt.utils.path
import salt.utils.pkg import salt.utils.pkg
import salt.utils.stringutils import salt.utils.stringutils
import salt.utils.versions import salt.utils.versions
from salt.exceptions import CommandExecutionError, MinionError, SaltInvocationEr ror from salt.exceptions import CommandExecutionError, MinionError, SaltInvocationEr ror
from salt.ext.six.moves import map # pylint: disable=import-error,redefined-bui ltin
from salt.ext.six.moves import shlex_quote as _cmd_quote # pylint: disable=impo rt-error from salt.ext.six.moves import shlex_quote as _cmd_quote # pylint: disable=impo rt-error
REPO_REGEXP = r'^#?\s*(src|src/gz)\s+([^\s<>]+|"[^<>]+")\s+[^\s<>]+' REPO_REGEXP = r'^#?\s*(src|src/gz)\s+([^\s<>]+|"[^<>]+")\s+[^\s<>]+'
OPKG_CONFDIR = "/etc/opkg" OPKG_CONFDIR = "/etc/opkg"
ATTR_MAP = { ATTR_MAP = {
"Architecture": "arch", "Architecture": "arch",
"Homepage": "url", "Homepage": "url",
"Installed-Time": "install_date_time_t", "Installed-Time": "install_date_time_t",
"Maintainer": "packager", "Maintainer": "packager",
"Package": "name", "Package": "name",
skipping to change at line 1214 skipping to change at line 1216
cmd.append(_cmd_quote(pkg1)) cmd.append(_cmd_quote(pkg1))
cmd.append(oper) cmd.append(oper)
cmd.append(_cmd_quote(pkg2)) cmd.append(_cmd_quote(pkg2))
retcode = __salt__["cmd.retcode"]( retcode = __salt__["cmd.retcode"](
cmd, output_loglevel="trace", ignore_retcode=True, python_shell=Fals e cmd, output_loglevel="trace", ignore_retcode=True, python_shell=Fals e
) )
if retcode == 0: if retcode == 0:
return ret return ret
return None return None
def _set_repo_option(repo, option):
"""
Set the option to repo
"""
if not option:
return
opt = option.split("=")
if len(opt) != 2:
return
if opt[0] == "trusted":
repo["trusted"] = opt[1] == "yes"
else:
repo[opt[0]] = opt[1]
def _set_repo_options(repo, options):
"""
Set the options to the repo.
"""
delimiters = "[", "]"
pattern = "|".join(map(re.escape, delimiters))
for option in options:
splitted = re.split(pattern, option)
for opt in splitted:
_set_repo_option(repo, opt)
def _create_repo(line, filename):
"""
Create repo
"""
repo = {}
if line.startswith("#"):
repo["enabled"] = False
line = line[1:]
else:
repo["enabled"] = True
cols = salt.utils.args.shlex_split(line.strip())
repo["compressed"] = not cols[0] in "src"
repo["name"] = cols[1]
repo["uri"] = cols[2]
repo["file"] = os.path.join(OPKG_CONFDIR, filename)
if len(cols) > 3:
_set_repo_options(repo, cols[3:])
return repo
def _read_repos(conf_file, repos, filename, regex):
"""
Read repos from configuration file
"""
for line in conf_file:
line = salt.utils.stringutils.to_unicode(line)
if not regex.search(line):
continue
repo = _create_repo(line, filename)
# do not store duplicated uri's
if repo["uri"] not in repos:
repos[repo["uri"]] = [repo]
def list_repos(**kwargs): # pylint: disable=unused-argument def list_repos(**kwargs): # pylint: disable=unused-argument
""" """
Lists all repos on ``/etc/opkg/*.conf`` Lists all repos on ``/etc/opkg/*.conf``
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
salt '*' pkg.list_repos salt '*' pkg.list_repos
""" """
repos = {} repos = {}
regex = re.compile(REPO_REGEXP) regex = re.compile(REPO_REGEXP)
for filename in os.listdir(OPKG_CONFDIR): for filename in os.listdir(OPKG_CONFDIR):
if filename.endswith(".conf"): if not filename.endswith(".conf"):
with salt.utils.files.fopen( continue
os.path.join(OPKG_CONFDIR, filename) with salt.utils.files.fopen(os.path.join(OPKG_CONFDIR, filename)) as con
) as conf_file: f_file:
for line in conf_file: _read_repos(conf_file, repos, filename, regex)
line = salt.utils.stringutils.to_unicode(line)
if regex.search(line):
repo = {}
if line.startswith("#"):
repo["enabled"] = False
line = line[1:]
else:
repo["enabled"] = True
cols = salt.utils.args.shlex_split(line.strip())
if cols[0] in "src":
repo["compressed"] = False
else:
repo["compressed"] = True
repo["name"] = cols[1]
repo["uri"] = cols[2]
repo["file"] = os.path.join(OPKG_CONFDIR, filename)
# do not store duplicated uri's
if repo["uri"] not in repos:
repos[repo["uri"]] = [repo]
return repos return repos
def get_repo(repo, **kwargs): # pylint: disable=unused-argument def get_repo(repo, **kwargs): # pylint: disable=unused-argument
""" """
Display a repo from the ``/etc/opkg/*.conf`` Display a repo from the ``/etc/opkg/*.conf``
CLI Examples: CLI Examples:
.. code-block:: bash .. code-block:: bash
skipping to change at line 1290 skipping to change at line 1330
line = salt.utils.stringutils.to_unicode(line) line = salt.utils.stringutils.to_unicode(line)
if regex.search(line): if regex.search(line):
if line.startswith("#"): if line.startswith("#"):
line = line[1:] line = line[1:]
cols = salt.utils.args.shlex_split(line.strip()) cols = salt.utils.args.shlex_split(line.strip())
if repo != cols[1]: if repo != cols[1]:
output.append(salt.utils.stringutils.to_str(line)) output.append(salt.utils.stringutils.to_str(line))
with salt.utils.files.fopen(filepath, "w") as fhandle: with salt.utils.files.fopen(filepath, "w") as fhandle:
fhandle.writelines(output) fhandle.writelines(output)
def _add_new_repo(repo, uri, compressed, enabled=True): def _set_trusted_option_if_needed(repostr, trusted):
"""
Set trusted option to repo if needed
"""
if trusted is True:
repostr += " [trusted=yes]"
elif trusted is False:
repostr += " [trusted=no]"
return repostr
def _add_new_repo(repo, properties):
""" """
Add a new repo entry Add a new repo entry
""" """
repostr = "# " if not enabled else "" repostr = "# " if not properties.get("enabled") else ""
repostr += "src/gz " if compressed else "src " repostr += "src/gz " if properties.get("compressed") else "src "
if " " in repo: if " " in repo:
repostr += '"' + repo + '" ' repostr += '"' + repo + '" '
else: else:
repostr += repo + " " repostr += repo + " "
repostr += uri + "\n" repostr += properties.get("uri")
repostr = _set_trusted_option_if_needed(repostr, properties.get("trusted"))
repostr += "\n"
conffile = os.path.join(OPKG_CONFDIR, repo + ".conf") conffile = os.path.join(OPKG_CONFDIR, repo + ".conf")
with salt.utils.files.fopen(conffile, "a") as fhandle: with salt.utils.files.fopen(conffile, "a") as fhandle:
fhandle.write(salt.utils.stringutils.to_str(repostr)) fhandle.write(salt.utils.stringutils.to_str(repostr))
def _mod_repo_in_file(repo, repostr, filepath): def _mod_repo_in_file(repo, repostr, filepath):
""" """
Replace a repo entry in filepath with repostr Replace a repo entry in filepath with repostr
""" """
with salt.utils.files.fopen(filepath) as fhandle: with salt.utils.files.fopen(filepath) as fhandle:
skipping to change at line 1416 skipping to change at line 1468
if "compressed" in kwargs: if "compressed" in kwargs:
repostr += "src/gz " if kwargs["compressed"] else "src" repostr += "src/gz " if kwargs["compressed"] else "src"
else: else:
repostr += "src/gz" if source["compressed"] else "src" repostr += "src/gz" if source["compressed"] else "src"
repo_alias = kwargs["alias"] if "alias" in kwargs else repo repo_alias = kwargs["alias"] if "alias" in kwargs else repo
if " " in repo_alias: if " " in repo_alias:
repostr += ' "{}"'.format(repo_alias) repostr += ' "{}"'.format(repo_alias)
else: else:
repostr += " {}".format(repo_alias) repostr += " {}".format(repo_alias)
repostr += " {}".format(kwargs["uri"] if "uri" in kwargs else source ["uri"]) repostr += " {}".format(kwargs["uri"] if "uri" in kwargs else source ["uri"])
trusted = kwargs.get("trusted")
repostr = (
_set_trusted_option_if_needed(repostr, trusted)
if trusted is not None
else _set_trusted_option_if_needed(repostr, source.get("trusted"
))
)
_mod_repo_in_file(repo, repostr, source["file"]) _mod_repo_in_file(repo, repostr, source["file"])
elif uri and source["uri"] == uri: elif uri and source["uri"] == uri:
raise CommandExecutionError( raise CommandExecutionError(
"Repository '{}' already exists as '{}'.".format(uri, source["na me"]) "Repository '{}' already exists as '{}'.".format(uri, source["na me"])
) )
if not found: if not found:
# Need to add a new repo # Need to add a new repo
if "uri" not in kwargs: if "uri" not in kwargs:
raise CommandExecutionError( raise CommandExecutionError(
"Repository '{}' not found and no URI passed to create one.".for mat( "Repository '{}' not found and no URI passed to create one.".for mat(
repo repo
) )
) )
properties = {"uri": kwargs["uri"]}
# If compressed is not defined, assume True # If compressed is not defined, assume True
compressed = kwargs["compressed"] if "compressed" in kwargs else True properties["compressed"] = (
kwargs["compressed"] if "compressed" in kwargs else True
)
# If enabled is not defined, assume True # If enabled is not defined, assume True
enabled = kwargs["enabled"] if "enabled" in kwargs else True properties["enabled"] = kwargs["enabled"] if "enabled" in kwargs else Tr
_add_new_repo(repo, kwargs["uri"], compressed, enabled) ue
properties["trusted"] = kwargs.get("trusted")
_add_new_repo(repo, properties)
if "refresh" in kwargs: if "refresh" in kwargs:
refresh_db() refresh_db()
def file_list(*packages, **kwargs): # pylint: disable=unused-argument def file_list(*packages, **kwargs): # pylint: disable=unused-argument
""" """
List the files that belong to a package. Not specifying any packages will List the files that belong to a package. Not specifying any packages will
return a list of _every_ file on the system's package database (not return a list of _every_ file on the system's package database (not
generally recommended). generally recommended).
 End of changes. 11 change blocks. 
31 lines changed or deleted 96 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)