Write font_times_directory
[pyff3.git] / script.py
blob07f854ce426b4e4941009e5165a5797cb8df5bd3
1 #!/usr/bin/env python
3 from optparse import OptionParser
4 import os
6 import lib
8 # the interpolate method should take a steps and button argument!!!
9 # maybe it does...
12 def for_every_file(top1, top2, my_function):
13 '''recursively descend the directory tree rooted at top,
14 calling the my_function function for each regular file'''
16 for f1 in os.listdir(top1):
17 for f2 in os.listdir(top2):
18 pathname = os.path.join(top2, f2)
19 mode = os.stat(pathname)[ST_MODE]
20 if S_ISDIR(mode):
21 # It's a directory, recurse into it
22 for_every_file(f1, f2, my_function)
23 elif S_ISREG(mode):
24 # It's a file, call the my_function function
25 my_function(f1, f2)
26 else:
27 # Unknown file type, print a message
28 print 'Skipping %s' % pathname
30 def font_times_directory(font0, directory):
31 for dirpath, dirnames, filenames in os.walk(directory):
32 for font1 in filenames:
34 font_times_my_font = lib.InterpolateFonts(os.path.join(dirpath, font0), os.path.join(dirpath, font1), options.button, options.steps)
35 font_times_my_font.font_info()
36 font_times_my_font.interpolate()
38 def directory_times_directory(directory0, directory1):
39 for dirpath0, dirnames0, filenames0 in os.walk(directory0):
40 for myfont0 in filenames0:
41 for dirpath1, dirnames1, filenames1 in os.walk(directory1):
42 for myfont1 in filenames1:
44 myfont0_times_myfont1 = lib.InterpolateFonts(os.path.join(dirpath0, myfont0), os.path.join(dirpath1, myfont1), options.button, options.steps)
45 myfont0_times_myfont1.font_info()
46 myfont0_times_myfont1.interpolate()
48 if __name__ == "__main__":
50 gui = OptionParser()
51 gui.add_option("-s", "--steps", action="store", type="int", dest="steps")
52 gui.add_option("-b", "--button", action="store", dest="button")
53 (options, paths) = gui.parse_args()
55 if font0 and font1 are directories:
56 directory_times_directory(font0, font1)
57 elif font0 is file:
58 font_times_directory(font0, font1):
59 elif font1 is file:
60 font_times_directory(font1, font0):
63 # myfont1_times_myfont0 = lib.InterpolateFonts(os.path.join(dirpath1, myfont1), os.path.join(dirpath0, myfont0), options.button, options.steps)
64 # myfont1_times_myfont0.font_info()
65 # myfont1_times_myfont0.interpolate()