Skip to content
Snippets Groups Projects

Setup silecs environments

Merged m.nabywaniec requested to merge 64-silecs-env-setup into master
+ 77
0
 
import os
 
import argparse
 
from packaging import version
 
 
def get_major(v):
 
return v._version.release[0]
 
 
def get_minor(v):
 
return v._version.release[1]
 
 
def get_available_versions(silecs_deploy_dir):
 
"""Find available versions of silecs in SILECS_DIR"""
 
subfolders = [f.name for f in os.scandir(silecs_deploy_dir) if os.path.isdir(f)]
 
available_versions = []
 
major_versions = []
 
for f in subfolders:
 
try:
 
v = version.Version(f)
 
available_versions.append(f)
 
if not major in major_versions:
 
major_versions.append(major)
 
except version.InvalidVersion:
 
pass
 
 
return sorted(available_versions, key= lambda x: version.Version(x))
 
 
def get_major_versions(versions):
 
"""Find all major versions eg ["3.0.1", "2.3.4", "1.4.1"] -> [3, 2, 1]"""
 
 
major_versions = []
 
for v in versions:
 
v = version.Version(v)
 
major = get_major(v)
 
if not major in major_versions:
 
major_versions.append(major)
 
return major_versions
 
 
 
def run(silecs_deploy_dir):
 
try:
 
versions = get_available_versions(silecs_deploy_dir)
 
print(versions)
 
major_versions = get_major_versions(versions)
 
assert len(versions)
 
except AssertionError:
 
print("No versions found")
 
return
 
 
latest_version = versions[0]
 
 
# set link for latest version
 
target = os.path.join(silecs_deploy_dir, latest_version)
 
link = os.path.join(silecs_deploy_dir, 'latest')
 
print("symlink created {target} -> {link}")
 
 
# For each major version create link to newest version
 
for mv in major_versions:
 
newest_version_with_major = str([version.Version(v) for v in versions][0])
 
target = os.path.join(SILECS_DIR, newest_version_with_major)
 
link = os.path.join(SILECS_DIR, mv)
 
os.symlink(target, link)
 
print("symlink created {target} -> {link}")
 
 
 
if __name__ == "__main__":
 
 
parser = argparse.ArgumentParser(description='Process some integers.')
 
parser.add_argument('silecs_deploy_dir', metavar='silecs_deploy_dir', type=str, nargs=1,
 
help='path to silecs deploy directory')
 
 
try:
 
options = parser.parse_args()
 
except Exception:
 
sys.exit(0)
 
 
silecs_deploy_dir = options.silecs_deploy_dir[0]
 
run(silecs_deploy_dir)
 
\ No newline at end of file
Loading