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