Sapan Bhatia | 51111c1 | 2016-01-14 11:20:10 -0500 | [diff] [blame] | 1 | Hi, |
| 2 | |
| 3 | I've written a tool called 'chuckmove' for helping move Python modules around in a source tree. You use it as follows. Lets say you want to relocate a module to a different location in the tree, and also rename it. So for instance, x is to become y.z. The syntax you use is: |
| 4 | |
| 5 | chuckmove -o x -n y.z <root directory> |
| 6 | |
| 7 | Invoking this command makes the tool recursively descend into the root directory, make a backup copy of each file (adding the prefix '.orig') and rewrite the imports in it, so that "import x" gets turned into "import y.z" |
| 8 | |
| 9 | It recognizes Python grammar, so it works with all of these forms: |
| 10 | |
| 11 | from x import a |
| 12 | from x.b import c |
| 13 | import x.d.e.f as foo # Comments are also handled |
| 14 | |
| 15 | ...with the nit that lines with syntax/grammatical errors are left as is. |
| 16 | |
| 17 | For example, for the observer/synchronizer changes, I just had to do the following: |
| 18 | |
| 19 | chuckmove -o observer -n synchronizers.base xos |
| 20 | |
| 21 | ...and then to generate a patch with the changes: |
| 22 | |
| 23 | gendiff xos .orig |
| 24 | |
| 25 | It's checked into the xos repository under tools (with a README file!). |
| 26 | |
| 27 | Sapan |