You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
image_to_script.py: recursive
This commit is contained in:
+11
-11
@@ -7,11 +7,9 @@ try:
|
||||
except IndexError:
|
||||
print('No file or directory given using current working directory')
|
||||
input_file = os.getcwd()
|
||||
|
||||
|
||||
def run(in_file):
|
||||
output_file = os.path.splitext(in_file)[0] + '.py'
|
||||
|
||||
ext = os.path.splitext(in_file)[1][1:]
|
||||
|
||||
with open(in_file, 'rb') as f:
|
||||
@@ -33,17 +31,19 @@ _{ext} = bytearray(binascii.unhexlify(
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(output)
|
||||
|
||||
def process_directory(directory):
|
||||
for root, _, files in os.walk(directory):
|
||||
for file in files:
|
||||
file_ext = os.path.splitext(file)[1][1:]
|
||||
if file_ext not in ('bmp', 'jpg', 'gif', 'png', 'bin', 'MF'):
|
||||
continue
|
||||
|
||||
thisfile = os.path.join(root, file)
|
||||
print('found file:', thisfile)
|
||||
run(thisfile)
|
||||
|
||||
if os.path.isdir(input_file):
|
||||
for file in os.listdir(input_file):
|
||||
file_ext = os.path.splitext(file)[1][1:]
|
||||
if file_ext not in ('bmp', 'jpg', 'gif', 'png', 'bin', 'MF'):
|
||||
continue
|
||||
|
||||
thisfile = os.path.join(input_file, file)
|
||||
print('found file:', thisfile)
|
||||
run(thisfile)
|
||||
|
||||
process_directory(input_file)
|
||||
else:
|
||||
file_ext = os.path.splitext(input_file)[1][1:]
|
||||
if file_ext not in ('bmp', 'jpg', 'gif', 'png', 'bin'):
|
||||
|
||||
Reference in New Issue
Block a user