forked from fogleman/Minecraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode.py
33 lines (29 loc) · 785 Bytes
/
encode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import base64
EXTENSIONS = [
'.png',
]
def print_data(data):
size = 72
offset = 0
length = len(data)
while offset < length:
print ' "%s"' % data[offset:offset+size]
offset += size
def generate(folder):
print '# Automatically generated file!'
print 'from wx.lib.embeddedimage import PyEmbeddedImage'
print
for name in os.listdir(folder):
if name[-4:] not in EXTENSIONS:
continue
path = os.path.join(folder, name)
base = name[:-4]
with open(path, 'rb') as f:
encoded = base64.b64encode(f.read())
print '%s = PyEmbeddedImage(' % base
print_data(encoded)
print ')'
print
if __name__ == '__main__':
generate('.')