コード例 #1
0
def rename_folder(directory):
    settings.debug_message("Attempting rename of parent folder!")

    translated_folder = folder_translator(directory)

    if translated_folder is None:
        print("{} has an issue I can't recover from. Skipping!".
              format(directory))
        try:
            rename_skipped(directory)
        except OSError:
            settings.debug_message("{} is locked by the OS. Skipping!".
                                   format(directory))
            pass
    else:
        new_directory = "{} ({})".format(translated_folder[0],
                                         translated_folder[1])
        try:
            os.rename(os.path.join(settings.incoming_dir, directory),
                      os.path.join(
                      settings.incoming_dir, new_directory))
            settings.debug_message("Rename successful!")
        except OSError:
            settings.debug_message("Access denied while trying to rename {}!".
                                   format(new_directory))
            return None

        return new_directory
コード例 #2
0
def process_folders(dirs):
    for directory in dirs:
        settings.debug_message("Switching to directory {}".format(directory))

        if not check_for_skips(directory):

            dir_files = [f for f in os.listdir(os.path.join(settings.
                         incoming_dir, directory)) if
                         os.path.isfile(os.path.join(settings.incoming_dir,
                                        directory, f))]
            try:
                if not in_use(os.path.join(settings.incoming_dir, directory,
                              dir_files[0])):
                    settings.debug_message("Folder is good to go - time to see"
                                           " if it's a video folder!")
                    if is_video_folder(directory, dir_files):
                        process_movie(directory, dir_files, rename_and_move)
                    else:
                        settings.debug_message("Folder does not appear to be a"
                                               "movie. Skipping.")

                    if is_audio_folder(directory, dir_files):
                        #  There will eventually be a process_audio() function
                        #  here, but for now we just need to move stuff.
                        move_folder(directory, 'audio')
                    else:
                        settings.debug_message("Folder does not appear to be "
                                               "an album. Skipping.")

            except IndexError:

                try:

                    dir_folders = [f for f in os.listdir(os.path.join(settings.
                                   incoming_dir, directory)) if os.path.isdir(
                                   os.path.join(settings.incoming_dir,
                                                directory, f))]

                    if dir_folders[0].lower() == "video_ts":
                        rename_and_move(directory)

                except IndexError:
                    settings.debug_message("Folder appears to be empty. Will "
                                           "mark as skip and move on.")
                    rename_skipped(directory)

            else:
                settings.debug_message("Can't use folder!"
                                       " Moving to next folder.")