mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-27 17:35:37 -04:00
Merge pull request #738 from siduction/pep8-unpackfs
Fixed pep8 whining in module unpackfs
This commit is contained in:
commit
aa75fda9f2
1 changed files with 58 additions and 30 deletions
|
@ -6,6 +6,7 @@
|
||||||
# Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
# Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||||
# Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org>
|
# Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org>
|
||||||
# Copyright 2014, Philip Müller <philm@manjaro.org>
|
# Copyright 2014, Philip Müller <philm@manjaro.org>
|
||||||
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
||||||
#
|
#
|
||||||
# Calamares is free software: you can redistribute it and/or modify
|
# Calamares is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -31,7 +32,8 @@ from libcalamares import *
|
||||||
|
|
||||||
|
|
||||||
class UnpackEntry:
|
class UnpackEntry:
|
||||||
""" Extraction routine using rsync.
|
"""
|
||||||
|
Extraction routine using rsync.
|
||||||
|
|
||||||
:param source:
|
:param source:
|
||||||
:param sourcefs:
|
:param sourcefs:
|
||||||
|
@ -51,7 +53,8 @@ ON_POSIX = 'posix' in sys.builtin_module_names
|
||||||
|
|
||||||
|
|
||||||
def list_excludes(destination):
|
def list_excludes(destination):
|
||||||
""" List excludes for rsync.
|
"""
|
||||||
|
List excludes for rsync.
|
||||||
|
|
||||||
:param destination:
|
:param destination:
|
||||||
:return:
|
:return:
|
||||||
|
@ -69,7 +72,8 @@ def list_excludes(destination):
|
||||||
|
|
||||||
|
|
||||||
def file_copy(source, dest, progress_cb):
|
def file_copy(source, dest, progress_cb):
|
||||||
""" Extract given image using rsync.
|
"""
|
||||||
|
Extract given image using rsync.
|
||||||
|
|
||||||
:param source:
|
:param source:
|
||||||
:param dest:
|
:param dest:
|
||||||
|
@ -89,7 +93,9 @@ def file_copy(source, dest, progress_cb):
|
||||||
args = ['rsync', '-aHAXr']
|
args = ['rsync', '-aHAXr']
|
||||||
args.extend(list_excludes(dest))
|
args.extend(list_excludes(dest))
|
||||||
args.extend(['--progress', source, dest])
|
args.extend(['--progress', source, dest])
|
||||||
process = subprocess.Popen(args, env=at_env, bufsize=1, stdout=subprocess.PIPE, close_fds=ON_POSIX)
|
process = subprocess.Popen(
|
||||||
|
args, env=at_env, bufsize=1, stdout=subprocess.PIPE, close_fds=ON_POSIX
|
||||||
|
)
|
||||||
|
|
||||||
for line in iter(process.stdout.readline, b''):
|
for line in iter(process.stdout.readline, b''):
|
||||||
# small comment on this regexp.
|
# small comment on this regexp.
|
||||||
|
@ -119,15 +125,16 @@ def file_copy(source, dest, progress_cb):
|
||||||
|
|
||||||
process.wait()
|
process.wait()
|
||||||
|
|
||||||
# 23 is the return code rsync returns if it cannot write extended attributes
|
# 23 is the return code rsync returns if it cannot write extended
|
||||||
# (with -X) because the target file system does not support it, e.g., the
|
# attributes (with -X) because the target file system does not support it,
|
||||||
# FAT EFI system partition. We need -X because distributions using file
|
# e.g., the FAT EFI system partition. We need -X because distributions
|
||||||
# system capabilities and/or SELinux require the extended attributes. But
|
# using file system capabilities and/or SELinux require the extended
|
||||||
# distributions using SELinux may also have SELinux labels set on files
|
# attributes. But distributions using SELinux may also have SELinux labels
|
||||||
# under /boot/efi, and rsync complains about those. The only clean way would
|
# set on files under /boot/efi, and rsync complains about those. The only
|
||||||
# be to split the rsync into one with -X and --exclude /boot/efi and a
|
# clean way would be to split the rsync into one with -X and
|
||||||
# separate one without -X for /boot/efi, but only if /boot/efi is actually
|
# --exclude /boot/efi and a separate one without -X for /boot/efi, but only
|
||||||
# an EFI system partition. For now, this hack will have to do. See also:
|
# if /boot/efi is actually an EFI system partition. For now, this hack will
|
||||||
|
# have to do. See also:
|
||||||
# https://bugzilla.redhat.com/show_bug.cgi?id=868755#c50
|
# https://bugzilla.redhat.com/show_bug.cgi?id=868755#c50
|
||||||
# for the same issue in Anaconda, which uses a similar workaround.
|
# for the same issue in Anaconda, which uses a similar workaround.
|
||||||
if process.returncode != 0 and process.returncode != 23:
|
if process.returncode != 0 and process.returncode != 23:
|
||||||
|
@ -137,7 +144,8 @@ def file_copy(source, dest, progress_cb):
|
||||||
|
|
||||||
|
|
||||||
class UnpackOperation:
|
class UnpackOperation:
|
||||||
""" Extraction routine using unsquashfs.
|
"""
|
||||||
|
Extraction routine using unsquashfs.
|
||||||
|
|
||||||
:param entries:
|
:param entries:
|
||||||
"""
|
"""
|
||||||
|
@ -147,7 +155,9 @@ class UnpackOperation:
|
||||||
self.entry_for_source = dict((x.source, x) for x in self.entries)
|
self.entry_for_source = dict((x.source, x) for x in self.entries)
|
||||||
|
|
||||||
def report_progress(self):
|
def report_progress(self):
|
||||||
""" Pass progress to user interface """
|
"""
|
||||||
|
Pass progress to user interface
|
||||||
|
"""
|
||||||
progress = float(0)
|
progress = float(0)
|
||||||
|
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
|
@ -162,7 +172,8 @@ class UnpackOperation:
|
||||||
job.setprogress(progress)
|
job.setprogress(progress)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Extract given image using unsquashfs.
|
"""
|
||||||
|
Extract given image using unsquashfs.
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
@ -170,7 +181,8 @@ class UnpackOperation:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
imgbasename = os.path.splitext(os.path.basename(entry.source))[0]
|
imgbasename = os.path.splitext(
|
||||||
|
os.path.basename(entry.source))[0]
|
||||||
imgmountdir = os.path.join(source_mount_path, imgbasename)
|
imgmountdir = os.path.join(source_mount_path, imgbasename)
|
||||||
os.mkdir(imgmountdir)
|
os.mkdir(imgmountdir)
|
||||||
|
|
||||||
|
@ -186,10 +198,14 @@ class UnpackOperation:
|
||||||
return ("Failed to unpack image",
|
return ("Failed to unpack image",
|
||||||
msg)
|
msg)
|
||||||
|
|
||||||
fslist = subprocess.check_output(["unsquashfs", "-l", entry.source])
|
fslist = subprocess.check_output(
|
||||||
|
["unsquashfs", "-l", entry.source]
|
||||||
|
)
|
||||||
|
|
||||||
if entry.sourcefs == "ext4":
|
if entry.sourcefs == "ext4":
|
||||||
fslist = subprocess.check_output(["find", imgmountdir, "-type", "f"])
|
fslist = subprocess.check_output(
|
||||||
|
["find", imgmountdir, "-type", "f"]
|
||||||
|
)
|
||||||
|
|
||||||
entry.total = len(fslist.splitlines())
|
entry.total = len(fslist.splitlines())
|
||||||
|
|
||||||
|
@ -197,25 +213,35 @@ class UnpackOperation:
|
||||||
error_msg = self.unpack_image(entry, imgmountdir)
|
error_msg = self.unpack_image(entry, imgmountdir)
|
||||||
|
|
||||||
if error_msg:
|
if error_msg:
|
||||||
return "Failed to unpack image {}".format(entry.source), error_msg
|
return ("Failed to unpack image {}".format(entry.source),
|
||||||
|
error_msg)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(source_mount_path)
|
shutil.rmtree(source_mount_path)
|
||||||
|
|
||||||
def mount_image(self, entry, imgmountdir):
|
def mount_image(self, entry, imgmountdir):
|
||||||
""" Mount given image as loop device.
|
"""
|
||||||
|
Mount given image as loop device.
|
||||||
|
|
||||||
:param entry:
|
:param entry:
|
||||||
:param imgmountdir:
|
:param imgmountdir:
|
||||||
"""
|
"""
|
||||||
if os.path.isdir(entry.source):
|
if os.path.isdir(entry.source):
|
||||||
subprocess.check_call(["mount", "--bind", entry.source, imgmountdir])
|
subprocess.check_call(["mount",
|
||||||
|
"--bind", entry.source,
|
||||||
|
imgmountdir])
|
||||||
else:
|
else:
|
||||||
subprocess.check_call(["mount", entry.source, imgmountdir, "-t", entry.sourcefs, "-o", "loop"])
|
subprocess.check_call(["mount",
|
||||||
|
entry.source,
|
||||||
|
imgmountdir,
|
||||||
|
"-t", entry.sourcefs,
|
||||||
|
"-o", "loop"
|
||||||
|
])
|
||||||
|
|
||||||
def unpack_image(self, entry, imgmountdir):
|
def unpack_image(self, entry, imgmountdir):
|
||||||
""" Unpacks image.
|
"""
|
||||||
|
Unpacks image.
|
||||||
|
|
||||||
:param entry:
|
:param entry:
|
||||||
:param imgmountdir:
|
:param imgmountdir:
|
||||||
|
@ -236,12 +262,13 @@ class UnpackOperation:
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
""" Unsquashes filesystem from given image file.
|
"""
|
||||||
|
Unsquashes filesystem from given image file.
|
||||||
|
|
||||||
from globalstorage: rootMountPoint
|
from globalstorage: rootMountPoint
|
||||||
from job.configuration: the path to where to mount the source image(s) for copying
|
from job.configuration: the path to where to mount the source image(s) for
|
||||||
an ordered list of unpack mappings for image file <-> target dir relative
|
copying an ordered list of unpack mappings for image file <-> target dir
|
||||||
to rootMountPoint, e.g.:
|
relative to rootMountPoint, e.g.:
|
||||||
configuration:
|
configuration:
|
||||||
unpack:
|
unpack:
|
||||||
- source: "/path/to/filesystem.img"
|
- source: "/path/to/filesystem.img"
|
||||||
|
@ -280,7 +307,8 @@ def run():
|
||||||
if os.path.isfile(PATH_PROCFS) and os.access(PATH_PROCFS, os.R_OK):
|
if os.path.isfile(PATH_PROCFS) and os.access(PATH_PROCFS, os.R_OK):
|
||||||
with open(PATH_PROCFS, 'r') as procfile:
|
with open(PATH_PROCFS, 'r') as procfile:
|
||||||
filesystems = procfile.read()
|
filesystems = procfile.read()
|
||||||
filesystems = filesystems.replace("nodev", "").replace("\t", "").splitlines()
|
filesystems = filesystems.replace(
|
||||||
|
"nodev", "").replace("\t", "").splitlines()
|
||||||
|
|
||||||
# Check if the source filesystem is supported
|
# Check if the source filesystem is supported
|
||||||
for fs in filesystems:
|
for fs in filesystems:
|
||||||
|
@ -292,7 +320,7 @@ def run():
|
||||||
|
|
||||||
destination = os.path.abspath(root_mount_point + entry["destination"])
|
destination = os.path.abspath(root_mount_point + entry["destination"])
|
||||||
|
|
||||||
if not os.path.exists(source):
|
if not os.path.exists(source):
|
||||||
return "Bad source", "source=\"{}\"".format(source)
|
return "Bad source", "source=\"{}\"".format(source)
|
||||||
|
|
||||||
if not os.path.isdir(destination):
|
if not os.path.isdir(destination):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue