Exemplo n.º 1
0
    def __get_selector(self):
        if self.paras.selector_file:
            try:
                selector = Selector(location=self.paras.selector_file)
                self.last_directory = os.path.dirname(self.paras.selector_file)
                LOG.debug("Loaded selector from %s" % self.paras.selector_file)
            except Exception as err:
                self.warn(
                    "Unable to read selector file '%s'" %
                    self.paras.selector_file, err)
                selector = Selector()
        else:
            selector = Selector()

        #Difficult keeping track of a selector that is not saved:
        if selector.location is None:
            selector_dir = os.path.join(Configurations.rspub_config_dir(),
                                        "selectors")
            os.makedirs(selector_dir, exist_ok=True)
            location = os.path.join(selector_dir, "default_selector.csv")
            if os.path.exists(location):
                selector = Selector(location=location)
            else:
                selector.write(location)
            self.paras.selector_file = location
        return selector
Exemplo n.º 2
0
    def test_read_write(self):
        selector = Selector()
        selector.include("collection1")
        selector.exclude("collection2")

        selector.write(os.path.join(test_dir(), "test_selector.txt"))

        selector2 = Selector(os.path.join(test_dir(), "test_selector.txt"))
        self.assertEqual(selector2.get_included_entries().pop(), "collection1")
        self.assertEqual(selector2.get_excluded_entries().pop(), "collection2")
Exemplo n.º 3
0
    def test_read_write(self):
        selector = Selector()
        selector.read_includes(os.path.join(test_dir(), "includes.txt"))
        selector.read_excludes(os.path.join(test_dir(), "excludes.txt"))

        print("\nselector 1")
        for filename in selector:
            print(filename)

        selector.write_includes(os.path.join(test_dir(), "includes_w.txt"))
        selector.write_excludes(os.path.join(test_dir(), "excludes_w.txt"))

        selector.write(os.path.join(test_dir(), "selector_1.txt"))
        selector2 = Selector(os.path.join(test_dir(), "selector_1.txt"))
        #
        print("\nselector 2")
        for filename in selector2:
            print(filename)

        selector2.clear_excludes()
        selector2.write(os.path.join(test_dir(), "test_data",
                                     "selector_2.txt"))