Write __main__ procedure
[pyff3.git] / script.py
blob02f1ea47c1f05df8ab5d86992f3189f24712c994
1 #!/usr/bin/env python
3 from optparse import OptionParser
4 import os
5 from stat import *
7 import lib
9 # the interpolate method should take a steps and button argument!!!
10 # maybe it does...
13 def for_every_file(top1, top2, my_function):
14 '''recursively descend the directory tree rooted at top,
15 calling the my_function function for each regular file'''
17 def font_times_directory(font0, directory):
18 for dirpath, dirnames, filenames in os.walk(directory):
19 for font1 in filenames:
21 font_times_my_font = lib.InterpolateFonts(os.path.join(dirpath, font0), os.path.join(dirpath, font1), options.button, options.steps)
22 font_times_my_font.font_info()
23 font_times_my_font.interpolate()
25 def directory_times_directory(directory0, directory1):
26 for dirpath0, dirnames0, filenames0 in os.walk(directory0):
27 for myfont0 in filenames0:
28 for dirpath1, dirnames1, filenames1 in os.walk(directory1):
29 for myfont1 in filenames1:
31 myfont0_times_myfont1 = lib.InterpolateFonts(os.path.join(dirpath0, myfont0), os.path.join(dirpath1, myfont1), options.button, options.steps)
32 myfont0_times_myfont1.font_info()
33 myfont0_times_myfont1.interpolate()
35 if __name__ == "__main__":
37 gui = OptionParser()
38 gui.add_option("-s", "--steps", action="store", type="int", dest="steps")
39 gui.add_option("-b", "--button", action="store", dest="button")
40 (options, paths) = gui.parse_args()
42 mode0 = os.stat(paths[0])[ST_MODE]
43 mode1 = os.stat(paths[1])[ST_MODE]
45 if S_ISDIR(mode0) and S_ISDIR(mode1):
46 directory_times_directory(paths[0], paths[1])
47 elif S_ISREG(mode0):
48 font_times_directory(paths[0], paths[1])
49 elif S_ISREG(mode1):
50 font_times_directory(paths[1], paths[0])
53 # myfont1_times_myfont0 = lib.InterpolateFonts(os.path.join(dirpath1, myfont1), os.path.join(dirpath0, myfont0), options.button, options.steps)
54 # myfont1_times_myfont0.font_info()
55 # myfont1_times_myfont0.interpolate()