Skip to content

Instantly share code, notes, and snippets.

@csprance
Forked from Farfarer/xNormalHelpers.py
Created January 12, 2016 17:58
Show Gist options
  • Save csprance/2cd2d921e225fb0da20d to your computer and use it in GitHub Desktop.
Save csprance/2cd2d921e225fb0da20d to your computer and use it in GitHub Desktop.
Just a few helper bits for xNormal/python.
#!/usr/bin/env python
import lx
import subprocess
import os
# Paths for xNormal.
path_xnormal_basedir = r'C:\Program Files\Santiago Orgaz'
path_xnormal_exedir = r'\x64\xNormal.exe'
path_xnormal = r'C:\Program Files\Santiago Orgaz\xNormal 3.18.9\x64\xNormal.exe'
path_xml = r'C:\Temp\xNormalBatcher.xml'
'''Return the last error listed by xNormal.'''
def getXNormalError ():
filename = os.path.expanduser (r'~\Documents\xNormal\xNormal_debugLog.txt')
if os.path.lexists (filename):
with open (filename) as f:
for line in f:
try:
line_error = line.split('-> ')[1].rstrip()
except:
pass
else:
return line_error
return 'Unknown error'
'''Call xNormal at path_xnormal with the batch XML at the location defined in path_xml variable.'''
def callXNormal ():
xNormal_process_call = [path_xnormal, path_xml]
p = subprocess.Popen (xNormal_process_call, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate ()
rc = p.returncode
if rc == 0:
# Return code of 0 means success.
pass
else:
# Otherwise, xNormal failed to bake.
# So grab the error from the debug log, if it exists.
xNormalError = getXNormalError ()
if xNormalError == 'Aborted by user':
# User aborted the bake.
# Might want to do different stuff here?
lx.out ('xNormal: %s.' % xNormalError)
else:
# Some other error.
lx.out ('xNormal: %s.' % xNormalError)
'''Get a list of installed xNormal versions.'''
def listXNormalVersions ():
xNormalVersions = []
for xndir in os.listdir (path_xnormal_basedir):
if os.path.lexists (path_xnormal_basedir + '\\' + xndir + path_xnormal_exedir):
xNormalVersions.append (xndir)
# Sort list by version in descending order.
xNormalVersions.sort(key=lambda s: map(int, s.split(' ')[1].split('.')))
xNormalVersions = self.xNormalVersions[::-1]
# xNormalVersions now contains just the versions of xNormal installs as a list in descending order of release.
# e.g. ['3.18.10', '3.10.17', '3.8.6']
# You could present these to the user as options or something?
if len(xNormalVersions) != 0:
# If we found at least one version, assign path_xnormal to be the latest installed version of xNormal.
global path_xnormal
path_xnormal = path_xnormal_basedir + '\\' + self.xNormalVersions[0] + path_xnormal_exedir
lx.out ('Defaulting xNormal to %s.' % self.xNormalVersions[0])
else:
lx.out('Unable to find any xNormal installs.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment