Skip to content

Commit

Permalink
Use Lib class
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Jul 15, 2024
1 parent 5c2b446 commit 16d098f
Showing 1 changed file with 63 additions and 26 deletions.
89 changes: 63 additions & 26 deletions upstream_utils/update_mpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,74 @@
git_am,
)

def get_repo_path(url, tempdir=None):
if tempdir is None:
tempdir = tempfile.gettempdir()
repo = os.path.basename(url)
dest = os.path.join(tempdir, repo)
dest = dest.removesuffix(".git")
return dest

def open_repo(url, *, err_msg_if_absent):
os.chdir(tempfile.gettempdir())
class Lib:
def __init__(
self,
name,
url,
old_tag,
patch_list,
copy_upstream_src,
patch_options={},
*,
pre_patch_hook=None,
pre_patch_commits=0,
):
self.name = name
self.url = url
self.old_tag = old_tag
self.patch_list = patch_list
self.copy_upstream_src = copy_upstream_src
self.patch_options = patch_options
self.pre_patch_hook = pre_patch_hook
self.pre_patch_commits = pre_patch_commits
self.wpilib_root = get_repo_root()

def get_repo_path(self, tempdir=None):
if tempdir is None:
tempdir = tempfile.gettempdir()
repo = os.path.basename(self.url)
dest = os.path.join(tempdir, repo)
dest = dest.removesuffix(".git")
return dest

def open_repo(self, *, err_msg_if_absent):
os.chdir(tempfile.gettempdir())

dest = self.get_repo_path(os.getcwd())

print(f"INFO: Opening repository at {dest}")

if not os.path.exists(dest):
if err_msg_if_absent is None:
subprocess.run(["git", "clone", "--filter=tree:0", self.url])
else:
print(err_msg_if_absent, file=sys.stderr)
exit(1)
os.chdir(dest)

def clone(self):
self.open_repo(err_msg_if_absent=None)

subprocess.run(["git", "switch", "--detach", self.old_tag])

dest = get_repo_path(url, os.getcwd())

print(f"INFO: Opening repository at {dest}")

if not os.path.exists(dest):
if err_msg_if_absent is None:
subprocess.run(["git", "clone", "--filter=tree:0", url])
else:
print(err_msg_if_absent, file=sys.stderr)
exit(1)
os.chdir(dest)
def main():
name = "mpack"
url = "https://github.com/ludocode/mpack"
tag = "v1.1.1"

def clone(url, tag):
open_repo(url, err_msg_if_absent=None)
patch_list = [
"0001-Don-t-emit-inline-defs.patch",
"0002-Update-amalgamation-script.patch",
"0003-Use-namespace-for-C.patch",
"0004-Group-doxygen-into-MPack-module.patch",
]

subprocess.run(["git", "switch", "--detach", tag])
mpack = Lib(name, url, tag, [], lambda: None)
mpack.clone()

def main():
wpilib_root = get_repo_root()
clone("https://github.com/ludocode/mpack", "v1.1.1")
wpilib_root = mpack.wpilib_root
upstream_root = os.getcwd()
wpiutil = os.path.join(wpilib_root, "wpiutil")

Expand Down

0 comments on commit 16d098f

Please sign in to comment.