From 0b8a6ee568d6f83a3a657831f7fcb783d3fab971 Mon Sep 17 00:00:00 2001 From: Gunter Miegel Date: Mon, 31 May 2021 13:10:57 +0200 Subject: [PATCH] Create plugin.py rework archive filename (#36) * Print name of created Coinboot plugin archive * Fix quoting, reformat with Black --- debirf/scripts/create_plugin.py | 95 +++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/debirf/scripts/create_plugin.py b/debirf/scripts/create_plugin.py index a0d9e026..83b6ed0b 100755 --- a/debirf/scripts/create_plugin.py +++ b/debirf/scripts/create_plugin.py @@ -34,60 +34,76 @@ from subprocess import call from docopt import docopt -DPKG_STATUS = '/var/lib/dpkg/status' -INITIAL_DPKG_STATUS = '/tmp/initial_status' -FINAL_DPKG_STATUS = '/tmp/dpkg_status' -PLUGIN_DIR = '/mnt/plugin/rootfs' - -EXCLUDE = ('/dev/', - '/proc/', - '/run/', - '/sys/', - '/tmp/', - '/usr/src', - '/usr/include', - '/usr/share/dbus-1/system-services', - '/vagrant', - '/var/cache', - '/var/lib/apt/lists', - '/var/lib/dpkg/[^info]', - '/var/log', - '.*__pycache__.*', - '.wget-hsts', - '.*\.cache' - ) +DPKG_STATUS = "/var/lib/dpkg/status" +INITIAL_DPKG_STATUS = "/tmp/initial_status" +FINAL_DPKG_STATUS = "/tmp/dpkg_status" +PLUGIN_DIR = "/mnt/plugin/rootfs" + +EXCLUDE = ( + "/dev/", + "/proc/", + "/run/", + "/sys/", + "/tmp/", + "/usr/src", + "/usr/include", + "/usr/share/dbus-1/system-services", + "/vagrant", + "/var/cache", + "/var/lib/apt/lists", + "/var/lib/dpkg/[^info]", + "/var/log", + ".*__pycache__.*", + ".wget-hsts", + ".*\.cache", +) def find(path_to_walk): """Return results similar to the Unix find command run without options i.e. traverse a directory tree and return all the file paths """ - return [os.path.join(path, file) - for (path, dirs, files) in os.walk(path_to_walk) - for file in files] + return [ + os.path.join(path, file) + for (path, dirs, files) in os.walk(path_to_walk) + for file in files + ] + def main(arguments): - #print(arguments) - if arguments['start']: - call(['cp', '-v', DPKG_STATUS, INITIAL_DPKG_STATUS]) - elif arguments['finish']: - f = open(FINAL_DPKG_STATUS, 'w') - call(['dpkg_status.py', '--old', INITIAL_DPKG_STATUS, '--new', DPKG_STATUS, '--diff'], stdout=f) + # print(arguments) + if arguments["start"]: + call(["cp", "-v", DPKG_STATUS, INITIAL_DPKG_STATUS]) + elif arguments["finish"]: + f = open(FINAL_DPKG_STATUS, "w") + call( + [ + "dpkg_status.py", + "--old", + INITIAL_DPKG_STATUS, + "--new", + DPKG_STATUS, + "--diff", + ], + stdout=f, + ) files_for_plugin_archive = [] for path in find(PLUGIN_DIR): - cleaned_path = re.sub(PLUGIN_DIR, '', path) + cleaned_path = re.sub(PLUGIN_DIR, "", path) # FIXME: Switch to re.match() against path without PLUGIN_DIR prefix if any(re.findall(pattern, cleaned_path) for pattern in EXCLUDE): - print('Excluded:', cleaned_path) + print("Excluded:", cleaned_path) else: - print('Included:', cleaned_path) + print("Included:", cleaned_path) files_for_plugin_archive.append(cleaned_path) files_for_plugin_archive.append(FINAL_DPKG_STATUS) - archive_name = arguments[''] + ".tar.gz + + archive_name = arguments[""] + ".tar.gz" + tar = tarfile.open(archive_name, "w:gz") for path in files_for_plugin_archive: # If a file was deleted which was in the lower directory @@ -100,11 +116,12 @@ def main(arguments): # the archive to get an absolute path wit a leading '/' tar.add(path, arcname=path) else: - print('Whiteout file from lower dir:', path) + print("Whiteout file from lower dir:", path) tar.close() - print('Created Coinboot Plugin:', archive_name) + print("Created Coinboot Plugin:", archive_name) + -if __name__ == '__main__': - arguments = docopt(__doc__, version='Create Coinboot Plugins v0.1') +if __name__ == "__main__": + arguments = docopt(__doc__, version="Create Coinboot Plugins v0.1") main(arguments)