예제 #1
0
    def test_strategy(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(Strategy.resourcelist, rsp.strategy)

        rsp = RsParameters(strategy=Strategy.inc_changelist)
        self.assertEquals(Strategy.inc_changelist, rsp.strategy)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(rsp2.strategy, Strategy.inc_changelist)

        rsp = RsParameters(strategy=1)
        self.assertEquals(Strategy.new_changelist, rsp.strategy)

        rsp = RsParameters(strategy="inc_changelist")
        self.assertEquals(Strategy.inc_changelist, rsp.strategy)

        with self.assertRaises(Exception) as context:
            rsp.strategy = 20056
        #print(context.exception)
        self.assertEquals("20056 is not a valid Strategy",
                          context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
예제 #2
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)
예제 #3
0
    def test_server_path(self):
        rsp = RsParameters(url_prefix="http://example.com/bla/foo/bar")
        self.assertEquals("http://example.com/bla/foo/bar/", rsp.url_prefix)
        self.assertEquals("/bla/foo/bar/", rsp.server_path())

        rsp.url_prefix = "http://www.example.com"
        self.assertEquals("http://www.example.com/", rsp.url_prefix)
        self.assertEquals("/", rsp.server_path())
예제 #4
0
 def load_configuration(self, name):
     try:
         self.paras = RsParameters(config_name=name)
         self.selector = self.__get_selector()
         self.switch_configuration.emit(name)
         self.switch_selector.emit(self.selector.abs_location())
         LOG.debug("Loaded configuration: '%s'" % name)
     except ValueError as err:
         self.error("Unable to load configuration %s" % name, err)
예제 #5
0
    def __init__(self, **kwargs):
        """
        :samp:`Initialization`

        :param str config_name: the name of the configuration to read. If given, sets the current configuration.
        :param kwargs: see :func:`rspub.core.rs_paras.RsParameters.__init__`

        .. seealso::  :doc:`rspub.core.rs_paras <rspub.core.rs_paras>`
        """
        Observable.__init__(self)
        RsParameters.__init__(self, **kwargs)
예제 #6
0
    def test_last_strategy(self):
        Configuration().core_clear()
        rsp = RsParameters()

        self.assertIsNone(rsp.last_strategy)

        rsp.last_strategy = Strategy.inc_changelist
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEqual(Strategy.inc_changelist, rsp2.last_strategy)

        self.save_configuration_test(rsp)
예제 #7
0
    def test_set_with_reflection(self):
        rsp = RsParameters()

        name = "resource_dir"
        try:
            setattr(rsp, name, "blaat")
        except ValueError as err:
            print(err)

        rsp.metadata_dir = "md1"
        name = "metadata_dir"
        x = getattr(rsp, name)
        print(x)
예제 #8
0
    def __init__(self, application_home, locale_dir):
        QObject.__init__(self)
        self.application_home = application_home
        self.locale_dir = locale_dir
        self.config = GuiConf()
        self.last_directory = os.path.expanduser("~")
        try:
            self.paras = RsParameters(
                config_name=self.config.last_configuration_name())
        except:
            self.paras = RsParameters()

        self.selector = self.__get_selector()
예제 #9
0
    def do_reset(self, line):
        """
reset::

    Reset the configuration to default settings.

        """
        global PARAS
        if self.__confirm__("Reset configuration '%s' to default settings?" %
                            PARAS.configuration_name()):
            Configuration().core_clear()
            PARAS = RsParameters()
            PARAS.save_configuration()
            self.do_list_parameters(line)
예제 #10
0
    def save_configuration_test(self, rsp):
        Configuration.reset()
        rsp.save_configuration()
        Configuration.reset()

        rsp2 = RsParameters()
        self.assertEquals(rsp.__dict__, rsp2.__dict__)
예제 #11
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)
예제 #12
0
    def test_generators(self):
        paras = RsParameters(config_name="DEFAULT")
        raud = ResourceAuditor(paras)
        generator = raud.get_generator(all_resources=False)
        for resource, src, relpath in generator():
            self.assertEquals(Resource, type(resource))

        generator = raud.get_generator(all_resources=True)
        for resource, src, relpath in generator():
            self.assertEquals(Resource, type(resource))
예제 #13
0
 def test_zip_resources(self):
     paras = RsParameters(config_name="DEFAULT")
     filename = os.path.splitext(paras.zip_filename)[0] + ".zip"
     if os.path.exists(filename):
         os.remove(filename)
     trans = Transport(paras)
     trans.register(EventLogger(logging_level=logging.INFO))
     trans.zip_resources(all_resources=False)
     if trans.count_resources + trans.count_sitemaps > 0:
         self.assertTrue(os.path.exists(filename))
예제 #14
0
    def test_description_dir(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertIsNone(rsp.description_dir)

        rsp.description_dir = "."
        self.assertEquals(os.getcwd(), rsp.description_dir)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(os.getcwd(), rsp2.description_dir)

        with self.assertRaises(Exception) as context:
            rsp.description_dir = "/foo/bar"
        #print(context.exception)
        self.assertIsInstance(context.exception, ValueError)

        self.assertEquals(os.getcwd(), rsp.description_dir)
        self.save_configuration_test(rsp)
예제 #15
0
    def test_current_description_url(self):
        rsp = RsParameters(url_prefix="http://example.com/bla/foo/bar")
        rsp.has_wellknown_at_root = True
        self.assertEquals(rsp.description_url(),
                          "http://example.com/.well-known/resourcesync")

        rsp.has_wellknown_at_root = False
        rsp.resource_dir = os.path.expanduser("~")
        rsp.metadata_dir = "some/path/md10"
        self.assertEquals(
            rsp.description_url(),
            "http://example.com/bla/foo/bar/some/path/md10/.well-known/resourcesync"
        )
예제 #16
0
    def test_booleans(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertTrue(rsp.is_saving_pretty_xml)
        self.assertTrue(rsp.is_saving_sitemaps)
        self.assertTrue(rsp.has_wellknown_at_root)

        rsp = RsParameters(is_saving_pretty_xml=False,
                           is_saving_sitemaps=False,
                           has_wellknown_at_root=False)
        self.assertFalse(rsp.is_saving_pretty_xml)
        self.assertFalse(rsp.is_saving_sitemaps)
        self.assertFalse(rsp.has_wellknown_at_root)

        # contamination test
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertFalse(rsp2.is_saving_pretty_xml)
        self.assertFalse(rsp2.is_saving_sitemaps)
        self.assertFalse(rsp2.has_wellknown_at_root)

        self.save_configuration_test(rsp)
예제 #17
0
    def __init__(self, rs_parameters: RsParameters = None):
        """
        :samp:`Initialization`

        If no :class:`~rspub.core.rs_paras.RsParameters` were given will construct
        new :class:`~rspub.core.rs_paras.RsParameters` from
        configuration found under :func:`~rspub.core.config.Configurations.current_configuration_name`.

        :param rs_parameters: :class:`~rspub.core.rs_paras.RsParameters` for execution
        """
        Observable.__init__(self)

        self.para = rs_parameters if rs_parameters else RsParameters()
        self.passes_resource_gate = None
        self.date_start_processing = None
        self.date_end_processing = None
예제 #18
0
 def read_parameters(self):
     paras = RsParameters(config_name="DEFAULT")
     # configuration:
     cfg_file = os.path.join(os.path.expanduser("~"), CFG_FILE)
     with open(cfg_file) as cfg:
         line = cfg.readline()
     spup = line.split(",")
     paras.imp_scp_server = spup[0]
     paras.imp_scp_port = int(spup[1])
     paras.imp_scp_user = spup[2]
     password = spup[3]
     paras.imp_scp_remote_path = spup[4]
     paras.imp_scp_local_path = spup[5].strip()
     return paras, password
예제 #19
0
    def test_max_items_in_list(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(50000, rsp.max_items_in_list)

        rsp = RsParameters(max_items_in_list=1)
        self.assertEquals(1, rsp.max_items_in_list)

        # contamination test
        rsp.max_items_in_list = 12345
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(12345, rsp2.max_items_in_list)

        with self.assertRaises(Exception) as context:
            rsp.max_items_in_list = "foo"
        #print(context.exception)
        self.assertEquals(
            "Invalid value for max_items_in_list: not a number foo",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.max_items_in_list = 0
        #print(context.exception)
        self.assertEquals(
            "Invalid value for max_items_in_list: value should be between 1 and 50000",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        with self.assertRaises(Exception) as context:
            rsp.max_items_in_list = 50001
        #print(context.exception)
        self.assertEquals(
            "Invalid value for max_items_in_list: value should be between 1 and 50000",
            context.exception.args[0])
        self.assertIsInstance(context.exception, ValueError)

        self.save_configuration_test(rsp)
예제 #20
0
    def do_open_configuration(self, name):
        """
open_configuration [name]::

    Open a saved configuration

        """
        global PARAS
        if name:
            try:
                PARAS = RsParameters(config_name=name)
                self.do_list_parameters(name)
            except ValueError as err:
                print("\nIllegal argument: {0}".format(err))
        else:
            print("Open a configuration. Specify a name:")
            self.do_list_configurations(name)
예제 #21
0
    def test_zero_fill_filename(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(4, rsp.zero_fill_filename)

        rsp = RsParameters(zero_fill_filename=10)
        self.assertEquals(10, rsp.zero_fill_filename)

        # contamination test
        rsp.zero_fill_filename = 8
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(8, rsp2.zero_fill_filename)

        self.save_configuration_test(rsp)
예제 #22
0
    def test_imp_scp_remote_path(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("~", rsp.imp_scp_remote_path)

        # contamination test
        rsp.imp_scp_remote_path = "/var/rs/"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("/var/rs", rsp2.imp_scp_remote_path)

        rsp.imp_scp_remote_path = "/opt/ehri/rs"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("/opt/ehri/rs", rsp3.imp_scp_remote_path)

        self.save_configuration_test(rsp)
예제 #23
0
    def test_imp_scp_user(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("username", rsp.imp_scp_user)

        # contamination test
        rsp.imp_scp_user = "******"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("kees", rsp2.imp_scp_user)

        rsp.imp_scp_user = "******"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("joe", rsp3.imp_scp_user)

        self.save_configuration_test(rsp)
예제 #24
0
    def test_exp_scp_document_root(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("/var/www/html", rsp.exp_scp_document_root)

        # contamination test
        rsp.exp_scp_document_root = "/opt/rs/"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("/opt/rs", rsp2.exp_scp_document_root)

        rsp.exp_scp_document_root = "/var/www/html/ehri/rs"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("/var/www/html/ehri/rs", rsp3.exp_scp_document_root)

        self.save_configuration_test(rsp)
예제 #25
0
    def test_imp_scp_port(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(22, rsp.imp_scp_port)

        # contamination test
        rsp.imp_scp_port = 2222
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(2222, rsp2.imp_scp_port)

        rsp.imp_scp_port = 1234
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals(1234, rsp3.imp_scp_port)

        self.save_configuration_test(rsp)
예제 #26
0
    def test_imp_scp_server(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals("example.com", rsp.imp_scp_server)

        # contamination test
        rsp.imp_scp_server = "imp.server.name.com"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals("imp.server.name.com", rsp2.imp_scp_server)

        rsp.imp_scp_server = "imp.server.name.nl"
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals("imp.server.name.nl", rsp3.imp_scp_server)

        self.save_configuration_test(rsp)
예제 #27
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)
예제 #28
0
    def test_plugin_dir(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(None, rsp.plugin_dir)

        user_home = os.path.expanduser("~")
        rsp.plugin_dir = user_home
        self.assertEquals(user_home, rsp.plugin_dir)

        # contamination test
        rsp.plugin_dir = None
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(None, rsp2.plugin_dir)

        rsp.plugin_dir = user_home
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals(user_home, rsp3.plugin_dir)

        self.save_configuration_test(rsp)
예제 #29
0
    def test_zip_filename(self):
        # defaults to configuration defaults
        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEqual(
            os.path.join(os.path.expanduser("~"), "resourcesync.zip"),
            rsp.zip_filename)

        rsp.zip_filename = "bar"
        self.assertEqual("bar.zip", rsp.zip_filename)

        rsp.zip_filename = "foo."
        self.assertEqual("foo.zip", rsp.zip_filename)

        rsp.zip_filename = "/"
        self.assertEqual("/.zip", rsp.zip_filename)

        # contamination test
        rsp.zip_filename = "/foo/bar.zip"
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEqual("/foo/bar.zip", rsp2.zip_filename)

        self.save_configuration_test(rsp)
예제 #30
0
    def test_imp_scp_local_path(self):
        # defaults to configuration defaults
        user_home = os.path.expanduser("~")

        Configuration().core_clear()
        rsp = RsParameters()
        self.assertEquals(user_home, rsp.imp_scp_local_path)

        # contamination test
        rsp.imp_scp_local_path = os.path.join(user_home, "local", "rs")
        rsp2 = RsParameters(**rsp.__dict__)
        self.assertEquals(os.path.join(user_home, "local", "rs"),
                          rsp2.imp_scp_local_path)

        rsp.imp_scp_local_path = os.path.join(user_home, "rs", "local")
        rsp3 = RsParameters(**rsp.__dict__)
        self.assertEquals(os.path.join(user_home, "rs", "local"),
                          rsp3.imp_scp_local_path)

        self.save_configuration_test(rsp)