Replace unsquashfs with unpackfs

Conflicts:
	src/modules/unsquashfs/unsquashfs.conf
This commit is contained in:
Philip 2014-08-19 11:30:59 +02:00 committed by Teo Mrnjavac
parent ea32ba6a83
commit 37426b9f7a
5 changed files with 48 additions and 27 deletions

View File

@ -31,7 +31,7 @@ install:
#- dummypython #- dummypython
- partition - partition
- mount - mount
- unsquashfs - unpackfs
- fstab - fstab
- locale - locale
- keyboard - keyboard

View File

@ -3,6 +3,8 @@
# === This file is part of Calamares - <http://github.com/calamares> === # === This file is part of Calamares - <http://github.com/calamares> ===
# #
# Copyright 2014, Teo Mrnjavac <teo@kde.org> # Copyright 2014, Teo Mrnjavac <teo@kde.org>
# Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org>
# Copyright 2014, Philip Müller <philm@manjaro.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
@ -28,10 +30,11 @@ from collections import namedtuple
from libcalamares import * from libcalamares import *
class UnpackEntry: class UnpackEntry:
__slots__= ['source', 'destination', 'copied', 'total'] __slots__= ['source', 'sourcefs', 'destination', 'copied', 'total']
def __init__(self, source, destination): def __init__(self, source, sourcefs, destination):
self.source = source self.source = source
self.sourcefs = sourcefs
self.destination = destination self.destination = destination
self.copied = 0 self.copied = 0
self.total = 0 self.total = 0
@ -86,7 +89,7 @@ def file_copy(source, dest, progress_cb):
return None return None
class UnsquashOperation: class UnpackOperation:
def __init__(self, entries): def __init__(self, entries):
self.entries = entries self.entries = entries
@ -110,33 +113,43 @@ class UnsquashOperation:
source_mount_path = tempfile.mkdtemp() source_mount_path = tempfile.mkdtemp()
try: try:
for entry in self.entries: for entry in self.entries:
sqfslist = subprocess.check_output(["unsquashfs",
"-l",
entry.source])
entry.total = len(sqfslist.splitlines())
imgbasename = os.path.splitext( imgbasename = os.path.splitext(
os.path.basename(entry.source))[0] 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)
self.mount_image(entry, imgmountdir)
if entry.sourcefs == "squashfs":
sqfslist = subprocess.check_output(["unsquashfs",
"-l",
entry.source])
entry.total = len(sqfslist.splitlines())
if entry.sourcefs == "ext4":
fslist = subprocess.check_output(["ls", "-1",
imgmountdir])
entry.total = len(fslist.splitlines())
self.report_progress() self.report_progress()
error_msg = self.unsquash_image(entry, imgmountdir) error_msg = self.unpack_image(entry, imgmountdir)
if error_msg: if error_msg:
return ("Failed to unsquash {}".format(entry.source), return ("Failed to unpack image {}".format(entry.source),
error_msg) error_msg)
return None return None
finally: finally:
shutil.rmtree(source_mount_path) shutil.rmtree(source_mount_path)
def unsquash_image(self, entry, imgmountdir): def mount_image(self, entry, imgmountdir):
subprocess.check_call(["mount",
entry.source,
imgmountdir,
"-t", entry.sourcefs, "-o", "loop"])
def unpack_image(self, entry, imgmountdir):
def progress_cb(copied): def progress_cb(copied):
entry.copied = copied entry.copied = copied
self.report_progress() self.report_progress()
subprocess.check_call(["mount",
entry.source,
imgmountdir,
"-t", "squashfs", "-o", "loop"])
try: try:
return file_copy(imgmountdir, return file_copy(imgmountdir,
entry.destination, entry.destination,
@ -149,13 +162,15 @@ def run():
# from globalstorage: rootMountPoint # from globalstorage: rootMountPoint
# from job.configuration: # from job.configuration:
# the path to where to mount the source image(s) for copying # the path to where to mount the source image(s) for copying
# an ordered list of unpack mappings for sqfs file <-> target dir relative # an ordered list of unpack mappings for image file <-> target dir relative
# to rootMountPoint, e.g.: # to rootMountPoint, e.g.:
# configuration: # configuration:
# unpack: # unpack:
# - source: "/path/to/squashfs/image.sqfs" # - source: "/path/to/filesystem.img"
# sourcefs: "ext4"
# destination: "" # destination: ""
# - source: "/path/to/another/image.sqfs" # - source: "/path/to/another/filesystem.sqfs"
# sourcefs: "squashfs"
# destination: "" # destination: ""
root_mount_point = globalstorage.value("rootMountPoint") root_mount_point = globalstorage.value("rootMountPoint")
@ -171,15 +186,17 @@ def run():
for entry in job.configuration["unpack"]: for entry in job.configuration["unpack"]:
source = os.path.abspath(entry["source"]) source = os.path.abspath(entry["source"])
sourcefs = entry["sourcefs"]
destination = os.path.abspath(root_mount_point + entry["destination"]) destination = os.path.abspath(root_mount_point + entry["destination"])
if not os.path.isfile(source): if not os.path.isfile(source):
return ("Bad source", "source=\"{}\"".format(source)) return ("Bad source", "source=\"{}\"".format(source))
# Add test for supported filesystems
if not os.path.isdir(destination): if not os.path.isdir(destination):
return ("Bad destination", return ("Bad destination",
"destination=\"{}\"".format(destination)) "destination=\"{}\"".format(destination))
unpack.append(UnpackEntry(source, destination)) unpack.append(UnpackEntry(source, sourcefs, destination))
unsquashop = UnsquashOperation(unpack) unpackop = UnpackOperation(unpack)
return unsquashop.run() return unpackop.run()

View File

@ -1,6 +1,6 @@
# Syntax is YAML 1.2 # Syntax is YAML 1.2
--- ---
type: "job" type: "job"
name: "unsquashfs" name: "unpackfs"
interface: "python" interface: "python"
script: "main.py" #assumed relative to the current directory script: "main.py" #assumed relative to the current directory

View File

@ -0,0 +1,8 @@
---
unpack:
- source: "/path/to/filesystem.img"
sourcefs: "ext4"
destination: ""
- source: "/path/to/another/filesystem.sqfs"
sourcefs: "squashfs"
destination: ""

View File

@ -1,4 +0,0 @@
---
unpack:
- source: "/path/to/squashfs/image.sqfs"
destination: ""