From 3d422f3da930e1aaea2b2a68e463a0d9c7561784 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Sun, 30 Mar 2014 10:04:46 +0200 Subject: [PATCH] Reduce code redundancy using a generator --- setup.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 7ec11d8f0..6deb47ad6 100755 --- a/setup.py +++ b/setup.py @@ -248,6 +248,13 @@ class picard_build(build): build.run(self) +def ui_files(): + for uifile in glob.glob("ui/*.ui"): + pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0] + pyfile = os.path.join("picard", "ui", pyfile) + yield (uifile, pyfile) + + class picard_build_ui(Command): description = "build Qt UI files and resources" user_options = [] @@ -268,9 +275,7 @@ class picard_build_ui(Command): r'\b_translate\(.*?, (.*?), None\)') ) - for uifile in glob.glob("ui/*.ui"): - pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0] - pyfile = os.path.join("picard", "ui", pyfile) + for uifile, pyfile in ui_files(): if newer(uifile, pyfile): log.info("compiling %s -> %s", uifile, pyfile) tmp = StringIO() @@ -298,9 +303,7 @@ class picard_clean_ui(Command): def run(self): from PyQt4 import uic - for uifile in glob.glob("ui/*.ui"): - pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0] - pyfile = os.path.join("picard", "ui", pyfile) + for uifile, pyfile in ui_files(): try: os.unlink(pyfile) log.info("removing %s", pyfile)