| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import argparse |
| 4 |
import git |
| 5 |
from git import Repo |
| 6 |
import glob |
| 7 |
import os |
| 8 |
import shutil |
| 9 |
import sys |
| 10 |
|
| 11 |
# where should files go |
| 12 |
dirs = { |
| 13 |
'/classes/3d/': 'classes/', |
| 14 |
'/classes/compute/': 'classes/', |
| 15 |
'/classes/dma-copy/': 'classes/', |
| 16 |
'/classes/host/': 'classes/', |
| 17 |
'/classes/memory-to-memory-format/': 'classes/', |
| 18 |
'/classes/inline-to-memory/': 'classes/', |
| 19 |
'/classes/twod/': 'classes/', |
| 20 |
} |
| 21 |
branch = 'master' |
| 22 |
target = os.path.abspath(os.path.dirname(__file__)) + "/nvidia/" |
| 23 |
|
| 24 |
parser = argparse.ArgumentParser(description='Updates Nvidia header files from git.') |
| 25 |
parser.add_argument('git_path', type=str, help='Path to the open-gpu-doc repo') |
| 26 |
|
| 27 |
args = parser.parse_args() |
| 28 |
repo_path = os.path.abspath(args.git_path) |
| 29 |
|
| 30 |
# 1. create repo object |
| 31 |
try: |
| 32 |
repo = Repo(repo_path) |
| 33 |
assert not repo.bare |
| 34 |
except git.exc.NoSuchPathError: |
| 35 |
print("{} doesn't point to a git repository".format(repo_path)) |
| 36 |
sys.exit(-1) |
| 37 |
|
| 38 |
# 2. update repo |
| 39 |
repo.remotes.origin.fetch() |
| 40 |
repo.git.checkout(branch) |
| 41 |
repo.git.rebase('origin/' + branch) |
| 42 |
|
| 43 |
# 3. check if all needed directories exist |
| 44 |
for dir in dirs.keys(): |
| 45 |
path = repo_path + dir |
| 46 |
if not os.path.isdir(path): |
| 47 |
print(dir + " does not exist in repository. Was the correct repository choosen?") |
| 48 |
sys.exit(-1) |
| 49 |
|
| 50 |
# 4. copy over files |
| 51 |
for src, dest in dirs.items(): |
| 52 |
src = repo_path + src |
| 53 |
dest = target + dest |
| 54 |
for header in glob.glob(src + "*.h"): |
| 55 |
print(header + " => " + dest) |
| 56 |
shutil.copy(header, dest) |