Last active
March 1, 2018 10:25
-
-
Save devhero/7fd74035ba59d24ceedff5dda7f8efe4 to your computer and use it in GitHub Desktop.
python get major version between files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, glob | |
from distutils.version import StrictVersion | |
def get_version(filename): | |
return os.path.splitext(filename)[0].split('-')[-1] | |
def _get_major_version(get_version_func): | |
def major_version(file_names=[]): | |
major_version_file = file_names[0] | |
for file in file_names: | |
if StrictVersion(get_version_func(file)) > StrictVersion(get_version_func(major_version_file)): | |
major_version_file = file | |
return major_version_file | |
return major_version | |
# example: | |
# lists all pdfbox jars in current folder | |
pdfbox_apps = [os.path.basename(f) for f in glob.glob(os.path.join(os.getcwd(), 'pdfbox*.jar'))] | |
print(pdfbox_apps) | |
# ['pdfbox-app-2.0.6.jar', 'pdfbox-app-2.0.8.jar'] | |
# create function that uses the get_version func as parser | |
get_major_version = _get_major_version(get_version) | |
# get the major version | |
major_pdfbox_app = get_major_version(pdfbox_apps) | |
print(major_pdfbox_app) | |
# pdfbox-app-2.0.8.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment