annotate artifacts/contrib/find-obsolete-java-files.py @ 8209:5114b643a6d6

Fixed broken build.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 18:30:20 +0200
parents f799db6b1219
children
rev   line source
8192
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 import os
8196
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
4 import sys
8192
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 def main():
8196
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
7 dirs = ['.'] if len(sys.argv) < 2 else sys.argv[1:]
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
8
8192
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 cnames = []
8196
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
10 for dir in dirs:
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
11 for root, _, files in os.walk(dir):
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
12 for f in files:
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
13 if not (f.endswith(".java") or f.endswith('.xml')):
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
14 continue
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
15 p = os.path.join(root, f)
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
16 with open(p, "rb") as jf:
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
17 content = jf.read()
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
18 if f.endswith('.xml'):
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
19 cnames.append(('', content, p))
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
20 else:
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
21 cname = f[0:-5]
f799db6b1219 Find obsolete Java files in more than one project hierachie.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8192
diff changeset
22 cnames.append((cname, content, p))
8192
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 for i in range(len(cnames)):
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 x = cnames[i]
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 cname = x[0]
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 if cname == '':
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 continue
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 found = False
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 for j in range(len(cnames)):
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 if i == j:
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 continue
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 if cnames[j][1].find(cname) >= 0:
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 found = True
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 break
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 if not found:
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 print cname, x[2]
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 if __name__ == "__main__":
adbf980004c0 Add Q'n'D Python script to find obsolete Java files.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 main()

http://dive4elements.wald.intevation.org