Beispiel #1
0
    def run(self):
        if utils.is_process_already_running(
                self.settings.get('DUMMY_FILE_PATH')):
            self.process_response([('error', PROCESS_RUNNING)])
            return

        try:
            utils.create_file(self.settings.get('DUMMY_FILE_PATH'))

            # Scan and Extract all compressed files
            self.scan_archives()

            # Scan and move/copy videos
            self.scan_videos()

            # UPDATE XBMC
            response = utils.update_xbmc(self.settings.get('KODI_IP'))
            self.process_response(response)

            # CLEAN UP
            for folder_path in utils.get_folders(self.unsorted_path):
                response = utils.delete_folder_if_empty(folder_path)
                self.process_response(response)

        except Exception as e:
            self.process_response([('error', traceback.print_exc())])
            self.process_response([('error', str(e))])

        finally:
            response = utils.delete_file(self.settings.get('DUMMY_FILE_PATH'))
            self.process_response(response)

        return
Beispiel #2
0
    def run(self):
        if utils.is_process_already_running(self.settings.get('DUMMY_FILE_PATH')):
            self.process_response([('error', PROCESS_RUNNING)])
            return

        try:
            utils.create_file(self.settings.get('DUMMY_FILE_PATH'))

            # Scan and Extract all compressed files
            self.scan_archives()

            # Scan and move/copy videos
            self.scan_videos()

            # UPDATE XBMC
            response = utils.update_xbmc(self.settings.get('KODI_IP'))
            self.process_response(response)

            # CLEAN UP
            for folder_path in utils.get_folders(self.unsorted_path):
                response = utils.delete_folder_if_empty(folder_path)
                self.process_response(response)

        except Exception as e:
            self.process_response([('error', traceback.print_exc())])
            self.process_response([('error', str(e))])

        finally:
            response = utils.delete_file(self.settings.get('DUMMY_FILE_PATH'))
            self.process_response(response)

        return
Beispiel #3
0
def test_main_process_running(_, __):
    dummy_file_path = tv_sort.settings.get('DUMMY_FILE_PATH')
    utils.create_file(dummy_file_path)
    tv_sort.run()
    assert all(x == PROCESS_RUNNING for x in tv_sort.report.get('errors'))
    tv_sort.run()
    response = utils.delete_file(dummy_file_path)
    assert response[0][0] == 'info'
    assert tv_sort.is_send_report() is False
Beispiel #4
0
def test_main_process_running(_, __):
    dummy_file_path = tv_sort.settings.get('DUMMY_FILE_PATH')
    utils.create_file(dummy_file_path)
    tv_sort.run()
    assert all(x == PROCESS_RUNNING for x in tv_sort.report.get('errors'))
    tv_sort.run()
    response = utils.delete_file(dummy_file_path)
    assert response[0][0] == 'info'
    assert tv_sort.is_send_report() is False
Beispiel #5
0
def test_move_file():
    test_file_path = tv_sort.settings.get('TEST_FILE_PATH')
    utils.create_file(test_file_path)
    new_path = tv_sort.settings.get('TV_PATH')
    new_test_file_path = os.path.join(new_path, utils.get_file_name(test_file_path))

    response = utils.copy_file(test_file_path, new_path)
    assert response[0][0] == 'info'

    # Clean-up
    response = utils.delete_file(new_test_file_path)
    assert response[0][0] == 'info'
Beispiel #6
0
def test_move_file():
    test_file_path = tv_sort.settings.get('TEST_FILE_PATH')
    utils.create_file(test_file_path)
    new_path = tv_sort.settings.get('TV_PATH')
    new_test_file_path = os.path.join(new_path,
                                      utils.get_file_name(test_file_path))

    response = utils.copy_file(test_file_path, new_path)
    assert response[0][0] == 'info'

    # Clean-up
    response = utils.delete_file(new_test_file_path)
    assert response[0][0] == 'info'
Beispiel #7
0
def test_delete_file():
    dummy_file_path = tv_sort.settings.get('DUMMY_FILE_PATH')
    response = utils.create_file(dummy_file_path)
    assert response[0][0] == 'info'

    response = utils.delete_file(dummy_file_path)
    assert response[0][0] == 'info'
Beispiel #8
0
def test_delete_file():
    dummy_file_path = tv_sort.settings.get('DUMMY_FILE_PATH')
    response = utils.create_file(dummy_file_path)
    assert response[0][0] == 'info'

    response = utils.delete_file(dummy_file_path)
    assert response[0][0] == 'info'
Beispiel #9
0
def test_move_file_already_exists():
    test_file_path = tv_sort.settings.get('TEST_FILE_PATH')
    new_path = tv_sort.settings.get('TV_PATH')
    new_test_file_path = os.path.join(new_path, utils.get_file_name(test_file_path))

    response = utils.create_file(test_file_path)
    assert response[0][0] == 'info'
    response = utils.copy_file(test_file_path, new_path, move_file=False)
    assert response[0][0] == 'info'

    response = utils.create_file(test_file_path)
    assert response[0][0] == 'info'
    response = utils.copy_file(test_file_path, new_path)
    tv_sort.logger.error(response)
    assert response[0][0] == 'error'

    # Clean-up
    response = utils.delete_file(new_test_file_path)
    assert response[0][0] == 'info'
Beispiel #10
0
def test_is_file_exists():
    file_path = tv_sort.settings.get('TEST_FILE_PATH')
    assert not utils.is_file_exists(file_path)
    response = utils.create_file(file_path)
    assert response[0][0] == 'info'
    assert 'File was created' in response[0][1]

    assert utils.is_file_exists(file_path)
    response = utils.delete_file(file_path)
    assert response[0][0] == 'info'
Beispiel #11
0
def test_is_file_exists():
    file_path = tv_sort.settings.get('TEST_FILE_PATH')
    assert not utils.is_file_exists(file_path)
    response = utils.create_file(file_path)
    assert response[0][0] == 'info'
    assert 'File was created' in response[0][1]

    assert utils.is_file_exists(file_path)
    response = utils.delete_file(file_path)
    assert response[0][0] == 'info'
Beispiel #12
0
def test_move_file_already_exists():
    test_file_path = tv_sort.settings.get('TEST_FILE_PATH')
    new_path = tv_sort.settings.get('TV_PATH')
    new_test_file_path = os.path.join(new_path,
                                      utils.get_file_name(test_file_path))

    response = utils.create_file(test_file_path)
    assert response[0][0] == 'info'
    response = utils.copy_file(test_file_path, new_path, move_file=False)
    assert response[0][0] == 'info'

    response = utils.create_file(test_file_path)
    assert response[0][0] == 'info'
    response = utils.copy_file(test_file_path, new_path)
    tv_sort.logger.error(response)
    assert response[0][0] == 'error'

    # Clean-up
    response = utils.delete_file(new_test_file_path)
    assert response[0][0] == 'info'
Beispiel #13
0
def test_not_empty_folder():
    file_name = 'dummy1.txt'
    folder_path = tv_sort.settings.get('DUMMY_PATH')
    file_path = os.path.join(folder_path, file_name)
    response = utils.create_file(file_path)
    assert response[0][0] == 'info'
    assert not utils.folder_empty(folder_path)

    # Can't delete not empty folder
    response = utils.delete_folder(folder_path)
    assert all(message[0] == 'error' for message in response)

    response = utils.delete_file(file_path)
    assert response[0][0] == 'info'
Beispiel #14
0
def test_not_empty_folder():
    file_name = 'dummy1.txt'
    folder_path = tv_sort.settings.get('DUMMY_PATH')
    file_path = os.path.join(folder_path, file_name)
    response = utils.create_file(file_path)
    assert response[0][0] == 'info'
    assert not utils.folder_empty(folder_path)

    # Can't delete not empty folder
    response = utils.delete_folder(folder_path)
    assert all(message[0] == 'error' for message in response)

    response = utils.delete_file(file_path)
    assert response[0][0] == 'info'