Esempio n. 1
0
    def setUp(self):
        super(ListAssociatedFiles, self).setUp()
        self.test_tree = os.path.join(self.FILEDIR, 'associated_files', 'random', 'recursive', 'subdir')

        file_names = [
            'Show Name [SickRage].avi',
            'Show Name [SickRage].srt',
            'Show Name [SickRage].nfo',
            'Show Name [SickRage].en.srt',
            'Non-Associated Show [SickRage].srt',
            'Non-Associated Show [SickRage].en.srt',
            'Show [SickRage] Non-Associated.en.srt',
            'Show [SickRage] Non-Associated.srt',
        ]
        self.file_list = [os.path.join(self.FILEDIR, f) for f in file_names] + [os.path.join(self.test_tree, f) for f in
                                                                                file_names]
        self.post_processor = PostProcessor('Show Name')
        self.post_processor._log = _log
        self.maxDiff = None
        sickrage.app.config.move_associated_files = True
        sickrage.app.config.allowed_extensions = ''

        make_dirs(self.test_tree)
        for test_file in self.file_list:
            io.open(test_file, 'a').close()
Esempio n. 2
0
    def setUp(self):
        super(ListAssociatedFiles, self).setUp()
        self.test_tree = os.path.join(self.FILEDIR, 'associated_files',
                                      'random', 'recursive', 'subdir')

        file_names = [
            'Show Name [SickRage].avi',
            'Show Name [SickRage].srt',
            'Show Name [SickRage].nfo',
            'Show Name [SickRage].en.srt',
            'Non-Associated Show [SickRage].srt',
            'Non-Associated Show [SickRage].en.srt',
            'Show [SickRage] Non-Associated.en.srt',
            'Show [SickRage] Non-Associated.srt',
        ]
        self.file_list = [
            os.path.join(self.FILEDIR, f) for f in file_names
        ] + [os.path.join(self.test_tree, f) for f in file_names]
        self.post_processor = PostProcessor('Show Name')
        self.post_processor._log = _log
        self.maxDiff = None
        sickrage.app.config.move_associated_files = True
        sickrage.app.config.allowed_extensions = ''

        make_dirs(self.test_tree)
        for test_file in self.file_list:
            open(test_file, 'a').close()
Esempio n. 3
0
    def rename_ep_file(self, cur_path, new_path, old_path_length=0):
        """
        Creates all folders needed to move a file to its new location, renames it, then cleans up any folders
        left that are now empty.

        :param  cur_path: The absolute path to the file you want to move/rename
        :param new_path: The absolute path to the destination for the file WITHOUT THE EXTENSION
        :param old_path_length: The length of media file path (old name) WITHOUT THE EXTENSION
        """

        # new_dest_dir, new_dest_name = os.path.split(new_path)

        if old_path_length == 0 or old_path_length > len(cur_path):
            # approach from the right
            cur_file_name, cur_file_ext = os.path.splitext(cur_path)
        else:
            # approach from the left
            cur_file_ext = cur_path[old_path_length:]
            cur_file_name = cur_path[:old_path_length]

        if cur_file_ext[1:] in Subtitles().subtitle_extensions:
            # Extract subtitle language from filename
            sublang = os.path.splitext(cur_file_name)[1][1:]

            # Check if the language extracted from filename is a valid language
            if sublang in Subtitles().subtitle_code_filter():
                cur_file_ext = '.' + sublang + cur_file_ext

        # put the extension on the incoming file
        new_path += cur_file_ext

        make_dirs(os.path.dirname(new_path))

        # move the file
        try:
            sickrage.app.log.info("Renaming file from %s to %s" % (cur_path, new_path))
            move_file(cur_path, new_path)
        except (OSError, IOError) as e:
            sickrage.app.log.warning("Failed renaming %s to %s : %r" % (cur_path, new_path, e))
            return False

        # clean up any old folders that are empty
        delete_empty_folders(os.path.dirname(cur_path))

        return True