(adoc_filename, apparent_filename, includes, src_images, dest_images, parents)
| 13 | return os.path.normpath(os.path.join(os.path.dirname(filename), relative_link)) |
| 14 | |
| 15 | def scan_adoc(adoc_filename, apparent_filename, includes, src_images, dest_images, parents): |
| 16 | parents.add(adoc_filename) |
| 17 | # look for image files |
| 18 | with open(os.path.join(input_dir, adoc_filename)) as fh: |
| 19 | contents = fh.read() |
| 20 | includes[adoc_filename] = set() |
| 21 | joinee_dir = os.path.dirname(adoc_filename) |
| 22 | # look for includes |
| 23 | for include in re.findall(r'(?:^|\n)include::(.+?)\[\](?:\n|$)', contents): |
| 24 | include_adoc = os.path.join(joinee_dir, include) |
| 25 | if include_adoc in parents: |
| 26 | raise Exception("{} includes {} which creates an infinite loop".format(adoc_filename, include_adoc)) |
| 27 | includes[adoc_filename].add(include_adoc) |
| 28 | scan_adoc(include_adoc, apparent_filename, includes, src_images, dest_images, parents.copy()) |
| 29 | # look for image files |
| 30 | for file in re.findall(r'image::?(.+?)\[.*\]', contents): |
| 31 | if not (file.startswith('http:') or file.startswith('https:')): |
| 32 | image_filename = resolve_url(adoc_filename, file) |
| 33 | dest_image = resolve_url(apparent_filename, file) |
| 34 | if dest_image in dest_images and dest_images[dest_image] != image_filename: |
| 35 | raise Exception("{} and {} would both end up as {}".format(dest_images[dest_image], image_filename, dest_image)) |
| 36 | src_images[image_filename] = dest_image |
| 37 | dest_images[dest_image] = image_filename |
| 38 | # look for video webm files, ignore youtube videos and all other formats for now (must update later if this changes) |
| 39 | for file in re.findall(r'video::?(.+?)\[.*\]', contents): |
| 40 | if file.endswith('.webm'): |
| 41 | video_filename = resolve_url(adoc_filename, file) |
| 42 | dest_video = resolve_url(apparent_filename, file) |
| 43 | if dest_video in dest_images and dest_images[dest_video] != video_filename: |
| 44 | raise Exception("{} and {} would both end up as {}".format(dest_images[dest_video], video_filename, dest_video)) |
| 45 | src_images[video_filename] = dest_video |
| 46 | dest_images[dest_video] = video_filename |
| 47 | |
| 48 | def add_entire_directory(tab_dir, dir_path, pages_set, src_images, dest_images): |
| 49 | #print("Adding all files from {} directory".format(tab_dir)) |
no test coverage detected