From 75b94789351be1de1a1e4d2b15d7ba6e50cbcba8 Mon Sep 17 00:00:00 2001 From: Paul Mullins Date: Thu, 2 Apr 2020 03:31:18 -0400 Subject: [PATCH] Now turns file into pythonfile that can uncompress itself --- metacompress.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/metacompress.py b/metacompress.py index e53a08a..83ddf6c 100644 --- a/metacompress.py +++ b/metacompress.py @@ -1,7 +1,30 @@ #!/usr/bin/env python import os import zipfile - + +beginning_text = ''' +import os +import zipfile + +# http://www.codecodex.com/wiki/Read_a_file_into_a_byte_array#Python +def write_bytes(write_bytes_where, mah_bytes): + f = open(write_bytes_where, 'wb') + f.write(mah_bytes) + f.close() + +# https://stackoverflow.com/questions/3451111/unzipping-files-in-python +def unzip_file(file_path, output_path): + with zipfile.ZipFile(file_path, 'r') as tyler_perry: + tyler_perry.extractall(output_path) +''' + + +end_text = ''' +write_bytes("mah_bytes.zip", mah_bytes) +unzip_file("mah_bytes.zip", "./what") +''' + + # https://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory-in-python def zipdir(path, ziph): # ziph is zipfile handle @@ -34,11 +57,16 @@ if __name__ == '__main__': zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED) zipdir(dir_path, zipf) zipf.close() - print('All files zipped successfully!') - some_bytes = get_bytes_from_file("Python.zip") + some_bytes = get_bytes_from_file("Python.zip") + ''' print(some_bytes) write_bytes('Python2.zip', some_bytes) unzip_file("Python.zip", "./what") + ''' + with open("supermeta.py", 'a') as out: + out.write(beginning_text + '\n') + out.write("mah_bytes = " + str(some_bytes) + "\n") + out.write(end_text + '\n') ## Peach Pie is from https://ccsearch.creativecommons.org/photos/fe32017c-df1b-455c-9784-0f9b3a141717 \ No newline at end of file