Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions android_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@
except ImportError:
DEVNULL = open(os.devnull, 'w')

def checkForPath(command):
return 0 == subprocess.call([
command, "--version"
], stdout=DEVNULL, stderr=subprocess.STDOUT)

def check_for_path(command):
try:
subprocess.check_call([
command, "--version"
], stdout=DEVNULL, stderr=subprocess.STDOUT)
return True

except OSError: # thrown if path not exists
return False

except subprocess.CalledProcessError: # any other execution error
return True


def error(msg):
sys.stderr.write((unicode(msg) + "\n").encode("UTF-8"))
Expand Down Expand Up @@ -178,11 +188,11 @@ def add_density_option(self, name, dpi):
error("Please enter a resource name")
if not options.densities:
error("Select at least one DPI variant to export")
if not checkForPath("inkscape"):
if not check_for_path("inkscape"):
error("Make sure you have 'inkscape' on your PATH")
if options.strip and not checkForPath("convert"):
if options.strip and not check_for_path("convert"):
error("Make sure you have 'convert' on your PATH if you want to reduce the image size using ImageMagick")
if options.optimize and not checkForPath("optipng"):
if options.optimize and not check_for_path("optipng"):
error("Make sure you have 'optipng' on your PATH if you want to reduce the image size using OptiPNG")

export(svg, options)