def _permissions_runner(self, test_base, perms_base="0700", apply_umask=True): # Create base directory and set the base permissions perms_base_int = int(perms_base, 8) self.fs.create_dir(test_base, perms_base_int) assert os.path.exists(test_base) is True self.assert_dir_perms(test_base, perms_base_int) # Create directories with permissions new_dir = os.path.join(test_base, "se 1", "ep1") filesystem.create_all_dirs(new_dir, apply_umask=apply_umask) # If permissions needed to be set, verify the new folder has the # right permissions and verify the base didn't change if apply_umask and cfg.umask(): perms_test_int = int(cfg.umask(), 8) | int("0700", 8) else: # Get the current umask, since os.mkdir masks that out cur_umask = os.umask(0) os.umask(cur_umask) perms_test_int = int("0777", 8) & ~cur_umask self.assert_dir_perms(new_dir, perms_test_int) self.assert_dir_perms(test_base, perms_base_int)
def test_basic_folder_creation(self): self.fs.create_dir("/test_base") # Also test for no crash when folder already exists for folder in ("/test_base", "/test_base/show/season 1/episode 1", "/test_base/show"): assert filesystem.create_all_dirs(folder) == folder assert os.path.exists(folder)
def test_create_all_dirs(self): self.dir = self.fs.create_dir(r"C:\Downloads") # Also test for no crash when folder already exists for folder in (r"C:\Downloads", r"C:\Downloads\Show\Test", r"C:\Downloads\Show\Test2", r"C:\Downloads\Show"): assert filesystem.create_all_dirs(folder) == folder assert os.path.exists(folder)
def prepare_extraction_path(nzo): """Based on the information that we have, generate the extraction path and create the directory. Separated so it can be called from DirectUnpacker """ one_folder = False marker_file = None # Determine class directory catdir = config.get_categories(nzo.cat).dir() if catdir.endswith("*"): catdir = catdir.strip("*") one_folder = True complete_dir = real_path(cfg.complete_dir.get_path(), catdir) complete_dir = long_path(complete_dir) # TV/Movie/Date Renaming code part 1 - detect and construct paths if cfg.enable_meta(): file_sorter = Sorter(nzo, nzo.cat) else: file_sorter = Sorter(None, nzo.cat) complete_dir = file_sorter.detect(nzo.final_name, complete_dir) if file_sorter.sort_file: one_folder = False complete_dir = sanitize_and_trim_path(complete_dir) if one_folder: workdir_complete = create_all_dirs(complete_dir, apply_umask=True) else: workdir_complete = get_unique_path(os.path.join( complete_dir, nzo.final_name), create_dir=True) marker_file = set_marker(workdir_complete) if not workdir_complete or not os.path.exists(workdir_complete): logging.error( T("Cannot create final folder %s") % os.path.join(complete_dir, nzo.final_name)) raise IOError if cfg.folder_rename() and not one_folder: prefixed_path = prefix(workdir_complete, "_UNPACK_") tmp_workdir_complete = get_unique_path(prefix(workdir_complete, "_UNPACK_"), create_dir=False) try: renamer(workdir_complete, tmp_workdir_complete) except: pass # On failure, just use the original name # Is the unique path different? Then we also need to modify the final path if prefixed_path != tmp_workdir_complete: workdir_complete = workdir_complete + os.path.splitext( tmp_workdir_complete)[1] else: tmp_workdir_complete = workdir_complete return tmp_workdir_complete, workdir_complete, file_sorter, one_folder, marker_file