From a330a3f47f8e176e708259a518cb8874d34401b9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Nov 2007 18:51:02 +0000 Subject: [PATCH] Switch to using custom make system for PyQt compilation --- src/libprs500/gui2/Makefile | 27 ---------- src/libprs500/gui2/make.py | 104 ++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 27 deletions(-) delete mode 100644 src/libprs500/gui2/Makefile create mode 100644 src/libprs500/gui2/make.py diff --git a/src/libprs500/gui2/Makefile b/src/libprs500/gui2/Makefile deleted file mode 100644 index fde86b6f73..0000000000 --- a/src/libprs500/gui2/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -UI = main_ui.py dialogs/metadata_single_ui.py dialogs/metadata_bulk_ui.py dialogs/jobs_ui.py \ - dialogs/conversion_error_ui.py dialogs/lrf_single_ui.py dialogs/choose_format_ui.py \ - dialogs/password_ui.py lrf_renderer/main_ui.py lrf_renderer/config_ui.py \ - dialogs/fetch_metadata_ui.py -RC = images_rc.pyc - -PYUIC = $(shell which pyuic4) - -%_ui.py : %.ui - ${PYUIC} $< | sed "s/import images_rc/from libprs500.gui2 import images_rc/" | \ - sed "s/from library import/from libprs500.gui2.library import/"> $@ - -%_rc.pyc : %.qrc % - pyrcc4 $< > $*_rc.py - python -c "import compiler; compiler.compileFile('$*_rc.py')" - -all : $(UI) $(RC) - - -clean : - rm -f $(UI) $(RC) - -test : all - python main.py - -lrfviewer: all - python lrf_renderer/main.py diff --git a/src/libprs500/gui2/make.py b/src/libprs500/gui2/make.py new file mode 100644 index 0000000000..02850a2906 --- /dev/null +++ b/src/libprs500/gui2/make.py @@ -0,0 +1,104 @@ +## Copyright (C) 2007 Kovid Goyal kovid@kovidgoyal.net +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License along +## with this program; if not, write to the Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +''' +Manage the PyQt build system pyrcc4, pylupdate4, lrelease and friends. +''' + +import sys, os, subprocess, cStringIO, compiler +from functools import partial + +from PyQt4.uic import compileUi + +check_call = partial(subprocess.check_call, shell=True) + +def find_forms(): + forms = [] + for root, dirs, files in os.walk('.'): + for name in files: + if name.endswith('.ui'): + forms.append(os.path.abspath(os.path.join(root, name))) + + return forms + +def form_to_compiled_form(form): + return form.rpartition('.')[0]+'_ui.py' + +def build_forms(forms): + for form in forms: + compiled_form = form_to_compiled_form(form) + if not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime: + print 'Compiling form', form + buf = cStringIO.StringIO() + compileUi(form, buf) + dat = buf.getvalue() + dat = dat.replace('import images_rc', 'from libprs500.gui2 import images_rc') + dat = dat.replace('from library import', 'from libprs500.gui2.library import') + open(compiled_form, 'wb').write(dat) + +def build_images(): + newest = 0 + for root, dirs, files in os.walk('./images'): + for name in files: + newest = max(os.stat(os.path.join(root, name)).st_mtime, newest) + + newest = max(newest, os.stat('images.qrc').st_mtime) + + if not os.path.exists('images_rc.py') or newest > os.stat('images_rc.py').st_mtime: + print 'Compiling images' + check_call(' '.join(['pyrcc4', '-o', 'images_rc.py', 'images.qrc'])) + compiler.compileFile('images_rc.py') + os.utime('images_rc.py', None) + os.utime('images_rc.pyc', None) + + +def build(forms): + build_forms(forms) + build_images() + +def clean(forms): + for form in forms: + compiled_form = form_to_compiled_form(form) + if os.path.exists(compiled_form): + print 'Removing compiled form', compiled_form + os.unlink(compiled_form) + print 'Removing compiled images' + os.unlink('images_rc.py') + os.unlink('images_rc.pyc') + +def main(args=sys.argv): + + if not os.getcwd().endswith('gui2'): + raise Exception('Must be run from the gui2 directory') + + forms = find_forms() + if len(args) == 1: + args.append('all') + + if args[1] == 'all': + build(forms) + elif args[1] == 'clean': + clean(forms) + elif args[1] == 'test': + build(forms) + print 'Running main.py' + subprocess.call('python main.py', shell=True) + else: + print 'Usage: %s [clean|test|all]'%(args[0]) + return 1 + + return 0 + +if __name__ == '__main__': + sys.exit(main()) \ No newline at end of file