Now turns file into pythonfile that can uncompress itself

This commit is contained in:
Paul Mullins 2020-04-02 03:31:18 -04:00
parent 31c13127be
commit 75b9478935
1 changed files with 31 additions and 3 deletions

View File

@ -2,6 +2,29 @@
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")
'''
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