aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlistair Bush <ali_bush@gentoo.org>2008-01-03 03:51:40 +0000
committerAlistair Bush <ali_bush@gentoo.org>2008-01-03 03:51:40 +0000
commit1bd09c16dc7883eed2b6708c7e65d565b46393f0 (patch)
treefe9b3a57a3a96f09fecc53bac93f67755a865573
parentStarted setup.py and migrated more tools. (diff)
downloadjavatoolkit-1bd09c16dc7883eed2b6708c7e65d565b46393f0.tar.gz
javatoolkit-1bd09c16dc7883eed2b6708c7e65d565b46393f0.tar.bz2
javatoolkit-1bd09c16dc7883eed2b6708c7e65d565b46393f0.zip
Finalise setup.py, update class-version-verify
svn path=/projects/javatoolkit/branches/layout_refactor_branch/; revision=5885
-rw-r--r--setup.py3
-rwxr-xr-xsrc/py/class-version-verify.py132
-rw-r--r--src/py/javatoolkit/cvv.py6
3 files changed, 49 insertions, 92 deletions
diff --git a/setup.py b/setup.py
index be91a9a..0f75daf 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,8 @@ setup (
"src/py/xml-rewrite-3.py",
"src/py/findclass",
"src/py/xml-rewrite.py",
- "src/py/buildparser"
+ "src/py/buildparser",
+ "src/py/class-version-verify.py"
]
)
diff --git a/src/py/class-version-verify.py b/src/py/class-version-verify.py
index b571c05..4d28e42 100755
--- a/src/py/class-version-verify.py
+++ b/src/py/class-version-verify.py
@@ -8,101 +8,59 @@
# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/bsfix/class-version-verify.py,v 1.2 2005/07/19 10:35:18 axxo Exp $
import os,sys
-from os.path import join, getsize
-from struct import unpack
from optparse import OptionParser, make_option
-from zipfile import ZipFile
+from javatoolkit.cvv import *
-class cvv:
- def __init__(self, target):
- self.target = target
- self.good = []
- self.bad = []
-
- def add(self, version, jar, file):
- if version <= self.target:
- self.good.append(("1."+str(version), jar, file))
- else:
- self.bad.append(("1."+str(version), jar, file))
-
- def do_class(self,filename):
- classFile = file(filename,"rb")
- classFile.seek(4)
-
- temp = classFile.read(4)
- #(version,) = unpack('>i',temp)
- (version,) = unpack('>xxh',temp)
- version-=44
-
- self.add(version, None, filename)
-
- def do_jar(self, filename):
- zipfile = ZipFile(filename, 'r')
-
- for file in zipfile.namelist():
- if file.endswith('class'):
- classFile = zipfile.read(file)
-
- (version,) = unpack('>h',classFile[6:8])
- version-=44
-
- self.add(version, filename, file)
-
- def do_file(self, filename):
- if not os.path.islink(filename):
- if filename.endswith(".class"):
- self.do_class(filename)
- if filename.endswith(".jar"):
- self.do_jar(filename)
-
if __name__ == '__main__':
-
- options_list = [
- make_option ("-r", "--recurse", action="store_true", dest="deep", default=False, help="go into dirs"),
- make_option ("-t", "--target", type="string", dest="version", help="target version that is valid"),
+
+ options_list = [
+ make_option ("-r", "--recurse", action="store_true", dest="deep", default=False, help="go into dirs"),
+ make_option ("-t", "--target", type="string", dest="version", help="target version that is valid"),
+
+ make_option ("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Print version of every calss"),
+ make_option ("-s", "--silent", action="store_true", dest="silent", default=False, help="No output"),
+ make_option ("-f", "--file-only", action="store_true", dest="file_only", default=False, help="Only output the files"),
+ ]
- make_option ("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Print version of every calss"),
- make_option ("-s", "--silent", action="store_true", dest="silent", default=False, help="No output"),
- make_option ("-f", "--file-only", action="store_true", dest="file_only", default=False, help="Only output the files"),
- ]
+ parser = OptionParser("%prog -t version [-r] [-v] [-s] <class/jar files or dir>", options_list)
+ (options, args) = parser.parse_args()
- parser = OptionParser("%prog -t version [-r] [-v] [-s] <class/jar files or dir>", options_list)
- (options, args) = parser.parse_args()
+ if not options.version:
+ print "-t is mandatory"
+ sys.exit(2)
- if not options.version:
- print "-t is mandatory"
- sys.exit(2)
+ options.version = int(options.version.split(".")[-1])
+
+ cvv = cvv(options.version)
- options.version = int(options.version.split(".")[-1])
-
- cvv = cvv(options.version)
+ for arg in args:
+ if os.path.isfile(arg):
+ cvv.do_file(arg)
+
+ if options.deep and os.path.isdir(arg):
+ for root, dirs, files in os.walk(arg):
+ for filename in files:
+ cvv.do_file("%s/%s" % (root, filename))
- for arg in args:
- if os.path.isfile(arg):
- cvv.do_file(arg)
-
- if options.deep and os.path.isdir(arg):
- for root, dirs, files in os.walk(arg):
- for filename in files:
- cvv.do_file("%s/%s" % (root, filename))
+ if options.file_only:
+ lst = set([set[1] for set in cvv.bad])
+ for i in lst:
+ print i
+ else:
- if options.file_only:
- lst = set([set[1] for set in cvv.bad])
- for i in lst:
- print i
- else:
+ if options.verbose:
+ for set in cvv.good:
+ print "Good: %s %s %s" % set
+
+ if not options.silent:
+ for set in cvv.bad:
+ print "Bad: %s %s %s" % set
+
+ print "CVV: %s\nChecked: %i Good: %i Bad: %i" % (options.version, len(cvv.good)+len(cvv.bad) , len(cvv.good), len(cvv.bad))
- if options.verbose:
- for set in cvv.good:
- print "Good: %s %s %s" % set
-
- if not options.silent:
- for set in cvv.bad:
- print "Bad: %s %s %s" % set
-
- print "CVV: %s\nChecked: %i Good: %i Bad: %i" % (options.version, len(cvv.good)+len(cvv.bad) , len(cvv.good), len(cvv.bad))
+ if len(cvv.bad) > 0:
+ sys.exit(1)
+ else:
+ sys.exit(0)
- if len(cvv.bad) > 0:
- sys.exit(1)
- else:
- sys.exit(0)
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/py/javatoolkit/cvv.py b/src/py/javatoolkit/cvv.py
index 20bd16c..de4e21b 100644
--- a/src/py/javatoolkit/cvv.py
+++ b/src/py/javatoolkit/cvv.py
@@ -3,10 +3,8 @@
# Distributed under the terms of the GNU General Public License v2
# $Header: $
-#import os,sys
-#from os.path import join, getsize
-#from struct import unpack
-#from optparse import OptionParser, make_option
+import os,sys
+from struct import unpack
from zipfile import ZipFile
class cvv: