Skip to content

Instantly share code, notes, and snippets.

@celiacintas
Created October 10, 2016 16:10
Show Gist options
  • Save celiacintas/be40beb3e9062ec30bd4b2fe2bbd7ae5 to your computer and use it in GitHub Desktop.
Save celiacintas/be40beb3e9062ec30bd4b2fe2bbd7ae5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# -*- coding: utf-8
import fnmatch
import shutil
import os
import sys
import fileinput
dir_photos = '.'
out_dir = '/tmp/modelos_raw'
def extract_files(dir_photos, out_dir):
for root, dirnames, filenames in os.walk(dir_photos):
for filename in fnmatch.filter(filenames, 'model_*.*'):
file_ = os.path.join(root, filename)
base, extension = os.path.splitext(filename)
prefix = os.path.basename(root)
shutil.copy(file_, os.path.join(out_dir, base + "_" + prefix + extension))
print "Done!"
def change_texture_file(out_dir):
for root, dirnames, filenames in os.walk(out_dir):
for filename in fnmatch.filter(filenames, 'model_*.ply'):
f = fileinput.FileInput(os.path.join(root, filename), inplace=1)
base, extension = os.path.splitext(filename)
for line in f:
line = line.replace("comment TextureFile model_texture.jpg",
"comment TextureFile model_texture_{}.jpg".format(str(base.split("_")[-1])))
print line,
f.close()
print "Done!"
def main():
extract_files(dir_photos, out_dir)
change_texture_file(out_dir)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment