From 0df079707118df72ba1131f53ace18d1561e0d17 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Thu, 5 Nov 2015 14:39:41 +0000 Subject: Move copy_file functionality into base. --- vmdebootstrap/base.py | 10 ++++++++++ vmdebootstrap/filesystem.py | 16 +++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'vmdebootstrap') diff --git a/vmdebootstrap/base.py b/vmdebootstrap/base.py index 279e5bc..0a302a4 100644 --- a/vmdebootstrap/base.py +++ b/vmdebootstrap/base.py @@ -22,6 +22,7 @@ import os import crypt +import shutil import cliapp import logging import subprocess @@ -74,6 +75,15 @@ def delete_password(rootdir, user): runcmd(['chroot', rootdir, 'passwd', '-d', user]) +def copy_files(src, dest): + for filename in os.listdir(src): + if os.path.isdir(filename) or os.path.islink(filename): + continue + shutil.copyfile( + os.path.join(src, filename), + os.path.join(dest, filename)) + + class Base(object): name = 'base' diff --git a/vmdebootstrap/filesystem.py b/vmdebootstrap/filesystem.py index 23c7fef..df3e7b5 100644 --- a/vmdebootstrap/filesystem.py +++ b/vmdebootstrap/filesystem.py @@ -22,10 +22,13 @@ import os -import shutil import cliapp import logging -from vmdebootstrap.base import Base, runcmd +from vmdebootstrap.base import ( + Base, + runcmd, + copy_files +) # pylint: disable=missing-docstring @@ -184,7 +187,7 @@ class Filesystem(Base): '-no-progress', '-comp', 'xz'], ignore_fail=False) logging.debug(msg) check_size = os.path.getsize(suffixed) - logging.debug("Created squashfs: %s" % suffixed) + logging.debug("Created squashfs: %s", suffixed) if check_size < (1024 * 1024): logging.warning( "%s appears to be too small! %s bytes", @@ -194,12 +197,7 @@ class Filesystem(Base): bootdir = os.path.join(self.devices['rootdir'], 'boot') # copying the boot/* files self.message("Copying boot files out of squashfs") - for filename in os.listdir(bootdir): - if os.path.isdir(filename) or os.path.islink(filename): - continue - shutil.copyfile( - os.path.join(bootdir, filename), - os.path.join(self.settings['squash'], filename)) + copy_files(bootdir, self.settings['squash']) def configure_apt(self): rootdir = self.devices['rootdir'] -- cgit v1.2.1