Member since
02-28-2018
2
Posts
0
Kudos Received
0
Solutions
03-09-2018
06:12 PM
@Matt Burgess, @John T: I got this working in Python, my first ever such program ,so it might be rough around the edges. The nifi processor expects input from listFile, not getFile, as it uses zipfile, which wants a file to read. The code: import zipfile
from org.apache.nifi.processor.io import InputStreamCallback
class ReadVersion(InputStreamCallback)
def __init__(self):
self.ff = None
self.version = ''
self.error = ''
def process(self,inputStream):
try:
zipname = self.ff.getAttribute('filename')
zippath = self.ff.getAttribute('absolute.path')
zfile = zipfile.ZipFile(zippath+zipname)
for name in zfile.namelist():
if (name == 'docProps/app.xml'):
inFile = zfile.open(name)
inContents = infile.read()
loc = inContents.find('<AppVersion>1')
if (loc != -1):
keyChar = inContents[loc+13:loc+14]
if (keyChar == '2'):
self.version = '2007'
elif (keyChar == '4'):
self.version = '2010'
elif (keyChar == '5'):
self.version = '2013'
elif (keyChar == '6'):
self.version = '2016'
else:
log.warn('Unexpected AppVersion value: ',inContents[loc+12:loc+14])
except:
log.warn('exception thrown (is this really a zip file?)')
self.error = 'error'
ff = session.get()
if (ff != None):
callback = ReadVersion()
callback.ff = ff
session.read(ff, callback)
if (callback.version != ''):
ff = session.putAttribute(ff,'MSVersion',callback.version)
session.transfer(ff, REL_SUCCESS)
if (callback.error == 'error'):
session.transfer(ff, REL_FAILURE)
... View more
03-05-2018
07:29 PM
@Matt Burgess Doing a trick like this to determine the MS version of a file would also be useful to me in my Nifi flow, so I'm keeping an eye on this.
... View more