|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import re |
| 6 | + |
| 7 | +import glob |
| 8 | + |
| 9 | +profile_mappings = \ |
| 10 | + {'your_enterprise_profile': "url='https://pythonapi.playground.esri.com/portal', "\ |
| 11 | + "username='arcgis_python', "\ |
| 12 | + "password='amazing_arcgis123'", |
| 13 | + 'your_online_profile': "url='https://arcgis.com/', "\ |
| 14 | + "username='arcgis_python', "\ |
| 15 | + "password='P@ssword123'" } |
| 16 | + |
| 17 | +regex_find_base = r"profile.*=.*(\\\"|').*{profile_str}.*(\\\"|')" |
| 18 | + |
| 19 | +def _replace_profiles(file_contents): |
| 20 | + for key, value in profile_mappings.items(): |
| 21 | + regex_find = regex_find_base.format(profile_str=key) |
| 22 | + regex_replace = value |
| 23 | + file_contents = re.sub(regex_find, regex_replace, file_contents) |
| 24 | + return file_contents |
| 25 | + |
| 26 | +def _main(): |
| 27 | + root_dir = os.path.abspath(os.path.join( |
| 28 | + os.path.dirname( __file__ ), |
| 29 | + '..', |
| 30 | + '..')) |
| 31 | + guide_dir = os.path.join(root_dir, "guide") |
| 32 | + samples_dir = os.path.join(root_dir, "samples") |
| 33 | + nb_file_paths = \ |
| 34 | + glob.glob(os.path.join(guide_dir, "**", "*.ipynb"), recursive=True) + \ |
| 35 | + glob.glob(os.path.join(samples_dir, "**", "*.ipynb"), recursive=True) |
| 36 | + |
| 37 | + for nb_file_path in nb_file_paths: |
| 38 | + print(f"Replacing profiles in {nb_file_path}") |
| 39 | + f = open(nb_file_path, "r") |
| 40 | + file_contents = f.read() |
| 41 | + file_contents = _replace_profiles(file_contents) |
| 42 | + f.close() |
| 43 | + f = open(nb_file_path, "w") |
| 44 | + f.write(file_contents) |
| 45 | + f.close() |
| 46 | + print(f" Finished!") |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + sys.exit(_main()) |
| 50 | + |
0 commit comments