diff --git a/edx_repo_tools/codemods/django42/script_to_update_pymemcache.sh b/edx_repo_tools/codemods/django42/script_to_update_pymemcache.sh new file mode 100644 index 00000000..bc8faa36 --- /dev/null +++ b/edx_repo_tools/codemods/django42/script_to_update_pymemcache.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Function to recursively find and replace the cache backend in files +function update_cache_backend() { + local root_dir=$1 + find "$root_dir" -type f -exec perl -i -pe 's/django\.core\.cache\.backends\.memcached\.MemcachedCache/django.core.cache.backends.memcached.PyMemcacheCache/g' {} + +} + +# Get the current directory +current_dir=$(pwd) + +# Update cache backend in the project +echo "Updating cache backend in project: $current_dir" +update_cache_backend "$current_dir" +echo "Cache backend update completed in project: $current_dir" diff --git a/edx_repo_tools/codemods/django42/update_pymemcache.py b/edx_repo_tools/codemods/django42/update_pymemcache.py new file mode 100644 index 00000000..343a03e2 --- /dev/null +++ b/edx_repo_tools/codemods/django42/update_pymemcache.py @@ -0,0 +1,16 @@ +import click +import subprocess + + +def main(): + """ + Function to call the bash script which is replacing all + django.core.cache.backends.memcached.MemcachedCache references with + django.core.cache.backends.memcached.PyMemcacheCache in the whole + project and adding pymemcache and removing python-memcached in requirements + """ + subprocess.run(['./edx_repo_tools/codemods/django42/script_to_update_pymemcache.sh']) + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 18003cc3..dc1437fe 100644 --- a/setup.py +++ b/setup.py @@ -119,6 +119,7 @@ def is_requirement(line): 'tag_release = edx_repo_tools.release.tag_release:main', 'modernize_tox_django42 = edx_repo_tools.codemods.django42.tox_moderniser_django42:main', 'modernize_github_actions_django42 = edx_repo_tools.codemods.django42.github_actions_modernizer_django42:main', + 'update_cache = edx_repo_tools.codemods.django42.update_pymemcache:main', 'remove_providing_args = edx_repo_tools.codemods.django42.remove_providing_args_arg:main', 'python312_gh_actions_modernizer = edx_repo_tools.codemods.python312.gh_actions_modernizer:main', 'python312_tox_modernizer = edx_repo_tools.codemods.python312.tox_modernizer:main',