generated from ScoopInstaller/BucketTemplate
-
Notifications
You must be signed in to change notification settings - Fork 26
/
checkdups.py
114 lines (94 loc) · 2.52 KB
/
checkdups.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" @todo add docstring """
# ### imports ###
from __future__ import (
absolute_import,
division,
print_function, # ,
# unicode_literals
)
import datetime
# import fnmatch
import glob
# import json
import re
import os
import subprocess
import sys
path = os.environ["PATH"]
paths = path.split(";")
seen_paths = {}
exes = {}
include_dirs = [] # ['c:\\bin']
exclude_dirs = [
r"%USERPROFILE%\scoop\apps\imagemagick\current",
r"%SystemDrive%\GnuWin32\bin",
r"%USERPROFILE%\scoop\apps\git\current\mingw64\bin",
]
for i, _dir in enumerate(exclude_dirs):
exclude_dirs[i] = os.path.expandvars(_dir)
max_path = 0
amap = {}
for path in paths:
p = path.lower().rstrip("\\")
if len(p) == 0:
continue
if p in seen_paths:
seen_paths[p] += 1
continue
seen_paths[p] = 1
if not os.path.exists(path):
print("path not found: '%s'" % path)
continue
skip = False
for adir in exclude_dirs:
if adir.upper().find(path.upper()) >= 0:
skip = True
if skip:
continue
os.chdir(path)
files = glob.glob("*.exe")
files += glob.glob("*.com")
# files += glob.glob("*.dll")
files += glob.glob("*.cmd")
files += glob.glob("*.bat")
for file in files:
file = file.lower()
if file not in exes:
exes[file] = []
exes[file].append(path)
if file not in amap:
amap[file] = {}
amap[file][path] = 1
files = []
for file, paths in exes.items():
if len(paths) > 1:
files.append(file)
files.sort()
for file in files:
for path in exes[file]:
max_path = max(max_path, len(path))
for file in files:
skip = False
for adir in include_dirs:
for path in amap[file]:
if adir.upper().find(path.upper()) >= 0:
skip = True
break
if skip:
continue
print("%s:" % file)
for path in exes[file]:
full = path + "\\" + file
# q = '"%s"' % full
# print("q=%s" % q)
out = "n/a"
if re.search("(com|dll|exe)$", file) is not None:
p = subprocess.Popen(["sigcheck.exe", "-nobanner", "-n", full], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
out = out.strip()
mtime = os.path.getmtime(full)
out += datetime.datetime.fromtimestamp(mtime).strftime(" (%Y-%m-%d %H:%M:%S)")
print(" %*s: %s" % (-max_path, path, out))
sys.exit(0)