Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This one's a little dangerous but necessary...adding a rename_app met…

…hod to fabfile. fab rename_app:yourapp. Probably only use this for initial setup
  • Loading branch information...
commit c2797fc65087fa5fb2720d261814148fc5cd26b5 1 parent 8203257
Al authored
Showing with 25 additions and 1 deletion.
  1. +25 −1
@@ -1,4 +1,11 @@
from fabric.api import local
+import logging
+log = logging.getLogger('fabric')
+ch = logging.StreamHandler()
APP_NAME = open('./').readline().strip()
ENV = open('./this.environment').readline().strip()
@@ -12,6 +19,24 @@ def switch_env(env):
local('echo "%s" > ./this.environment' % env)
+def rename_app(new_name):
+ old_name = APP_NAME
+ print """CAUTION: this is a pretty dumb renaming strategy: it will just replace the current all python files for the following patterns: ["from APP_NAME(...)", "import APP_NAME(...)"]. It also assumes that your source directory is in the same dir as your fabfile (may not be good if you want to use a source dir for eclipse, etc.) Intended for use when first naming your project.
+ if raw_input('Are you sure you want to do this[y|N]? ').lower() == 'y':
+ sed_cmd = 'sed -i "{s/from[\ ]*%(old)s/from %(new)s/g;s/import[\ ]*%(old)s/import %(new)s/g;}"' % {'old': old_name, 'new': new_name}
+'Updating .py files in source dir...')
+ local ('find ./%(old_name)s -type f -follow -name "*.py" | xargs %(sed_cmd)s' % {'sed_cmd': sed_cmd, 'old_name': old_name})
+ local('%s' % sed_cmd)
+'Moving old source dir...')
+ local('mv %(old_dir)s %(new_dir)s' % {'old_dir': old_name, 'new_dir': new_name})
+'Changing for future fabric tasks')
+ local("echo '%s' > ./" % new_name)
def start():
local('./env/bin/python runserver %s' % ENV)
@@ -23,4 +48,3 @@ def controller(name):
'app_name': APP_NAME,
'filename': name}, capture=False)
Please sign in to comment.
Something went wrong with that request. Please try again.