def _get_replay_beatmap_file(osu_path, replay_file): global _beatmap_cache m = re.search(r"[^\\/]+ \- (.+ \- .+) \[(.+)\] \(.+\)", replay_file) if m is None: return None beatmap, diff = m[1], m[2] beatmap_file_pattern = "*" + glob_escape(beatmap) + "*" + glob_escape("[" + diff + "]") + ".osu" if beatmap_file_pattern in _beatmap_cache: return _beatmap_cache[beatmap_file_pattern] pattern = os.path.join(osu_path, "Songs", "**", beatmap_file_pattern) file_matches = glob(pattern) if len(file_matches) > 0: _beatmap_cache[beatmap_file_pattern] = file_matches[0] return file_matches[0] else: _beatmap_cache[beatmap_file_pattern] = None return None
def _beads(self, conditions) -> Iterable[Archive]: ''' Retrieve matching beads. ''' match = compile_conditions(conditions) bead_names = set(value for tag, value in conditions if tag == bead_spec.BEAD_NAME) if bead_names: if len(bead_names) > 1: # easy path: names disagree return [] # beadname_20170615T075813302092+0200.zip glob = bead_names.pop() + '_????????T????????????[-+]????.zip' else: glob = '*' paths = iglob(Path(glob_escape(self.directory)) / glob) beads = self._archives_from(paths) candidates = (bead for bead in beads if match(bead)) return candidates
def _download_manifest_tasks(self, no_metadata, no_data): with open(self.manifest) as f: bundles = defaultdict(set) # unicode_literals is on so all strings are unicode. CSV wants a str so we need to jump through a hoop. reader = tsv.DictReader(f) for row in reader: bundles[(row['bundle_uuid'], row['bundle_version'])].add(row['file_name']) for (bundle_uuid, bundle_version), data_files in bundles.items(): if no_data: data_filter = ('', ) else: data_filter = tuple( glob_escape(file_name) for file_name in data_files if file_name) if no_metadata: metadata_filter = ('', ) else: metadata_filter = ('*', ) task = functools.partial(self.download_bundle, bundle_uuid, data_filter=data_filter, metadata_filter=metadata_filter) self.runner.submit(bundle_uuid, task)
torrent_content_path = join(save_path, first_file_path[:index]) else: # Путь до файла торрента (когда торрент состоит из одного файла) torrent_content_path = join(save_path, first_file_path) torrent_content_path = normpath(torrent_content_path) torrent_content_path_list.append(torrent_content_path) # Получим файлы, что есть в <save_path_current_paths>, но нет в torrent_content_path_list items = sorted(set(save_path_current_paths) - set(torrent_content_path_list)) print(len(items), items) total_size = 0 for path in items: if isfile(path): size = getsize(path) else: # Найдем все файлы в папке и подпапках и подсчитаем их суммарный размер sub_files = filter(isfile, glob(glob_escape(path) + '/**', recursive=True)) size = sum(getsize(file_name) for file_name in sub_files) total_size += size print(f'{path} ({size} / {sizeof_fmt(size)})') print() print(f'Total size: {total_size} / {sizeof_fmt(total_size)}')