-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added bash to update memcache with pymemcache
- Loading branch information
1 parent
153d3f5
commit 97bda59
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
edx_repo_tools/codemods/django42/script_to_update_pymemcache.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/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' {} + | ||
} | ||
|
||
# Function to find and append "pymemcache" to base.in files | ||
function append_pymemcache() { | ||
local root_dir=$1 | ||
find "$root_dir" -type f -name "base.in" -exec sh -c 'echo "pymemcache" >> "$0"' {} \; | ||
} | ||
|
||
# Function to find and remove the line containing "python-memcached==<version>" | ||
function remove_python_memcached() { | ||
local root_dir=$1 | ||
find "$root_dir" -type f -exec perl -i -ne 'print unless /^python-memcached==.*$/' {} + | ||
} | ||
|
||
# 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" | ||
|
||
# Append "pymemcache" to base.in files | ||
echo "Appending 'pymemcache' to base.in files in project: $current_dir" | ||
append_pymemcache "$current_dir" | ||
echo "Appending 'pymemcache' completed in project: $current_dir" | ||
|
||
# Remove lines containing "python-memcached==<version>" | ||
echo "Removing 'python-memcached' lines in project: $current_dir" | ||
remove_python_memcached "$current_dir" | ||
echo "Removal of 'python-memcached' lines completed in project: $current_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters