All pastes #1080630 Raw Edit

Simple script for Roman Sharp

public python v1 · immutable
#1080630 ·published 2008-07-23 11:00 UTC
rendered paste body
#!/usr/bin/env python2.5import sys, os, time, shutil messages = {"help": "Help: Use jadsize file.jad", "filePermissionError": "Permission Error",            "jarFileError": "jar-file error"}def getParam():    if (len(sys.argv) != 2) or sys.argv[1].lower() in ("-h", "--help"):        print messages["help"]; sys.exit(0)    return sys.argv[1]def getJarSize(file_):    jar = os.path.abspath(file_)[:-1]+"r"    if os.path.exists(jar):        return os.path.getsize(jar)    print messages["jarFileError"], jar; sys.exit(0)def newJad(jad, size):    f = open(jad)    newjad = ["MIDlet-Jar-Size: %d\n" % size if "MIDlet-Jar-Size: " in line else line for line in f]    f.close; f = open(jad, "w"); map(lambda x: f.write(x), newjad); f.close()def run():    jad = getParam(); jarsize = getJarSize(jad)    #backup old file    timestamp = reduce(lambda x, y: str(x)+str(y), time.localtime()[:6])    shutil.copy2(jad, jad[:-4]+timestamp+jad[-4:])    newJad(jad, jarsize)    if __name__ == "__main__":    run()