Skip to content

Commit

Permalink
Added checks to see if we have pyuic4 and pyrcc4 in the path
Browse files Browse the repository at this point in the history
  • Loading branch information
g-sherman committed Oct 5, 2014
1 parent d1540c3 commit 1f14e24
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 27 deletions.
63 changes: 38 additions & 25 deletions pb_tool/pb_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import click

from util import check_path

@click.group()
def cli():
Expand Down Expand Up @@ -61,7 +62,7 @@ def get_install_files(cfg):
@cli.command()
def version():
"""Return the version of pb_tool and exit"""
click.echo("1.0, 2014-10-01")
click.echo("1.1, 2014-10-04")


@cli.command()
Expand Down Expand Up @@ -435,31 +436,43 @@ def compile_files(cfg):
# TODO add changed detection
#cfg = get_config(config)

ui_files = cfg.get('files', 'compiled_ui_files').split()
ui_count = 0
for ui in ui_files:
if os.path.exists(ui):
(base, ext) = os.path.splitext(ui)
output = "{}.py".format(base)
print "Compiling {} to {}".format(ui, output)
subprocess.check_call(['pyuic4', '-o', output, ui])
ui_count += 1
else:
print "{} does not exist---skipped".format(ui)
print "Compiled {} UI files".format(ui_count)
# check to see if we have pyuic4
pyuic4 = check_path('pyuic4')

res_files = cfg.get('files', 'resource_files').split()
res_count = 0
for res in res_files:
if os.path.exists(res):
(base, ext) = os.path.splitext(res)
output = "{}_rc.py".format(base)
print "Compiling {} to {}".format(res, output)
subprocess.check_call(['pyrcc4', '-o', output, res])
res_count += 1
else:
print "{} does not exist---skipped".format(res)
print "Compiled {} resource files".format(res_count)
if not pyuic4:
print "pyuic4 is not in your path---unable to compile your ui files"
else:
ui_files = cfg.get('files', 'compiled_ui_files').split()
ui_count = 0
for ui in ui_files:
if os.path.exists(ui):
(base, ext) = os.path.splitext(ui)
output = "{}.py".format(base)
print "Compiling {} to {}".format(ui, output)
subprocess.check_call(['pyuic4', '-o', output, ui])
ui_count += 1
else:
print "{} does not exist---skipped".format(ui)
print "Compiled {} UI files".format(ui_count)

# check to see if we have pyrcc4
pyrcc4 = check_path('pyrcc4')

if not pyrcc4:
print "pyrcc4 is not in your path---unable to compile your resource file(s)"
else:
res_files = cfg.get('files', 'resource_files').split()
res_count = 0
for res in res_files:
if os.path.exists(res):
(base, ext) = os.path.splitext(res)
output = "{}_rc.py".format(base)
print "Compiling {} to {}".format(res, output)
subprocess.check_call(['pyrcc4', '-o', output, res])
res_count += 1
else:
print "{} does not exist---skipped".format(res)
print "Compiled {} resource files".format(res_count)


def copy(source, destination):
Expand Down
4 changes: 2 additions & 2 deletions pb_tool/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name='pb_tool',
version='1.0',
version='1.1',
description='A tool to aid in QGIS Python plugin development',
url='https://github.com/g-sherman/plugin_build_tool',
author='Gary Sherman',
Expand All @@ -36,7 +36,7 @@
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Topic :: Scientific/Engineering :: GIS'],
keywords='QGIS PyQGIS',
py_modules=['pb_tool'],
py_modules=['pb_tool', 'util'],
install_requires=[
'Click',
'nose'
Expand Down
44 changes: 44 additions & 0 deletions pb_tool/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
/***************************************************************************
pb_tool utilities
A tool for building and deploying QGIS plugins
-------------------
begin : 2014-09-24
copyright : (C) 2014 by GeoApt LLC
email : gsherman@geoapt.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
def check_path(app):
""" Adapted form StackExchange:
http://stackoverflow.com/questions/377017
"""
import os
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)

def ext_candidates(fpath):
yield fpath
for ext in os.environ.get("PATHEXT", "").split(os.pathsep):
yield fpath + ext

fpath, fname = os.path.split(app)
if fpath:
if is_exe(app):
return app
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, app)
for candidate in ext_candidates(exe_file):
if is_exe(candidate):
return candidate

return None

0 comments on commit 1f14e24

Please sign in to comment.