Example #1
0
    def test_instantiate_from_RsParameters(self):
        paras = RsParameters()
        paras.metadata_dir = "test_instantiate_from_RsParameters"

        rs = ResourceSync(**paras.__dict__)
        self.assertEquals("test_instantiate_from_RsParameters",
                          rs.metadata_dir)
Example #2
0
    def test_strategy_new_changelist(self):
        self.change_file_contents()

        rs = ResourceSync(resource_dir=resource_dir(),
                          metadata_dir=metadata_dir())
        rs.register(EventLogger(logging_level=logging.INFO))
        #rs.max_items_in_list = 3
        #rs.is_saving_sitemaps = False
        rs.zero_fill_filename = 4
        rs.strategy = Strategy.new_changelist

        rs.metadata_dir = "tmp/rs/md1"
        # must exist
        # rs.description_dir = "/Users/Shared/foo"

        filenames = [test_resource()]
        rs.execute(filenames)
Example #3
0
    def do_run(self, line):
        """
run::

    run rspub with the current configuration.

        """
        # SELECTOR ->   yes ->   SELECTOR.location -> yes -> associated -> yes -> [runs]
        #   no|                       no|                      no|
        # P.selector > y > [run]    [runs]                 P.selector -> yes -> ask ->yes-> [runs]
        #   no|                                                no|               no|
        # [abort]                                             [runs]           [abort]
        # ----------------------------------------------------------------------------------------
        global PARAS
        global SELECTOR
        run = False  # rs.execute()
        runs = False  # rs.execute(SELECTOR)
        abort = False

        if PARAS.select_mode == SelectMode.simple and PARAS.simple_select_file:
            SELECTOR = Selector()
            SELECTOR.include(PARAS.simple_select_file)

        if SELECTOR is None:
            if PARAS.selector_file is None:
                abort = "No selector and configuration not associated with selector. Run aborted."
            else:
                run = True
        else:
            if SELECTOR.location is None \
                    or SELECTOR.abs_location() == PARAS.selector_file \
                    or PARAS.selector_file is None:
                runs = True
            elif self.__confirm__(
                    "Associate current configuration with selector?"):
                runs = True
            else:
                abort = "Not associating current configuration with selector. Run aborted."

        if abort:
            print(abort)
        elif run or runs:
            try:
                rs = ResourceSync(**PARAS.__dict__)
                rs.register(self)
                rs.execute(
                    SELECTOR)  # == rs.execute() if SELECTOR is None for [run]
                PARAS = RsParameters(
                    **rs.__dict__)  # catch up with updated paras
            except Exception as err:
                traceback.print_exc()
                print("\nUncompleted run: {0}".format(err))
        else:  # we should not end here!
            location = None
            if SELECTOR:
                location = SELECTOR.abs_location()
            print("Missed a path in tree: ", SELECTOR, location,
                  PARAS.selector_file)
Example #4
0
    def test_strategy_incremental_changelist(self):
        self.change_file_contents()
        rs = ResourceSync(resource_dir=resource_dir(),
                          metadata_dir=metadata_dir())

        rs.register(EventLogger(logging_level=logging.INFO))
        #rs.max_items_in_list = 3
        # rs.is_saving_sitemaps = False
        rs.strategy = Strategy.inc_changelist

        filenames = [test_resource()]
        rs.execute(filenames)
Example #5
0
    def test_strategy_new_resourcelist(self):
        rs = ResourceSync(resource_dir=resource_dir(),
                          metadata_dir=metadata_dir())
        rs.register(EventLogger(logging_level=logging.INFO))
        #rs.max_items_in_list = 3

        rs.strategy = Strategy.resourcelist
        # must exist
        #rs.description_dir = "/Users/Shared/foo"

        filenames = [test_resource()]
        rs.execute(filenames)
Example #6
0
    def test_with_selector(self):
        metadata = os.path.join("tmp", "rs", "md_select")

        selector = Selector()
        os.makedirs(os.path.join(resource_dir(), "tmp", "rs", "test_data"),
                    exist_ok=True)
        selector.location = os.path.join(resource_dir(), "tmp", "rs",
                                         "test_data", "selector1.txt")
        selector.include(test_resource())
        selector.exclude(os.path.join(test_resource(), "collection2"))

        rs = ResourceSync(resource_dir=resource_dir(), metadata_dir=metadata)
        rs.register(EventLogger(logging_level=logging.INFO))

        rs.execute(selector)
        # once executed we can just call rs.execute() because selector associated with paras
        rs.execute()
Example #7
0
 def run(self):
     LOG.debug("Executor thread started %s" % self)
     self.file_count = 0
     self.excluded_file_count = 0
     self.rejected_by_gate_count = 0
     rs = None
     try:
         rs = ResourceSync(**self.paras.__dict__)
         rs.register(self)
         self.selector.register(self)
         rs.execute(self.selector)
         paras = RsParameters(**rs.__dict__)
         self.signal_end_processing.emit(paras)
     except Exception as err:
         LOG.exception("Exception in executor thread:")
         self.signal_exception.emit(
             _("Exception in executor thread: {0}").format(err))
         self.inform_execution_end(date_end_processing=None)
     finally:
         self.selector.unregister(self)
         if rs:
             rs.unregister(self)