diff --git a/portable_install/install.py b/portable_install/install.py index e69de29..719465a 100644 --- a/portable_install/install.py +++ b/portable_install/install.py @@ -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) \ No newline at end of file diff --git a/portable_install/regex_analysis.py b/portable_install/regex_analysis.py new file mode 100644 index 0000000..e19f98c --- /dev/null +++ b/portable_install/regex_analysis.py @@ -0,0 +1,71 @@ +import re +extension = re.compile(r'\.(?:(?:tar\.(?:gz|bz))|[a-z0-9]+)$',re.I) +platform = re.compile(r'(?(?:32|64|86(?:[^368](?=\d))?)+)',re.I) +version = re.compile(r'v?(?P\d+(?P[\.-_])(?:\d+(?P=sep)?)*\d+)(?:[^(?P=sep)\.](?=[abrs]))?(?P