Example #1
0
 def test_remove_folder(self):
     file_changes_json.init_file()
     path, include, exclude = h_get_dummy_folder_data()
     file_changes_json.add_folder(path, include, exclude)
     file_changes_json.remove_folder(path)
     data = file_changes_json._get_json_data()
     self.assertEqual({}, data)
Example #2
0
 def test_add_folder_existing(self):
     file_changes_json.init_file()
     path, include, exclude = h_get_dummy_folder_data()
     added = file_changes_json.add_folder(path, include, exclude)
     self.assertTrue(added)
     added = file_changes_json.add_folder(path, include, exclude)
     self.assertFalse(added)
Example #3
0
    def test_set_include_regexes(self):
        file_changes_json.init_file()
        path, include, exclude = h_get_dummy_folder_data()
        file_changes_json.add_folder(path, include, exclude)

        new_include = ["hello", "you"]
        file_changes_json.set_include_regexes(path, new_include)
        folder = file_changes_json.get_folder_entry(path)
        self.assertEqual(new_include, folder["include_regexes"])
Example #4
0
    def test_add_change_entry(self):
        file_changes_json.init_file()
        path, include, exclude = h_get_dummy_folder_data()
        file_changes_json.add_folder(path, include, exclude)

        rel_file_path = client_paths.normalize_path("test.txt")
        file_changes_json.add_change_entry(path, rel_file_path,
                                           gen_json.ACTION_PULL)
        folder_entry = file_changes_json.get_folder_entry(path)
        changes = folder_entry["changes"]
        self.assertEqual(1, len(changes))
Example #5
0
 def test_add_folder(self):
     path, include, exclude = h_get_dummy_folder_data()
     server_path = file_changes_json.NormalizedPath("folder_at_server")
     file_changes_json.add_folder(path, include, exclude, server_path)
     data = file_changes_json._get_json_data()
     expected = {
         path: {
             "server_folder_path": server_path,
             "include_regexes": include,
             "exclude_regexes": exclude,
             "changes": {}
         }
     }
     self.assertEqual(expected, data)
Example #6
0
def add_folder(abs_folder_path: str,
               include_regexes: List[str] = (".*", ),
               exclude_regexes: List[str] = (),
               remote_name: Optional[str] = None) -> bool:
    """If possible add folder to file and start watching. Returns True, if the folder was added."""
    assert isinstance(include_regexes, list) or isinstance(
        include_regexes, tuple)
    assert isinstance(exclude_regexes, list) or isinstance(
        exclude_regexes, tuple)
    abs_folder_path = normalize_path(abs_folder_path)
    added = file_changes_json.add_folder(abs_folder_path, include_regexes,
                                         exclude_regexes, remote_name)
    if not added:
        return False
    _add_watcher(abs_folder_path, include_regexes, exclude_regexes)
    logger_sync.info(
        f"Start watching at new folder: {abs_folder_path}, include_regexes={include_regexes}, "
        f"exclude_regexes={exclude_regexes}")
    return True