1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-16 10:59:53 +02:00
Mailu/setup/setup.py

40 lines
1.3 KiB
Python
Raw Normal View History

2018-03-10 16:25:52 +02:00
import git
import tempfile
import argparse
import os
import shutil
import re
VERSION_BRANCH = re.compile("(master|\d+\.\d+)")
2018-04-22 11:53:40 +02:00
def main(upstream, dest, dev=True):
2018-03-10 16:25:52 +02:00
shutil.rmtree(dest, ignore_errors=True)
os.makedirs(dest, exist_ok=True)
with tempfile.TemporaryDirectory() as clone_path:
repo = git.Repo.clone_from(upstream, clone_path)
for branch in repo.refs:
if not branch.name.startswith("origin/"):
continue
name = branch.name[len("origin/"):]
if not VERSION_BRANCH.match(name):
continue
branch.checkout()
2018-04-22 16:12:13 +02:00
config_path = os.path.join(clone_path, "setup")
2018-03-10 16:25:52 +02:00
if os.path.exists(config_path):
shutil.copytree(config_path, os.path.join(dest, name))
print("Imported branch {}".format(name))
2018-04-22 11:53:40 +02:00
if dev:
shutil.copytree(".", os.path.join(dest, "dev"))
print("Imported dev")
2018-03-10 16:25:52 +02:00
if __name__ == "__main__":
parser = argparse.ArgumentParser()
2018-04-22 11:53:40 +02:00
parser.add_argument("--dev", action="store_true", help="Copy the local dir in /dev")
2018-03-10 16:25:52 +02:00
parser.add_argument("upstream", help="Path to Mailu git repository")
parser.add_argument("dest", help="Destination directory for data files")
args = parser.parse_args()
main(**vars(args))