This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
forked from AMReX-Codes/regression_testing
-
Notifications
You must be signed in to change notification settings - Fork 3
/
repo.py
105 lines (75 loc) · 3.79 KB
/
repo.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""This module is used to handle all of the git operations for the
test suite"""
import os
import shutil
import test_util
class Repo(object):
""" a simple class to manage our git operations """
def __init__(self, suite, directory, name,
branch_wanted=None, hash_wanted=None,
build=0, comp_string=None):
self.suite = suite
self.dir = directory
self.name = name
self.branch_wanted = branch_wanted
self.hash_wanted = hash_wanted
self.build = build # does this repo contain build directories?
self.comp_string = comp_string # environment vars needed to build
# for storage
self.branch_orig = None
self.hash_current = None
self.update = True
if hash_wanted:
self.update = False
def git_update(self):
""" Do a git update of the repository. If githash is not empty, then
we will check out that version instead of git-pulling. """
os.chdir(self.dir)
# find out current branch so that we can go back later if we need.
stdout0, stderr0, rc = test_util.run("git rev-parse --abbrev-ref HEAD")
self.branch_orig = stdout0.rstrip('\n')
if self.branch_orig != self.branch_wanted:
self.suite.log.log("git checkout {} in {}".format(self.branch_wanted, self.dir))
stdout, stderr, rc = test_util.run("git checkout {}".format(self.branch_wanted),
stdin=True)
if rc != 0:
self.suite.log.fail("ERROR: git checkout was unsuccessful")
else:
self.branch_wanted = self.branch_orig
if self.hash_wanted == "" or self.hash_wanted is None:
self.suite.log.log("'git pull' in {}".format(self.dir))
# we need to be tricky here to make sure that the stdin is
# presented to the user to get the password.
stdout, stderr, rc = test_util.run("git pull", stdin=True,
outfile="git.{}.out".format(self.name))
else:
stdout, stderr, rc = test_util.run("git checkout {}".format(self.hash_wanted),
outfile="git.{}.out".format(self.name))
if rc != 0:
self.suite.log.fail("ERROR: git update was unsuccessful")
shutil.copy("git.{}.out".format(self.name), self.suite.full_web_dir)
def save_head(self):
"""Save the current head of the repo"""
os.chdir(self.dir)
self.suite.log.log("saving git HEAD for {}/".format(self.name))
stdout, stderr, rc = test_util.run("git rev-parse HEAD",
outfile="git.{}.HEAD".format(self.name) )
self.hash_current = stdout
shutil.copy("git.{}.HEAD".format(self.name), self.suite.full_web_dir)
def make_changelog(self):
""" generate a ChangeLog git repository, and copy it to the
web directory"""
os.chdir(self.dir)
self.suite.log.log("generating ChangeLog for {}/".format(self.name))
test_util.run("git log --name-only",
outfile="ChangeLog.{}".format(self.name), outfile_mode="w")
shutil.copy("ChangeLog.{}".format(self.name), self.suite.full_web_dir)
def git_back(self):
""" switch the repo back to its original branch """
os.chdir(self.dir)
self.suite.log.log("git checkout {} in {}".format(self.branch_orig, self.dir))
stdout, stderr, rc = test_util.run("git checkout {}".format(self.branch_orig),
stdin=True,
outfile="git.{}.out".format(self.name))
if rc != 0:
self.suite.log.fail("ERROR: git checkout was unsuccessful")