To the best of my knowledge there is no method to get this information in the fmeobjects API, but you can check the version of the Python interpreter itself:
import sys
is64bit = sys.maxsize > 2**32
if is64bit:
print "FME is 64-bit version"
else:
print "FME is 32-bit version"
This works because the 32-bit version of FME can only work with the 32-bit version of Python, etc.
Hi @taojunabc
Another possibility is to check the log file since the version is mentioned in there:
import fme
import fmeobjects
import re
def checkVersion(feature):
log_file = fmeobjects.FMELogFile()
name_log_file = log_file.getFileName()
with open(name_log_file, 'r') as f:
content = f.read().replace('\n','')
try:
line = re.search('(?<=\|INFORM\|FME \d{4}\.\d\.\d\.\d \().*?(?=\))', content).group(0)
version = re.search('\d+$', line).group(0)
log_file.logMessageString('The version of FME is {}'.format(version), fmeobjects.FME_WARN)
except:
log_file.logMessageString('The version could not be found', fmeobjects.FME_ERROR)
I added an idea to provide this information in the fme-module:
https://knowledge.safe.com/idea/40450/add-3264-bit-information-to-python-module-fme.html
To the best of my knowledge there is no method to get this information in the fmeobjects API, but you can check the version of the Python interpreter itself:
import sys
is64bit = sys.maxsize > 2**32
if is64bit:
print "FME is 64-bit version"
else:
print "FME is 32-bit version"
This works because the 32-bit version of FME can only work with the 32-bit version of Python, etc.
Nice and clean solution!
Hi @taojunabc
Another possibility is to check the log file since the version is mentioned in there:
import fme
import fmeobjects
import re
def checkVersion(feature):
log_file = fmeobjects.FMELogFile()
name_log_file = log_file.getFileName()
with open(name_log_file, 'r') as f:
content = f.read().replace('\n','')
try:
line = re.search('(?<=\|INFORM\|FME \d{4}\.\d\.\d\.\d \().*?(?=\))', content).group(0)
version = re.search('\d+$', line).group(0)
log_file.logMessageString('The version of FME is {}'.format(version), fmeobjects.FME_WARN)
except:
log_file.logMessageString('The version could not be found', fmeobjects.FME_ERROR)
I added an idea to provide this information in the fme-module:
https://knowledge.safe.com/idea/40450/add-3264-bit-information-to-python-module-fme.html
Just be aware that the log file doesn't exist yet if you try to call this in e.g. the startup script or in a scripted parameter.
To the best of my knowledge there is no method to get this information in the fmeobjects API, but you can check the version of the Python interpreter itself:
import sys
is64bit = sys.maxsize > 2**32
if is64bit:
print "FME is 64-bit version"
else:
print "FME is 32-bit version"
This works because the 32-bit version of FME can only work with the 32-bit version of Python, etc.
@david_r
Very simple solution, Nice! Thanks.
I watched the FME installation directory, found that some of these documents are different, there is a shw.dll file to install directory under 32bit fme for example, there is a shw64.dll file to install directory under the 64, I think it can also be used to determine the file exists to determine the current FME version. Although this method is can not guarantee the future version after the upgrade also is useful.
import os,fme
is64bit = os.path.exists(fme.macroValuesa'FME_HOME']+'shw64.dll')
if is64bit:
print "FME is 64-bit version"
else:
print "FME is 32-bit version"
Hi @taojunabc
Another possibility is to check the log file since the version is mentioned in there:
import fme
import fmeobjects
import re
def checkVersion(feature):
log_file = fmeobjects.FMELogFile()
name_log_file = log_file.getFileName()
with open(name_log_file, 'r') as f:
content = f.read().replace('\n','')
try:
line = re.search('(?<=\|INFORM\|FME \d{4}\.\d\.\d\.\d \().*?(?=\))', content).group(0)
version = re.search('\d+$', line).group(0)
log_file.logMessageString('The version of FME is {}'.format(version), fmeobjects.FME_WARN)
except:
log_file.logMessageString('The version could not be found', fmeobjects.FME_ERROR)
I added an idea to provide this information in the fme-module:
https://knowledge.safe.com/idea/40450/add-3264-bit-information-to-python-module-fme.html
@jeroenstiers ,Thanks. You offer a different approach.
But, as @david_r says, the log files may not exist at the beginning.
My method is to place a simple workspace in the same directory, then call it by WorkspaceRunner, and then read the log file. This ensures the existence of log file.
sub.fmw
get-fme-platform.fmw
In addition, I improved the regular expression, it will look more simple.
platform = re.search('FME Platform: (.+?)
', content).group(1)
@david_r
Today, When I check out the new fme python api document, I found that FME api provides a “FME_BUILD_STRING” property in the fmeobjects class.This property is also valid in 2017.
http://docs.safe.com/fme/html/fmepython/api/fmeobjects/constants.html
import fmeobjects
def GetBuildString(feature):
feature.setAttribute('bulidString',fmeobjects.FME_BUILD_STRING)
@david_r
Very simple solution, Nice! Thanks.
I watched the FME installation directory, found that some of these documents are different, there is a shw.dll file to install directory under 32bit fme for example, there is a shw64.dll file to install directory under the 64, I think it can also be used to determine the file exists to determine the current FME version. Although this method is can not guarantee the future version after the upgrade also is useful.
import os,fme
is64bit = os.path.exists(fme.macroValues<'FME_HOME']+'shw64.dll')
if is64bit:
print "FME is 64-bit version"
else:
print "FME is 32-bit version"
Yeah, I wouldn't recommend doing this, too many assumptions for my taste.
@david_r
Today, When I check out the new fme python api document, I found that FME api provides a “FME_BUILD_STRING” property in the fmeobjects class.This property is also valid in 2017.
http://docs.safe.com/fme/html/fmepython/api/fmeobjects/constants.html
import fmeobjects
def GetBuildString(feature):
feature.setAttribute('bulidString',fmeobjects.FME_BUILD_STRING)
Good find, thanks for sharing.