MCPcopy Create free account
hub / github.com/gitless-vcs/gitless / PathProcessor

Class PathProcessor

gitless/cli/helpers.py:102–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101
102class PathProcessor(argparse.Action):
103
104 def __init__(
105 self, option_strings, dest, repo=None, skip_dir_test=None,
106 skip_dir_cb=None, recursive=True, **kwargs):
107 self.repo = repo
108 self.skip_dir_test = skip_dir_test
109 self.skip_dir_cb = skip_dir_cb
110 self.recursive = recursive
111 super(PathProcessor, self).__init__(option_strings, dest, **kwargs)
112
113 def __call__(self, parser, namespace, paths, option_string=None):
114 root = self.repo.root if self.repo else ''
115 repo_dir = self.repo.path[:-1] if self.repo else '' # strip trailing /
116 def process_paths():
117 for path in paths:
118 path = os.path.abspath(path)
119 if self.recursive and os.path.isdir(path):
120 for curr_dir, dirs, fps in os.walk(path, topdown=True):
121 if curr_dir.startswith(repo_dir):
122 dirs[:] = []
123 continue
124 curr_dir_rel = os.path.relpath(curr_dir, root)
125 if (curr_dir_rel != "." and self.skip_dir_test and
126 self.skip_dir_test(curr_dir_rel)):
127 if self.skip_dir_cb:
128 self.skip_dir_cb(curr_dir_rel)
129 dirs[:] = []
130 continue
131 for fp in fps:
132 yield os.path.join(curr_dir_rel, fp)
133 else:
134 if not path.startswith(repo_dir):
135 yield os.path.relpath(path, root)
136 else:
137 yield path
138
139 setattr(namespace, self.dest, process_paths())
140
141
142class CommitIdProcessor(argparse.Action):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected