"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "snapcraft/internal/repo/_deb.py" between
snapcraft-4.5.1.tar.gz and snapcraft-4.5.2.tar.gz

About: Snapcraft is a build and packaging tool that makes it easy to incorporate components from different sources and build technologies or solutions.

_deb.py  (snapcraft-4.5.1):_deb.py  (snapcraft-4.5.2)
skipping to change at line 19 skipping to change at line 19
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import fileinput import fileinput
import functools import functools
import io
import logging import logging
import os import os
import pathlib import pathlib
import re import re
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
from typing import Dict, List, Optional, Set, Tuple # noqa: F401 from typing import Dict, List, Optional, Set, Tuple # noqa: F401
from typing_extensions import Final
from xdg import BaseDirectory from xdg import BaseDirectory
from snapcraft import file_utils from snapcraft import file_utils
from snapcraft.internal import os_release
from snapcraft.internal.indicators import is_dumb_terminal from snapcraft.internal.indicators import is_dumb_terminal
from snapcraft.project._project_options import ProjectOptions
from . import apt_ppa, errors from . import errors
from ._base import BaseRepo, get_pkg_name_parts from ._base import BaseRepo, get_pkg_name_parts
if sys.platform == "linux": if sys.platform == "linux":
# Ensure importing works on non-Linux. # Ensure importing works on non-Linux.
from .apt_cache import AptCache from .apt_cache import AptCache
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
_DEB_CACHE_DIR: pathlib.Path = pathlib.Path( _DEB_CACHE_DIR: pathlib.Path = pathlib.Path(
BaseDirectory.save_cache_path("snapcraft", "download") BaseDirectory.save_cache_path("snapcraft", "download")
skipping to change at line 202 skipping to change at line 198
def _run_dpkg_query_list_files(package_name: str) -> Set[str]: def _run_dpkg_query_list_files(package_name: str) -> Set[str]:
output = ( output = (
subprocess.check_output(["dpkg", "-L", package_name]) subprocess.check_output(["dpkg", "-L", package_name])
.decode(sys.getfilesystemencoding()) .decode(sys.getfilesystemencoding())
.strip() .strip()
.split() .split()
) )
return {i for i in output if ("lib" in i and os.path.isfile(i))} return {i for i in output if ("lib" in i and os.path.isfile(i))}
def _get_host_arch() -> str:
return ProjectOptions().deb_arch
def _get_dpkg_list_path(base: str) -> pathlib.Path: def _get_dpkg_list_path(base: str) -> pathlib.Path:
return pathlib.Path(f"/snap/{base}/current/usr/share/snappy/dpkg.list") return pathlib.Path(f"/snap/{base}/current/usr/share/snappy/dpkg.list")
def get_packages_in_base(*, base: str) -> List[str]: def get_packages_in_base(*, base: str) -> List[str]:
# We do not want to break what we already have. # We do not want to break what we already have.
if base in ("core", "core16", "core18"): if base in ("core", "core16", "core18"):
return _DEFAULT_FILTERED_STAGE_PACKAGES return _DEFAULT_FILTERED_STAGE_PACKAGES
base_package_list_path = _get_dpkg_list_path(base) base_package_list_path = _get_dpkg_list_path(base)
if not base_package_list_path.exists(): if not base_package_list_path.exists():
skipping to change at line 229 skipping to change at line 222
package_list = list() package_list = list()
with fileinput.input(str(base_package_list_path)) as fp: with fileinput.input(str(base_package_list_path)) as fp:
for line in fp: for line in fp:
if not line.startswith("ii "): if not line.startswith("ii "):
continue continue
package_list.append(line.split()[1]) package_list.append(line.split()[1])
# format of package_list is <package_name>[:<architecture>] # format of package_list is <package_name>[:<architecture>]
return package_list return package_list
def _sudo_write_file(*, dst_path: pathlib.Path, content: bytes) -> None:
"""Workaround for writing to privileged files."""
with tempfile.NamedTemporaryFile() as src_f:
src_f.write(content)
src_f.flush()
try:
command = [
"sudo",
"install",
"--owner=root",
"--group=root",
"--mode=0644",
src_f.name,
str(dst_path),
]
subprocess.check_call(command)
except subprocess.CalledProcessError:
raise RuntimeError(f"failed to run: {command!r}")
class Ubuntu(BaseRepo): class Ubuntu(BaseRepo):
_SNAPCRAFT_INSTALLED_SOURCES_LIST: Final[
str
] = "/etc/apt/sources.list.d/snapcraft.list"
@classmethod @classmethod
def get_package_libraries(cls, package_name: str) -> Set[str]: def get_package_libraries(cls, package_name: str) -> Set[str]:
return _run_dpkg_query_list_files(package_name) return _run_dpkg_query_list_files(package_name)
@classmethod @classmethod
def get_package_for_file(cls, file_path: str) -> str: def get_package_for_file(cls, file_path: str) -> str:
return _run_dpkg_query_search(file_path) return _run_dpkg_query_search(file_path)
@classmethod @classmethod
def get_packages_for_source_type(cls, source_type): def get_packages_for_source_type(cls, source_type):
skipping to change at line 474 skipping to change at line 443
@classmethod @classmethod
def get_installed_packages(cls) -> List[str]: def get_installed_packages(cls) -> List[str]:
with AptCache() as apt_cache: with AptCache() as apt_cache:
return [ return [
f"{pkg_name}={pkg_version}" f"{pkg_name}={pkg_version}"
for pkg_name, pkg_version in apt_cache.get_installed_packages(). items() for pkg_name, pkg_version in apt_cache.get_installed_packages(). items()
] ]
@classmethod @classmethod
def install_ppa(cls, ppa: str) -> bool:
owner, name = apt_ppa.split_ppa_parts(ppa=ppa)
codename = os_release.OsRelease().version_codename()
return any(
[
cls.install_sources(
components=["main"],
formats=["deb"],
name=f"ppa-{owner}_{name}",
suites=[codename],
url=f"http://ppa.launchpad.net/{owner}/{name}/ubuntu",
),
]
)
@classmethod
def _construct_deb822_source(
cls,
*,
architectures: Optional[List[str]] = None,
components: Optional[List[str]] = None,
formats: Optional[List[str]] = None,
suites: List[str],
url: str,
) -> str:
with io.StringIO() as deb822:
if formats:
type_text = " ".join(formats)
else:
type_text = "deb"
print(f"Types: {type_text}", file=deb822)
print(f"URIs: {url}", file=deb822)
suites_text = " ".join(suites)
print(f"Suites: {suites_text}", file=deb822)
if components:
components_text = " ".join(components)
print(f"Components: {components_text}", file=deb822)
if architectures:
arch_text = " ".join(architectures)
else:
arch_text = _get_host_arch()
print(f"Architectures: {arch_text}", file=deb822)
return deb822.getvalue()
@classmethod
def install_sources(
cls,
*,
architectures: Optional[List[str]] = None,
components: Optional[List[str]] = None,
formats: Optional[List[str]] = None,
name: str,
suites: List[str],
url: str,
) -> bool:
config = cls._construct_deb822_source(
architectures=architectures,
components=components,
formats=formats,
suites=suites,
url=url,
)
if name not in ["default", "default-security"]:
name = "snapcraft-" + name
config_path = pathlib.Path(f"/etc/apt/sources.list.d/{name}.sources")
if config_path.exists() and config_path.read_text() == config:
# Already installed and matches, nothing to do.
logger.debug(f"Ignoring unchanged sources: {config_path}")
return False
_sudo_write_file(dst_path=config_path, content=config.encode())
logger.debug(f"Installed sources: {config_path}")
return True
@classmethod
def _extract_deb_name_version(cls, deb_path: pathlib.Path) -> str: def _extract_deb_name_version(cls, deb_path: pathlib.Path) -> str:
try: try:
output = subprocess.check_output( output = subprocess.check_output(
["dpkg-deb", "--show", "--showformat=${Package}=${Version}", deb _path] ["dpkg-deb", "--show", "--showformat=${Package}=${Version}", deb _path]
) )
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
raise errors.UnpackError(deb_path) raise errors.UnpackError(deb_path)
return output.decode().strip() return output.decode().strip()
 End of changes. 9 change blocks. 
117 lines changed or deleted 1 lines changed or added

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