#!/usr/bin/env python import os,sys,subprocess def ExtractJad(fname): """This will extract read the manifest-nf and create a jad file that can be loaded by the loader""" #tests check = True if os.path.exists("META-INF") or os.path.exists("META-INF/MANIFEST.MF"): check = False print "There is already a META-INF directory" if not (os.path.exists(fname) and fname.endswith('.jar')): check = False print "invalid filename/file does not exist" if check: prog = subprocess.Popen(['jar','-xf',fname,"META-INF/MANIFEST.MF"]) rc = prog.wait() if rc==0: newname = fname.replace('jar','jad') outdata = "MIDlet-Jar-Size: 100\nMIDlet-Jar-URL: %s\n"%fname oldmanifest = open("META-INF/MANIFEST.MF",'r').read() outdata += oldmanifest newjad = open(newname,'w') newjad.write(outdata) newjad.close() os.unlink("META-INF/MANIFEST.MF") os.rmdir("META-INF") else: print "the .jar did not extract correctly" try: for item in sys.argv[1:]: ExtractJad(item) except IndexError: print "usage: mjad.py filename.jar"