From 3bd0905bc284378e1403bc889742cd51a2bd74f2 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 13 Mar 2011 20:54:25 +0100 Subject: [PATCH] Write __main__ procedure --- script.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/script.py b/script.py index 07f854c..02f1ea4 100755 --- a/script.py +++ b/script.py @@ -2,6 +2,7 @@ from optparse import OptionParser import os +from stat import * import lib @@ -13,20 +14,6 @@ def for_every_file(top1, top2, my_function): '''recursively descend the directory tree rooted at top, calling the my_function function for each regular file''' - for f1 in os.listdir(top1): - for f2 in os.listdir(top2): - pathname = os.path.join(top2, f2) - mode = os.stat(pathname)[ST_MODE] - if S_ISDIR(mode): - # It's a directory, recurse into it - for_every_file(f1, f2, my_function) - elif S_ISREG(mode): - # It's a file, call the my_function function - my_function(f1, f2) - else: - # Unknown file type, print a message - print 'Skipping %s' % pathname - def font_times_directory(font0, directory): for dirpath, dirnames, filenames in os.walk(directory): for font1 in filenames: @@ -52,12 +39,15 @@ if __name__ == "__main__": gui.add_option("-b", "--button", action="store", dest="button") (options, paths) = gui.parse_args() - if font0 and font1 are directories: - directory_times_directory(font0, font1) - elif font0 is file: - font_times_directory(font0, font1): - elif font1 is file: - font_times_directory(font1, font0): + mode0 = os.stat(paths[0])[ST_MODE] + mode1 = os.stat(paths[1])[ST_MODE] + + if S_ISDIR(mode0) and S_ISDIR(mode1): + directory_times_directory(paths[0], paths[1]) + elif S_ISREG(mode0): + font_times_directory(paths[0], paths[1]) + elif S_ISREG(mode1): + font_times_directory(paths[1], paths[0]) # myfont1_times_myfont0 = lib.InterpolateFonts(os.path.join(dirpath1, myfont1), os.path.join(dirpath0, myfont0), options.button, options.steps) -- 2.11.4.GIT