Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts to archive easyconfigs #18934

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions scripts/archive_old
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3

import argparse
from datetime import datetime, timezone
import glob
import os
import git


def system_toolchain(ecpath):
with open(ecpath, 'r', encoding='utf8') as file:
for line in file:
if line.strip() == 'toolchain = SYSTEM':
return True
return False


parser = argparse.ArgumentParser(
prog='archive_old',
description='Archives easyconfigs based on when they were first committed')
parser.add_argument('--branch', action='store_true', help='create new branch')
parser.add_argument('--apply', action='store_true', help='apply git mv')
parser.add_argument('--commit', action='store_true', help='automatically commit')
parser.add_argument('--repo', type=str, required=True, help='root dir of easyconfigs repo')
parser.add_argument(
'--cutoff',
type=lambda s: datetime.strptime(s, '%Y-%m-%d').astimezone(timezone.utc),
required=True,
help='Year-month-day (in UTC)')

args = parser.parse_args()

repo = git.Repo(args.repo)

robot_dir = os.path.join(args.repo, 'easybuild/easyconfigs')
archive_dir = os.path.join(robot_dir, '__archive__')
paths = glob.glob(os.path.join(robot_dir, '?/*/*.eb'))

changes_to_commit = False

for path in paths:
if not system_toolchain(path):
continue

for commit in repo.iter_commits(paths=path, reverse=True):
# Just looking at the oldest commits for software age.
if commit.committed_datetime < args.cutoff:
if args.apply:
archive_path = path.replace(robot_dir, archive_dir)
os.makedirs(archive_path.rsplit('/', maxsplit=1)[0], exist_ok=True)
repo.index.move([path, archive_path])
changes_to_commit = True
print(f"Archived '{path}' from {commit.committed_datetime}")
else:
print(f"Would have archived '{path}' from {commit.committed_datetime}")

break

if changes_to_commit:
if args.branch:
new_branch_name = f'archive_system_{args.cutoff}'
repo.create_head(new_branch_name)
new_branch = repo.heads[new_branch_name]
new_branch.checkout()

commit_message = f"Archive files from before {args.cutoff.strftime('%Y-%m-%d')}"
if args.commit:
repo.index.commit(commit_message)
print(f'Committed "{commit_message}"')
else:
print('Commit the changes with:')
print(f'git commit -m "{commit_message}"')
else:
print("No changes to commit.")
52 changes: 52 additions & 0 deletions scripts/archive_toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

import argparse
import glob
import os
import git


parser = argparse.ArgumentParser(
prog='archive_old',
description='Archives easyconfigs based toolchain substring in easyconfig name')
parser.add_argument('--branch', action='store_true', help='create new branch')
parser.add_argument('--apply', action='store_true', help='apply git mv')
parser.add_argument('--commit', action='store_true', help='automatically commit')
parser.add_argument('--repo', type=str, required=True, help='root dir of easyconfigs repo')
parser.add_argument('--toolchain', type=str, required=True, help='e.g. "foss-2016a"')

args = parser.parse_args()

repo = git.Repo(args.repo)

robot_dir = os.path.join(args.repo, 'easybuild/easyconfigs')
archive_dir = os.path.join(robot_dir, '__archive__')
paths = glob.glob(os.path.join(robot_dir, f'?/*/*{args.toolchain}*.eb'))

changes_to_commit = False
for path in paths:
if args.apply:
archive_path = path.replace(robot_dir, archive_dir)
os.makedirs(archive_path.rsplit('/', maxsplit=1)[0], exist_ok=True)
repo.index.move([path, archive_path])
changes_to_commit = True
print(f'Archived {path}')
else:
print(f'Would have archived {path}')

if changes_to_commit:
if args.branch:
new_branch_name = f'archive_{args.toolchain}'
repo.create_head(new_branch_name)
new_branch = repo.heads[new_branch_name]
new_branch.checkout()

commit_message = f"Archive {args.toolchain}"
if args.commit:
repo.index.commit(commit_message)
print(f'Committed "{commit_message}"')
else:
print('Commit the changes with:')
print(f'git commit -m "{commit_message}"')
else:
print("No changes to commit.")