def __init__(self, cmd="", inputs=None, outputs=None, desc="", **kwds): self._inputs = as_tuple(inputs) self._outputs = as_tuple(outputs) desc_kw = dict(i=self._inputs, o=self._outputs) desc_kw.update(kwds) desc = desc.format(**desc_kw) cmd_kw = dict(i=shquote(self._inputs), o=shquote(self._outputs)) cmd_kw.update(kwds) cmd = vformat_list(string.Formatter(), cmd, [], cmd_kw) if not desc: desc = cmd super().__init__(cmd=cmd, desc=desc)
def _format_filelist_shargs(filelist): return " ".join(shquote(i) for i in sorted(filelist))
def test_stringify_list(self): self.assertEqual(shquote([PathLib("1 0"), PathLib("2 0")]), ["'1 0'", "'2 0'"])
def test_stringify_singleton(self): self.assertEqual(shquote(PathLib("1 0")), "'1 0'")
def test_set_of_strings(self): r = shquote(frozenset(("a b", "c d"))) self.assertCountEqual(r, ("'a b'", "'c d'")) self.assertIs(type(r), frozenset)
def test_tuple_of_strings(self): r = shquote(("a b", "c d")) self.assertCountEqual(r, ("'a b'", "'c d'")) self.assertIs(type(r), tuple)
def test_list_of_strings(self): r = shquote(["a b", "c d"]) self.assertCountEqual(r, ("'a b'", "'c d'")) self.assertIs(type(r), list)
def test_single_string(self): self.assertEqual(shquote("a b"), "'a b'")
def convert_field(self, value, conversion): if conversion == "q": return shquote(value) return super().convert_field(value, conversion)
def formatter(self): return " ".join(shquote(as_flat_list(getattr(self, name))))