From 9c2fd5e409427cbe469b5ef709da32b1988f85b1 Mon Sep 17 00:00:00 2001 From: psakievich Date: Wed, 9 Feb 2022 09:22:08 -0700 Subject: [PATCH] Remove some unused scripts (#161) --- scripts/create_machine_spack_environment.py | 103 --------------- scripts/environment_updater.py | 131 -------------------- scripts/rebless.py | 1 - scripts/set_permissions.py | 48 ------- 4 files changed, 283 deletions(-) delete mode 100755 scripts/create_machine_spack_environment.py delete mode 100755 scripts/environment_updater.py delete mode 100644 scripts/rebless.py delete mode 100755 scripts/set_permissions.py diff --git a/scripts/create_machine_spack_environment.py b/scripts/create_machine_spack_environment.py deleted file mode 100755 index b5bacbdb..00000000 --- a/scripts/create_machine_spack_environment.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env spack-python -""" -A script for creating a new environment -on a given machine -""" - -import shutil -import os -import sys -from find_machine import find_machine -import argparse - -default_env_file = ( - """ -spack: - include: -{includes} - concretization: together - view: false - specs: - - {spec}""") - - -def NewName(newHead, oldFile, prefix=None): - tail = os.path.basename(oldFile) - if prefix is not None: - return os.path.join(newHead, prefix + '_' + tail) - else: - return os.path.join(newHead, tail) - - -def CopyFilesAcrossPaths(pathStart, pathEnd, prefix=None): - copiedFiles = [] - for f in os.listdir(pathStart): - d = os.path.join(pathStart, f) - n = NewName(pathEnd, d, prefix) - copiedFiles.append(os.path.basename(n)) - shutil.copy(d, n) - return copiedFiles - - -def CreateEnvDir(args): - """ - Copy files as needed - """ - if args.machine is not None: - machine = args.machine - else: - machine = find_machine() - - if args.spec is not None: - spec = args.spec - else: - spec = 'exawind' - - genPath = os.path.join(os.environ['SPACK_MANAGER'], 'configs', 'base') - hostPath = os.path.join(os.environ['SPACK_MANAGER'], 'configs', machine) - - if os.path.exists(hostPath): - if args.directory is not None: - if os.path.exists(args.directory) is False: - print("making", args.directory) - os.makedirs(args.directory) - - theDir = args.directory - else: - theDir = os.getcwd() - - machineFiles = CopyFilesAcrossPaths(hostPath, theDir, 'machine') - generalFiles = CopyFilesAcrossPaths(genPath, theDir, 'general') - - includeString = '' - for x in machineFiles + generalFiles: - includeString += ' - {v}\n'.format(v=x) - - if args.yaml is not None: - assert(os.path.isfile(args.yaml)) - shutil.copy(args.yaml, os.path.join(theDir, 'spack.yaml')) - else: - open(os.path.join(theDir, 'spack.yaml'), 'w').write( - default_env_file.format(spec=spec, includes=includeString)) - else: - raise Exception('Host not setup in spack-manager: %s' % hostPath) - - -def Parse(args): - parser = argparse.ArgumentParser(description='A convenience script' - ' for setting up a spack environment' - ' through the spack-manager repository.') - parser.add_argument('-m', '--machine', required=False, - help='Machine to match configs') - parser.add_argument('-d', '--directory', required=False, - help='Directory to copy files') - parser.add_argument('-y', '--yaml', required=False, - help='Reference spack.yaml to copy to directory') - parser.add_argument('-s', '--spec', required=False, - help='Spec to populate the environment with') - return parser.parse_args(args) - - -if __name__ == '__main__': - args = Parse(sys.argv[1:]) - CreateEnvDir(args) diff --git a/scripts/environment_updater.py b/scripts/environment_updater.py deleted file mode 100755 index 6730aecf..00000000 --- a/scripts/environment_updater.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env spack-python -""" -This script will cycle over a list of environments -and update them. These environments should control -the views that modules use. -""" -import spack.environment as ev -import spack.util.executable -from datetime import date -import os -import sys - -git = spack.util.executable.which('git') - - -def GetValidEnvironment(env): - try: - # check for registerd env - return ev.read(env) - except: - try: - # check for anonymous env - ev.Environment(env) - except: - raise ev.SpackEnvironmentErrror( - '%s is not a valid environment' % env) - finally: - return ev.Environment(env) - return None - - -def GetListOfEnvironments(iFile): - envs = [] - fp = open(iFile) - for line in fp: - print(line) - try: - name, frequency = line.split() - except: - print('Failing line: ', line) - envs.append({'name': name, 'freq': frequency}) - return envs - - -def TimeToUpdate(f): - """ - Check if the environment should be built - based off the specified frequency and current - date - """ - today = date.today() - - if f == 'monthly' and today.day == 1: - return True - if f == 'daily': - return True - if f == 'quarterly' and today.day == 1 and today.month in [1, 4, 7, 10]: - return True - - return False - - -def UpdateDevelopmentSpecs(e): - env = GetValidEnvironment(e) - with env: - for name, entry in env.dev_specs.items(): - os.chdir(os.path.join(env.path, entry['path'])) - print('Updating develop spec for: %s' % name) - try: - git('fetch', '--unshallow', error=os.devnull) - except: - pass - git('pull') - git('submodule', 'update') - - -def UpdateEnvironment(e): - env = GetValidEnvironment(e) - with env: - env.install_all() - - -def UpdateListOfEnvironments(inputFile, group): - envs = GetListOfEnvironments(inputFile) - for e in envs: - if TimeToUpdate(e['freq']): - print("Updating environment: {f}".format(f=e['name'])) - try: - UpdateDevelopmentSpecs(e['name']) - UpdateEnvironment(e['name']) - except: - pass - finally: - print('Finished with environment: {f}'.format(f=e['name'])) - - -def Parse(args): - parser = argparse.ArgumentParser( - description='Cycle environments and update them') - parser.add_argument( - '-i', '--input_file', required=False, - help='File with list of environments to update') - parser.add_argument( - '-e', '--environment', required=False, - help='Single environment to update without checking frequency') - parser.add_argument( - '-u', '--update_spack_manager', action='store_true', - help='Update spack-manager before updating environments') - parser.add_argument( - '-j', '--jobs', required=False, - help='Number of cores to forward to spack') - parser.set_defaults(update_spack_manager=False, group='wg-sierra-users') - return parser.parse_args() - - -if __name__ == "__main__": - import argparse - - args = Parse(sys.argv[1:]) - if args.update_spack_manager: - os.chdir(os.environ['SPACK_MANAGER']) - git('pull') - git('submodule', 'update') - - if args.input_file is not None: - UpdateListOfEnvironments(args.input_file, args.group) - - if args.environment is not None: - env = args.environment - UpdateDevelopmentSpecs(env) - UpdateEnvironment(env) diff --git a/scripts/rebless.py b/scripts/rebless.py deleted file mode 100644 index ee3ecd22..00000000 --- a/scripts/rebless.py +++ /dev/null @@ -1 +0,0 @@ -#! /usr/bin/env python diff --git a/scripts/set_permissions.py b/scripts/set_permissions.py deleted file mode 100755 index 8843f70d..00000000 --- a/scripts/set_permissions.py +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env python3 -""" -Module to set permissions uniformly -""" - -import shutil -import os -import sys - - -def recursive_file_system_func(path, func, kargs): - for dirpath, dirnames, filenames in os.walk(path): - kargs['path'] = dirpath - func(**kargs) - for filename in filenames: - kargs['path'] = os.path.join(dirpath, filename) - try: - func(**kargs) - except: - pass - - -def recursive_chown(path, user=None, group=None): - kargs = { - 'user': user, - 'group': group - } - recursive_file_system_func(path, shutil.chown, kargs) - - -def recursive_chgrp(path, group): - recursive_chown(path, None, group) - - -def recursive_chmod(path, spec): - kargs = { - 'mode': spec - } - recursive_file_system_func(path, os.chmod, kargs) - - -def set_dir_permissions(location, permissions, group): - recursive_chmod(location, permissions) - recursive_chgrp(location, group) - - -if __name__ == '__main__': - set_dir_permissions(sys.argv[1], 0o755, 'wg-sierra-users')