Skip to content

Commit

Permalink
Create plugin.py rework archive filename (#36)
Browse files Browse the repository at this point in the history
* Print name of created Coinboot plugin archive

* Fix quoting, reformat with Black
  • Loading branch information
frzb authored May 31, 2021
1 parent 66d28c8 commit 0b8a6ee
Showing 1 changed file with 56 additions and 39 deletions.
95 changes: 56 additions & 39 deletions debirf/scripts/create_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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['<plugin_name>'] + ".tar.gz

archive_name = arguments["<plugin_name>"] + ".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
Expand All @@ -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)

0 comments on commit 0b8a6ee

Please sign in to comment.