fixup rebuildUi script to allow selection of specific ui files to rebuild
This commit is contained in:
parent
39ebc6717d
commit
6ea2bce484
@ -1,30 +1,53 @@
|
|||||||
import os, sys
|
"""
|
||||||
## Search the package tree for all .ui files, compile each to
|
Script for compiling Qt Designer .ui files to .py
|
||||||
## a .py for pyqt and pyside
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
import os, sys, subprocess, tempfile
|
||||||
|
|
||||||
pyqtuic = 'pyuic4'
|
pyqtuic = 'pyuic4'
|
||||||
pysideuic = 'pyside-uic'
|
pysideuic = 'pyside-uic'
|
||||||
pyqt5uic = 'pyuic5'
|
pyqt5uic = 'pyuic5'
|
||||||
|
|
||||||
for path, sd, files in os.walk('.'):
|
usage = """Compile .ui files to .py for all supported pyqt/pyside versions.
|
||||||
|
|
||||||
|
Usage: python rebuildUi.py [.ui files|search paths]
|
||||||
|
|
||||||
|
May specify a list of .ui files and/or directories to search recursively for .ui files.
|
||||||
|
"""
|
||||||
|
|
||||||
|
args = sys.argv[1:]
|
||||||
|
if len(args) == 0:
|
||||||
|
print usage
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
uifiles = []
|
||||||
|
for arg in args:
|
||||||
|
if os.path.isfile(arg) and arg.endswith('.ui'):
|
||||||
|
uifiles.append(arg)
|
||||||
|
elif os.path.isdir(arg):
|
||||||
|
# recursively search for ui files in this directory
|
||||||
|
for path, sd, files in os.walk(arg):
|
||||||
for f in files:
|
for f in files:
|
||||||
base, ext = os.path.splitext(f)
|
if not f.endswith('.ui'):
|
||||||
if ext != '.ui':
|
|
||||||
continue
|
continue
|
||||||
ui = os.path.join(path, f)
|
uifiles.append(os.path.join(path, f))
|
||||||
|
else:
|
||||||
py = os.path.join(path, base + '_pyqt.py')
|
print('Argument "%s" is not a directory or .ui file.' % arg)
|
||||||
if not os.path.exists(py) or os.stat(ui).st_mtime > os.stat(py).st_mtime:
|
sys.exit(-1)
|
||||||
os.system('%s %s > %s' % (pyqtuic, ui, py))
|
|
||||||
print(py)
|
|
||||||
|
|
||||||
py = os.path.join(path, base + '_pyside.py')
|
|
||||||
if not os.path.exists(py) or os.stat(ui).st_mtime > os.stat(py).st_mtime:
|
|
||||||
os.system('%s %s > %s' % (pysideuic, ui, py))
|
|
||||||
print(py)
|
|
||||||
|
|
||||||
py = os.path.join(path, base + '_pyqt5.py')
|
|
||||||
if not os.path.exists(py) or os.stat(ui).st_mtime > os.stat(py).st_mtime:
|
|
||||||
os.system('%s %s > %s' % (pyqt5uic, ui, py))
|
|
||||||
print(py)
|
|
||||||
|
|
||||||
|
# rebuild all requested ui files
|
||||||
|
for ui in uifiles:
|
||||||
|
base, _ = os.path.splitext(ui)
|
||||||
|
for compiler, ext in [(pyqtuic, '_pyqt.py'), (pysideuic, '_pyside.py'), (pyqt5uic, '_pyqt5.py')]:
|
||||||
|
py = base + ext
|
||||||
|
if os.path.exists(py) and os.stat(ui).st_mtime <= os.stat(py).st_mtime:
|
||||||
|
print("Skipping %s; already compiled." % py)
|
||||||
|
else:
|
||||||
|
cmd = '%s %s > %s' % (compiler, ui, py)
|
||||||
|
print(cmd)
|
||||||
|
try:
|
||||||
|
subprocess.check_call(cmd, shell=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
os.remove(py)
|
||||||
|
Loading…
Reference in New Issue
Block a user