def getSwirl(cls, fileName): """helper function given a filename it return a SwirlFile if the given plugin does not support the given fileName should just return None ATT: only one plugin should return a SwirlFile for a given file """ fd=open(fileName) magic = fd.read(4) if magic == '\x7f\x45\x4c\x46': #it's an elf see specs #http://www.sco.com/developers/gabi/1998-04-29/ch4.eheader.html#elfid swirlFile = SwirlFile( fileName ) swirlFile.setPluginName( cls.pluginName ) swirlFile.dyn = True else: #not an elf return None bitness = fd.read(1) if bitness == '\x01': swirlFile.set32bits() elif bitness == '\x02': swirlFile.set64bits() swirlFile.type = 'ELF' cls._setDepsRequs(swirlFile) return swirlFile
def getSwirl(self, fileName): """helper function given a filename it return a SwirlFile if the given plugin does not support the given fileName should just return None ATT: only one plugin should return a SwirlFile for a given file """ #we call all the getSwirl method of all the plugin for key, plugin in self.plugins.iteritems(): temp = plugin.getSwirl(fileName) if temp != None: return temp #nobady claimed the file let's make it a Data file swirlFile = SwirlFile(fileName) swirlFile.type="Data" return swirlFile
try : f = file(fileName) data = f.read().rstrip().replace("\r\n","\n") lis = parser.suite(data).tolist() except SyntaxError,msg : #print "Not a python file" f.close() return None except : if f: f.close() return None else : swirlFile = SwirlFile( fileName ) swirlFile.setPluginName( cls.pluginName ) swirlFile.type = cls.pluginName swirlFile.dyn = True # # let's check which interpreter should we use # f.seek(0) header = f.readline().rstrip() f.close() pythonVer = None if header[0:2] == '#!': for i in re.split(' |/|!', header): if 'python' in i: pythonVer = i if not pythonVer: pythonVer = cls._prefix for item in cls._getModules(lis) :