-
Notifications
You must be signed in to change notification settings - Fork 2
/
usefixedserialVersionUID.py
27 lines (26 loc) · 1.03 KB
/
usefixedserialVersionUID.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python
#coding=utf-8
import os
import io
import re
import hashlib
curdirname = os.path.dirname(os.path.abspath(__file__))
print (curdirname)
jsonjavapath = os.path.join(curdirname, "flinketl/src/main/java/com/kedacom/flinketlgraph/json")
print (jsonjavapath)
for root,dirs,files in os.walk(jsonjavapath):
for file in files:
filefullpath = os.path.join(root,file)
print(filefullpath)
strfile = ""
with io.open(filefullpath, 'r', encoding="utf-8") as f:
strfile = f.read()
classnames = re.findall(r'public class (.*) implements', strfile)
serivalid = re.findall(r'final static long serialVersionUID = (.*)L;', strfile)
if len(classnames)!=1 or len(serivalid)!=1:
x = 1/0
newid = int(hashlib.md5(classnames[0].encode("utf-8")).hexdigest()[0:10], 16)
print (classnames[0], serivalid[0], newid)
strfile = strfile.replace(serivalid[0], "%d" % newid)
with io.open(filefullpath, 'w', encoding="utf-8") as f:
f.write(strfile)