Pull.py for CS301

Woo! It has been two years since I last took Prof. Long’s course. This code can be used to automatically download CS301’s homework template files.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import tarfile

def main(a):
    path = "HW" + str(a)
    out_fname = 'HW' + str(a) + '.tar.gz'
    url = "http://repolab.colab.duke.edu:8005/courses/proxy/cs301/jpax/" + out_fname
    os.popen('curl -LO ' + url).read()
    tar = tarfile.open(out_fname)
    tar.extractall()
    tar.close()
    os.remove(out_fname)

    base_dir = os.path.abspath(path)  # Get absolute path of the target directory
    for root, dirs, files in os.walk(base_dir, topdown=False):
        for name in dirs:
            if name != "wdir_msg":
                target_dir = os.path.join(root, name)
                if os.path.exists(target_dir):
                    print(f'Accessing {target_dir}')
                    os.chdir(target_dir)
                    os.popen('make init-pull').read()
                else:
                    print(f'Error: {target_dir} does not exist or cannot be accessed')

if __name__ == "__main__":
    a = input("Enter HW#: ")
    main(a)
Last updated: 2024-11-10
Built with Hugo, theme modified on Stack