#find . -name '*pyc' | xargs rm
mv mediacore mediadrop

find mediadrop/ batch-scripts/ setup.py doc/ -name '*.py' | xargs -n1 sed -i 's/from mediacore\(.\+\?\) import \(.\+\?\)$/from mediadrop\1 import \2/g'
find mediadrop/ batch-scripts/ setup.py doc/ -name '*.py' | xargs -n1 sed -i 's/import mediacore\(.\+\?\)$/import mediadrop\1/g'
find doc/ -name '*.rst' | xargs -n1 sed -i 's/from mediacore\(.\+\?\) import \(.\+\?\)$/from mediadrop\1 import \2/g'

# i18n
find . -name 'mediacore.po' -exec sh -c 'mv {} `dirname {}`/mediadrop.po' \;
mv mediadrop/i18n/mediacore.pot mediadrop/i18n/mediadrop.pot
find mediadrop/i18n/ -type f | xargs -n1 sed -i 's/mediacore/mediadrop/g'
find . -name '*.html' -type f | xargs -n1 sed -i 's/i18n:domain="mediacore"/i18n:domain="mediadrop"/g'

# replace mediacore in docstrings and comments
find . -name '*.rst' -o -name '*.py' | xargs -n1 sed -i "s/\([\`~ <]\)mediacore\([.\/]\)/\1mediadrop\2/g"

find . -name '*.rst' | xargs -n1 sed -i 's/\`mediacore\//\`mediadrop\//g'
find . -name '*.rst' | xargs -n1 sed -i 's/mediacore_install/mediadrop_install/g'

find batch-scripts/ deployment-scripts/ doc/ mediadrop/ -type f | xargs -n1 sed -i 's/mediacore.fcgi/mediadrop.fcgi/g'
find batch-scripts/ deployment-scripts/ doc/ mediadrop/ -type f | xargs -n1 sed -i 's/mediacore.wsgi/mediadrop.wsgi/g'
mv deployment-scripts/mod_fastcgi/mediacore.fcgi deployment-scripts/mod_fastcgi/mediadrop.fcgi 
mv deployment-scripts/mod_wsgi/mediacore.wsgi deployment-scripts/mod_wsgi/mediadrop.wsgi
mv deployment-scripts/uwsgi/mediacore.wsgi deployment-scripts/uwsgi/mediadrop.wsgi

sed -i "s/the mediacore /the 'mediadrop' /g" mediadrop/lib/i18n.py mediadrop/lib/decorators.py
sed -i 's/mediacore\\\.fcgi/mediadrop\.fcgi/' deployment-scripts/mod_fastcgi/.htaccess
find . -name '*.rst' -o -name '*.py' | xargs -n1  sed -i 's/`mediacore/`mediadrop/g'
sed -i 's/mediacore.sock/mediadrop.soc/' doc/install/nginx-uwsgi.rst
find doc/ -name '*rst' | xargs -n1 sed -i 's/\/mediacore\//\/mediadrop\//g'
find . -name '*.html' -o -name '*.js' | xargs -n1 sed -i 's/\/mediacore\//\/mediadrop\//g'

sed -i 's/\/mediacore\//\/mediadrop\//g' deployment-scripts/mod_wsgi/apache-config.sample
sed -i 's/mediacore_/mediadrop_/g' deployment-scripts/mod_wsgi/apache-config.sample
sed -i 's/ mediacore / MediaDrop /g' deployment-scripts/mod_wsgi/apache-config.sample

sed -i 's/"mediacore\//"mediadrop\//g' LICENSE.txt
sed -i 's/mediacore\//mediadrop\//' .gitignore

find . -name '*.rst' -o -name '*.py' | xargs -n1 sed -i 's/:`mediacore\//:`mediadrop\//g'

sed -i "s/'mediacore'/'mediadrop'/g" mediadrop/controllers/admin/settings.py
ack -l mediacore.__file__ | xargs -n1 sed -i 's/mediacore.__file__/mediadrop.__file__/g'
sed -i "s/'mediacore'/'mediadrop'/g" setup.py mediadrop/config/environment.py mediadrop/lib/i18n.py mediadrop/lib/test/support.py
ack -l mediacore batch-scripts | xargs -n1 sed -i 's/mediacore/mediadrop/g'
sed -i 's/mediacore/mediadrop/g' MANIFEST.in mediadrop/lib/test/support.py mediadrop/lib/i18n.py mediadrop/lib/thumbnails.py
sed -i "s/'mediacore/'mediadrop/g" setup.py mediadrop/migrations/util.py

# avoid renaming __mediacore_serve__ in the ini files
sed -i 's/\([^\_][^\_]\)mediacore/\1mediadrop/g' *ini mediadrop/config/deployment.ini_tmpl .tx/config
sed -i 's/redirect_url_if_mediacore_is_mounted/redirect_url_if_mediadrop_is_mounted/g' mediadrop/controllers/tests/login_test.py

sed -i 's/mediacore_permission_system_test/mediadrop_permission_system_test/g' mediadrop/lib/test/__init__.py

sed -i 's/mediacore/mediadrop/g' .tx/config mediadrop/controllers/sitemaps.py setup.cfg
sed -i 's/MediaCore/MediaDrop/g' deployment-scripts/mod_fastcgi/mediadrop.fcgi

find mediadrop/ -name 'mediacore.mo' | xargs rm

sed -i 's/instance of mediacore is/instance of MediaDrop is/g' mediadrop/lib/base.py
sed -i 's/"mediacore.model/"mediadrop.model/g' mediadrop/model/tests/media_status_test.py

sed -i 's/running MediaCore, you will/running MediaDrop, you will/g' deployment-scripts/mod_wsgi/mediadrop.wsgi deployment-scripts/uwsgi/mediadrop.wsgi
sed -i "s/not compiled together with MediaCore's closure/not compiled together with MediaDrop's closure/g" mediadrop/public/scripts/mcore/players/controller.js
sed -i 's/MediaCore extension/MediaDrop extension/g' mediadrop/public/scripts/third-party/squeezebox-1.1-rc4.js
sed -i 's/see if MediaCore tables/see if MediaDrop tables/g' mediadrop/websetup.py
sed -i 's/your MediaCore install/your MediaDrop install/g' mediadrop/websetup.py
sed -i 's/that MediaCore should try/that MediaDrop should try/g' mediadrop/model/players.py
sed -i 's/MediaCore/MediaDrop/g' mediadrop/controllers/api/media.py

ack -l mediacore-content  | xargs sed -i 's/mediacore-content/mediadrop-content/g'
