Example #1
0
def filter_only(keys, items):

    if isinstance(keys, str):
        keys = [keys]
    if isinstance(items, str):
        items = [items]

    # the default rule is to accept
    ret = True

    for key in keys:
        # ignore empty filters
        if key == '':
            continue

        for item in items:
            # key is part of the item, let the branch in
            if item.path.startswith(key):
                return True

            # siblings and their children, filter them out
            if item.parent.path.startswith(tree.path_parent(key)):
                ret = False
                continue

    # everything else should go in
    return ret
Example #2
0
def filter_out(keys, items):

    if isinstance(keys, str):
        keys = [keys]
    if isinstance(items, str):
        items = [items]

    for key in keys:
        # ignore empty filters
        if key == '':
            continue

        for item in items:
            # key is part of the item, leave the branch out
            if item.path.startswith(key):
                return False

            # sibling and its children, let them in
            if item.path.startswith(tree.path_parent(key)):
                continue

    # everything else should get in
    return True
Example #3
0
 def test_false_direct_parent(self):
     self.assertNotEqual(tree.path_parent('/os/linux'), '/')
Example #4
0
 def test_direct_parent(self):
     self.assertEqual(tree.path_parent('/os/linux'), '/os')
Example #5
0
 def test_on_root(self):
     self.assertEqual(tree.path_parent('/'), '/')
Example #6
0
 def test_empty_string(self):
     self.assertEqual(tree.path_parent(''), '/')
Example #7
0
 def test_false_direct_parent(self):
     self.assertNotEqual(tree.path_parent('/os/linux'), '/')
Example #8
0
 def test_direct_parent(self):
     self.assertEqual(tree.path_parent('/os/linux'), '/os')
Example #9
0
 def test_on_root(self):
     self.assertEqual(tree.path_parent('/'), '')
Example #10
0
 def test_empty_string(self):
     self.assertEqual(tree.path_parent(''), '')