#!/usr/bin/env python3 import argparse import os from pathlib import Path import subprocess def main(): parser = argparse.ArgumentParser() parser.add_argument("--project-dir", type=str, default=None) parser.add_argument("--install-path", type=str) args = parser.parse_args() export_vcs(args.project_dir, args.install_path) def export_vcs(project_directory, install_path): if not project_directory: # Assume we're being called from colcon and need to figure this out ourselves. # When run by colcon cwd is something like /build/package_name cwd = Path(os.getcwd()) project_directory = cwd.parent.parent # Where we're going to save the output. output_file = install_path + "/project_state.repos" # Now call vcs. vcs_command = "vcs export --exact-with-tags {} > {}".format(project_directory, output_file) subprocess.run(vcs_command, shell=True) if __name__ == "__main__": main()