Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: jpstoryHi
I created a node that removes the read & write password off Excel files. (Basically, the node just launches Excel behind the screen and opens up the file via Excel and removes the password. The password is provided to the node as an input parameter)
It's been working fine until lately it failed on a file that has password of length of 16 characters. The file has the same password for both Read and Write access, the password is in the same pattern as
AbcdEfghijk12345.
But if I set the password to be 15-character long
AbcdEfghijk1234 on purpose and then run the node, it works just fine.
I wonder if it's becasue I chose the wrong data type when set up the paramter, so I tried Text, String and Password but none of them worked.
Here's the code:
import braininfo
import os, sys
import win32com.client
def setup(brainNodeControlObj, BrainNodeClass):
class BrainNode(BrainNodeClass):
def finalize(self, val):
super(BrainNode, self).finalize(val)
#Actions to execute when the class finishes its task
self.xcl.Quit()
self.xcl = None
del self.xcl
def initialize(self):
super(BrainNode, self).initialize()
metadata = self.newMetadata()
metadata.append("FileName","String")
metadata.append("OpenPassword","String")
metadata.append("WritePassword","String")
self.outputs[0].metadata = metadata
metadataExcpt = self.newMetadata()
metadataExcpt.append("FileName","String")
metadataExcpt.append("OpenPassword Tried","String")
metadataExcpt.append("WritePassword Tried","String")
self.outputs[1].metadata = metadataExcpt
#Load Parameters
self.OpenPsWd = self.properties.getString("ls.brain.node.decrypt.openpassword")
self.WritePsWd = self.properties.getString("ls.brain.node.decrypt.writepassword")
def pump(self, quant):
self.xcl = win32com.client.Dispatch('Excel.Application')
while quant.permitsRunning(self):
inRec = self.inputs[0].read()
if not inRec:
return False
filename = inRec["FileName"]
#try:
self.Decrypt(filename)
outRec = self.outputs[0].newRecord()
outRec["FileName"] = filename
outRec["OpenPassword"] = self.OpenPsWd
outRec["WritePassword"] = self.WritePsWd
self.outputs[0].write(outRec)
#except:
#outRec = self.outputs[1].newRecord()
#outRec["FileName"] = filename
#outRec["OpenPassword Tried"] = self.OpenPsWd
#outRec["WritePassword Tried"] = self.OpenPsWd
#self.outputs[1].write(outRec)
return True
#self.xcl.Quit()
def Decrypt(self,filename):
#Open(Filename As String,[UpdateLink],[ReadOnly],[Format],[WriteResPassword],[IgnoreReadOnlyRecommended],[Origin],
#[Delimiter],[Editable],[Notify],[Converter],[AddToMru],[CorruptLoad])
wb = self.xcl.workbooks.open(filename, False, False, None, str(self.OpenPsWd), str(self.WritePsWd))
wb.Password = ""
wb.WritePassword = ""
self.xcl.DisplayAlerts = False
self.xcl.ScreenUpdating = False
wb.Save()
wb.Close()
return BrainNode