Files
gpu_runner/code/utils.py
T
2023-07-13 12:35:52 +02:00

45 lines
1.1 KiB
Python

from pydantic import AnyHttpUrl
from pathlib import Path
from git import Repo
import logging
import shutil
import os
from dotenv import load_dotenv
from configparser import ConfigParser
from runner_script import RunnerScript
# load default values
load_dotenv()
config = ConfigParser()
config.read(Path(__file__).parent / 'defaults.ini')
REPO_DIR = config.get('main', 'repo_dir')
if 'DEV' in os.environ:
REPO_DIR = os.getenv('REPO_DIR', default=REPO_DIR)
def clone_repository(
repo_url: AnyHttpUrl,
repo_dir: str = REPO_DIR
) -> Path:
print('repo_url: ', repo_url)
print('repo_dir: ', repo_dir)
# extract repo name
repo_name = repo_url.split('/')[-1].replace('.git', '')
dst_dir = Path(repo_dir) / repo_name
# prepare repo download dir
if dst_dir.exists():
shutil.rmtree(dst_dir)
dst_dir.mkdir()
# git clone repo
Repo.clone_from(url=repo_url, to_path=dst_dir)
logging.debug('finished')
return dst_dir
def execute_runner_script(path: Path) -> None:
script_list = RunnerScript.from_file(path)
for cmd in script_list:
os.system(cmd)
logging.debug('finished')