workspace.py
Go to the documentation of this file.
1 import pathlib
2 import git
3 
4 
5 def _get_parent_dirs(cur_dir):
6  folder = cur_dir.resolve()
7  while folder:
8  yield folder
9  if folder.parent == folder:
10  return
11  else:
12  folder = folder.parent
13 
14 
15 def get_workspace_root(cur_dir=pathlib.Path('.')):
16  for folder in _get_parent_dirs(cur_dir):
17  if (folder / '.catkin_workspace').exists():
18  return 'catkin_make', folder
19  elif (folder / '.catkin_tools').exists():
20  return 'catkin_tools', folder
21  return None, None
22 
23 
24 def get_git_repos(root):
25  queue = [root]
26  repos = []
27  while queue:
28  folder = queue.pop(0)
29  if (folder / '.git').exists():
30  repos.append(folder)
31  continue
32 
33  for new_path in folder.iterdir():
34  if new_path.is_dir():
35  queue.append(new_path)
36  return repos
37 
38 
39 def workspace():
40  d = {}
41  build_tool, workspace_root = get_workspace_root()
42  d['build_tool'] = build_tool
43  d['folder'] = str(workspace_root)
44  d['repos'] = {}
45  for repo_folder in get_git_repos(workspace_root / 'src'):
46  rd = {}
47  repo = git.Repo(repo_folder)
48  rd['remotes'] = {rem.name: rem.url for rem in repo.remotes}
49  rd['hash'] = repo.head.object.hexsha
50  rd['branch'] = repo.active_branch.name
51  rd['folder'] = str(repo_folder.relative_to(workspace_root))
52 
53  d['repos'][repo_folder.stem] = rd
54  return d
system_fingerprint.workspace._get_parent_dirs
def _get_parent_dirs(cur_dir)
Definition: workspace.py:5
system_fingerprint.workspace.get_git_repos
def get_git_repos(root)
Definition: workspace.py:24
system_fingerprint.workspace.get_workspace_root
def get_workspace_root(cur_dir=pathlib.Path('.'))
Definition: workspace.py:15
system_fingerprint.workspace.workspace
def workspace()
Definition: workspace.py:39


system_fingerprint
Author(s):
autogenerated on Wed May 14 2025 02:20:56