Now turns file into pythonfile that can uncompress itself
This commit is contained in:
parent
31c13127be
commit
75b9478935
@ -1,7 +1,30 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
import zipfile
|
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
|
# https://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory-in-python
|
||||||
def zipdir(path, ziph):
|
def zipdir(path, ziph):
|
||||||
# ziph is zipfile handle
|
# ziph is zipfile handle
|
||||||
@ -34,11 +57,16 @@ if __name__ == '__main__':
|
|||||||
zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
|
zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
|
||||||
zipdir(dir_path, zipf)
|
zipdir(dir_path, zipf)
|
||||||
zipf.close()
|
zipf.close()
|
||||||
|
|
||||||
print('All files zipped successfully!')
|
print('All files zipped successfully!')
|
||||||
some_bytes = get_bytes_from_file("Python.zip")
|
some_bytes = get_bytes_from_file("Python.zip")
|
||||||
|
'''
|
||||||
print(some_bytes)
|
print(some_bytes)
|
||||||
write_bytes('Python2.zip', some_bytes)
|
write_bytes('Python2.zip', some_bytes)
|
||||||
unzip_file("Python.zip", "./what")
|
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
|
## Peach Pie is from https://ccsearch.creativecommons.org/photos/fe32017c-df1b-455c-9784-0f9b3a141717
|
Loading…
Reference in New Issue
Block a user