Created
December 28, 2010 00:01
-
-
Save jlintz/756716 to your computer and use it in GitHub Desktop.
Print out a count of focal lengths from canon raw image files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Author: Justin Lintz | |
# usage: ./focal_length dir | |
# Requiresments: dcraw http://www.cybercom.net/~dcoffin/dcraw/ | |
import os | |
import sys | |
from subprocess import Popen, PIPE | |
from operator import itemgetter | |
focals = {} | |
DCRAW='/path/to/dcraw' | |
def process_files(filelist): | |
for filename in filelist: | |
p = Popen([DCRAW,'-i','-v',filename],stdout=PIPE) | |
for line in p.stdout: | |
if line.startswith('Focal'): | |
length = line.split(':')[1].strip() | |
focal = length[:-2] | |
if focal in focals : | |
focals[focal] = focals[focal] + 1 | |
else: | |
focals[focal] = 1 | |
def get_raw_files(path): | |
file_list = [] | |
for root,dirs,files in os.walk(path): | |
for filename in files: | |
if filename.endswith('CR2'): | |
file_list.append(os.path.join(root,filename)) | |
return file_list | |
def main(): | |
files = get_raw_files(sys.argv[1]) | |
print 'Total pics to process: %d' % len(files) | |
process_files(files) | |
sorted_list = sorted(focals.items(),key=itemgetter(1),reverse=True) | |
for length,count in sorted_list: | |
print 'Length: %s , Count: %d' % (length,count) | |
return 0 | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment