2 changed files with 136 additions and 0 deletions
@ -0,0 +1,65 @@ |
|||
import os |
|||
import py7z |
|||
import re |
|||
import edlib |
|||
import pickle |
|||
import functools |
|||
with open('test.pkl','rb') as file: |
|||
test = pickle.load(file) |
|||
|
|||
#check 1: see if all files lie within a single dir |
|||
def __inner__(top,first = True): |
|||
os.chdir(top) |
|||
dirs = os.listdir() |
|||
valid = len(dirs) == 1 |
|||
if valid: |
|||
valid = os.path.isdir(dirs[0]) |
|||
if valid: |
|||
return __inner__(dirs[0],False) |
|||
else: |
|||
if not first: |
|||
return top |
|||
|
|||
def single_dir(top): |
|||
og_cwd = os.getcwd() |
|||
res = __inner__(top) |
|||
os.chdir(og_cwd) |
|||
return res |
|||
#check 2: see if there is an 64 bit and 32 bit executable; take common name |
|||
def is32or64(top): |
|||
exes = [] |
|||
for root,dirs,files in os.walk(top): |
|||
for file in files: |
|||
if file.endswith('.exe'): |
|||
exes.append(file) |
|||
candidates = list(filter(lambda exe: '32' in exe or '64' in exe,exes)) |
|||
res = os.path.commonprefix(candidates) |
|||
if res != '': |
|||
return res.rstrip('.exe') |
|||
|
|||
#check 3: sort executables by edit-distance from archive name; pick top one |
|||
def by_edit_distance(top): |
|||
exes = [] |
|||
for root,dirs,files in os.walk(top): |
|||
for file in files: |
|||
if file.endswith('.exe'): |
|||
exes.append(file) |
|||
res = sorted(exes,key = lambda a: edlib.align(top,a)['editDistance'],reverse=False) |
|||
if len(res) >= 1: |
|||
return res[0][:len(res[0])-len('.exe')] |
|||
def dispatch(file_list): |
|||
trials = ( |
|||
single_dir, |
|||
is32or64, |
|||
by_edit_distance, |
|||
) |
|||
res = None |
|||
for trial in trials: |
|||
if res is None: |
|||
res = trial(file_list) |
|||
else: |
|||
break |
|||
return res |
|||
top = r"Z:\out" |
|||
t1 = list(map(dispatch,(os.path.join(top,file) for file in os.listdir(top)))) |
|||
print(t1) |
|||
@ -0,0 +1,71 @@ |
|||
import re |
|||
extension = re.compile(r'\.(?:(?:tar\.(?:gz|bz))|[a-z0-9]+)$',re.I) |
|||
platform = re.compile(r'(?<!\d)(?:(?<!^)win(?:dows)?)?[^x368?]?x?(?P<platform>(?:32|64|86(?:[^368](?=\d))?)+)',re.I) |
|||
version = re.compile(r'v?(?P<version_code>\d+(?P<sep>[\.-_])(?:\d+(?P=sep)?)*\d+)(?:[^(?P=sep)\.](?=[abrs]))?(?P<label>setup|redist|beta|alpha|release)?',re.I) |
|||
name = re.compile(r'^[a-z0-9]+(?:(?P<sep>[^a-z0-9])(?=[a-z0-9]))?(?:[a-z0-9]+(?P=sep))*(?:[a-z0-9]+)?[a-z0-9]',re.I) |
|||
|
|||
def snip(string,span): |
|||
beginning = string[:span[0]] |
|||
end = string[span[1]:] |
|||
return beginning + end |
|||
def get_info(fname): |
|||
ret = {} |
|||
match = extension.search(fname) |
|||
if match: |
|||
ret['ext'] = match.group(0) |
|||
fname = snip(fname,match.span()) |
|||
match = platform.search(fname) |
|||
if match: |
|||
ret['platform'] = match.group('platform') |
|||
fname = snip(fname,match.span()) |
|||
match = version.search(fname) |
|||
if match: |
|||
ret['version'] = re.sub(r'[^\d\.]','.',match.group('version_code')) |
|||
ret['label'] = match.group('label') |
|||
sep = match.group('sep') |
|||
fname = snip(fname,match.span()) |
|||
match = name.search(fname) |
|||
if match: |
|||
ret['name'] = match.group(0) |
|||
return ret |
|||
|
|||
test_fnames = '''\ |
|||
6_3_0.zip |
|||
Anaconda2-4.3.0.1-Windows-x86_64.zip |
|||
chromedriver_win32.zip |
|||
cpu-z_1.81-en.zip |
|||
Dimmer_v1.0.zip |
|||
duplicate_files_deleter.zip |
|||
elevate-1.3.0-redist.7z |
|||
evolution-win.zip |
|||
evosim_win_2016_04_02.zip |
|||
Flowgorithm-2.14.1-Setup.zip |
|||
foldertimeupdate-x64.zip |
|||
httpd-2.4.29-o102n-x86-vc14-r2.zip |
|||
httpd-2.4.33-win64-VC15.zip |
|||
hwmonitor_1.33.zip |
|||
KeePassX-2.0.3.zip |
|||
Mindustry-windows64-3.5-release-40.zip |
|||
Mindustry-windows64-4.0-alpha-52.zip |
|||
Neon Skylines - Windows x86.zip |
|||
nginx-1.15.3.zip |
|||
nssm-2.24.zip |
|||
openhardwaremonitor-v0.8.0-beta.zip |
|||
OpenSSH-Win64.zip |
|||
PluginManager_v1.4.9_x64.zip |
|||
pyenchant-prebuild-win-amd64.7z |
|||
RAMMap.zip |
|||
SkyUI_5_1-3863-5-1.7z |
|||
tesseract-3.02.02-win32-lib-include-dirs.zip |
|||
tesseract-ocr-3.02-win32-portable.zip |
|||
testdisk-7.0.win.zip |
|||
Tic Tac Toe 2.7z |
|||
visus805.zip |
|||
wakeonlanmonitor.zip |
|||
win-acme.v1.9.11.2.zip |
|||
winprefetchview-x64.zip |
|||
wolsniffer.zip |
|||
xdelta3-3.1.0-x86_64.exe.zip\ |
|||
'''.split('\n') |
|||
for fname in test_fnames: |
|||
print(get_info(fname)) |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue