Ejemplo n.º 1
0
def watch(ignore, delimiter, timeout, no_folders, force_poll): # path, ignore, delimiter, timeout, no_folders):
    """
    Watches local files added or imported by ltk, and sends a PATCH when a document is changed.
    Also watches remote files, and automatically downloads finished translations.
    """
    try:
        action = WatchAction(os.getcwd(), timeout)
        init_logger(action.path)
        action.watch_action(ignore, delimiter, no_folders, force_poll) #path, ignore, delimiter, no_folders)
    except (UninitializedError, RequestFailedError) as e:
        print_log(e)
        logger.error(e)
Ejemplo n.º 2
0
def watch(ignore, delimiter, timeout, no_folders, force_poll): # path, ignore, delimiter, timeout, no_folders):
    """
    Watches local files added by ltk, and sends a PATCH when a document is changed.
    Also watches remote files, and automatically downloads finished translations.
    Automatically adds documents that are added to the watchfolder.  Note: The add is performed without extra options (no srx id, no download folder, etc.)
    """
    try:
        action = WatchAction(os.getcwd(), timeout)
        init_logger(action.path)
        action.watch_action(ignore, delimiter, no_folders, force_poll) #path, ignore, delimiter, no_folders)
    except (UninitializedError, RequestFailedError) as e:
        print_log(e)
        logger.error(e)
        return
class TestWatch(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = WatchAction(os.getcwd())
        self.action.clean_action(False, False, None)
        self.downloaded = []
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)
        # todo current problem: watchdog does not seem to detect changes in daemon
        # but not daemonizing watch causes tests to hang..
        watch_thread = Thread(target=self.action.watch_action, args=(None, (), None, 5,))
        watch_thread.daemon = True
        watch_thread.start()

    def tearDown(self):
        for fn in self.files:
            self.action.rm_action(fn, force=True)
        self.action.clean_action(False, False, None)
        for fn in self.downloaded:
            os.remove(fn)
        self.action.close()

    def test_watch_new_file(self):
        file_name = "new_file.txt"
        added_file = create_txt_file(file_name)
        # self.files.append(file_name)
        # check if watch detected file and added it to db
        doc = None
        time_passed = 0
        while doc is None and time_passed < 60:
            doc = self.action.doc_manager.get_doc_by_prop('name', file_name)
            time.sleep(1)
            time_passed += 1
        assert doc
        assert poll_doc()
 def setUp(self):
     self.action = WatchAction(os.getcwd())
     self.action.clean_action(False, False, None)
     self.downloaded = []
     self.action.add_action(None, ['sample*.txt'], force=True)
     self.doc_ids = self.action.doc_manager.get_doc_ids()
     for doc_id in self.doc_ids:
         assert poll_doc(self.action, doc_id)
     # todo current problem: watchdog does not seem to detect changes in daemon
     # but not daemonizing watch causes tests to hang..
     watch_thread = Thread(target=self.action.watch_action, args=(None, (), None, 5,))
     watch_thread.daemon = True
     watch_thread.start()
Ejemplo n.º 5
0
 def setUp(self):
     self.action = WatchAction(os.getcwd(), 1)
     self.action.clean_action(False, False, None)
     # self.action.open()
     self.downloaded = []
     self.files = []
     self.dir_name = "dir1"
     create_directory(self.dir_name)
     self.action.add_action([self.dir_name], force=True)
     # todo current problem: watchdog does not seem to detect changes in daemon
     # but not daemonizing watch causes tests to hang..
     watch_thread = Thread(target=self.action.watch_action, args=('.', (), None))
     watch_thread.daemon = True
     watch_thread.start()
Ejemplo n.º 6
0
 def setUp(self):
     self.action = WatchAction(os.getcwd())
     self.clean_action = CleanAction(os.getcwd())
     self.add_action = AddAction(os.getcwd())
     self.rm_action = RmAction(os.getcwd())
     self.locales_to_test = ['de-DE', 'es-AR', 'ja-JP']
     #default in my test was clone on download folder none target locale folders none
     self.config_action = ConfigAction(os.getcwd())
     self.clean_action.clean_action(False, False, None)
     self.config_action.config_action(target_locales=self.locales_to_test)
     # self.action.open()
     self.downloaded = []
     self.files = []
     self.dir_name = "dir1"
     create_directory(self.dir_name)
     self.add_action.add_action([self.dir_name], overwrite=True)
Ejemplo n.º 7
0
class TestWatch(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = WatchAction(os.getcwd())
        self.files = ['sample.txt']
        for fn in self.files:
            create_txt_file(fn)
        self.downloaded = []
        self.action.add_action(None, ['sample*.txt'], force=True)
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)
        # todo current problem: watchdog does not seem to detect changes in daemon
        # but not daemonizing watch causes tests to hang..
        watch_thread = Thread(target=self.action.watch_action, args=(None, (), None, 5,))
        watch_thread.daemon = True
        watch_thread.start()

    def tearDown(self):
        for fn in self.files:
            self.action.rm_action(fn, True)
        self.action.clean_action(False, False, None)
        for fn in self.downloaded:
            os.remove(fn)

    def test_watch_new_file(self):
        file_name = "new_file.txt"
        added_file = create_txt_file(file_name)
        # check if watch detected file and added it to db
        assert self.action.doc_manager.get_doc_by_prop('name', file_name)

    def test_watch_update(self):
        append_file(self.files[0])
        time.sleep(20)
        downloaded_path = self.action.download_action(self.doc_ids[0], None, False)
        self.downloaded.append(downloaded_path)
        with open(downloaded_path, 'r') as f:
            downloaded = f.read()
        assert "Appended text. " in downloaded
Ejemplo n.º 8
0
class TestWatch(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = WatchAction(os.getcwd(), 1)
        self.action.clean_action(False, False, None)
        # self.action.open()
        self.downloaded = []
        self.files = []
        self.dir_name = "dir1"
        create_directory(self.dir_name)
        self.action.add_action([self.dir_name], force=True)
        # todo current problem: watchdog does not seem to detect changes in daemon
        # but not daemonizing watch causes tests to hang..
        watch_thread = Thread(target=self.action.watch_action, args=('.', (), None))
        watch_thread.daemon = True
        watch_thread.start()

    def tearDown(self):
        #delete files
        for fn in self.files:
            self.action.rm_action(fn, force=True)
        self.action.clean_action(False, False, None)
        #delete downloads
        for fn in self.downloaded:
            os.remove(fn)
        #delete directory
        delete_directory(self.dir_name)

    def test_watch_new_file(self):
        file_name = "test_watch_sample_0.txt"
        self.files.append(self.dir_name+"/"+file_name)
        if os.path.exists(self.dir_name+file_name):
            delete_file(file_name)
        create_txt_file(file_name, self.dir_name)

        # check if watch detected file and added it to db
        doc = None
        time_passed = 0
        while doc is None and time_passed < 10:
            doc = self.action.doc_manager.get_doc_by_prop('name', file_name)
            time.sleep(1)
            time_passed += 1
        assert doc
        assert poll_doc(self.action, doc['id'])

    def test_watch_update(self):
        file_name = "test_watch_sample_1.txt"
        self.files.append(self.dir_name+'/'+file_name)
        if os.path.exists(self.dir_name+file_name):
            delete_file(file_name)
        create_txt_file(file_name, self.dir_name)

        doc = None
        time_passed = 0
        while doc is None and time_passed < 10:
            doc = self.action.doc_manager.get_doc_by_prop('name', file_name)
            time.sleep(1)
            time_passed += 1
        assert doc
        assert poll_doc(self.action, doc['id'])

        append_file(file_name, self.dir_name)
        #assert check_updated_ids(self.action, [doc['id']])
        with open(self.dir_name+'/'+file_name, 'r') as f:
            downloaded = f.read()
        assert "Appended text." in downloaded