diff options
| author | Chris McDonough <chrism@plope.com> | 2010-10-25 12:35:23 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2010-10-25 12:35:23 -0400 |
| commit | 6f19024d79f091f1310ed547d7a1eb93b457e07e (patch) | |
| tree | f0702d75f9c96c8da45aa19f8cb4c7a1e01b6462 | |
| parent | 8e9b6288d29837f8271f06073ba53e8616c19f5d (diff) | |
| download | pyramid-6f19024d79f091f1310ed547d7a1eb93b457e07e.tar.gz pyramid-6f19024d79f091f1310ed547d7a1eb93b457e07e.tar.bz2 pyramid-6f19024d79f091f1310ed547d7a1eb93b457e07e.zip | |
fix ZCML too
| -rw-r--r-- | pyramid/fixers/fix_bfg_imports.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/pyramid/fixers/fix_bfg_imports.py b/pyramid/fixers/fix_bfg_imports.py index e93181be4..6a30c7710 100644 --- a/pyramid/fixers/fix_bfg_imports.py +++ b/pyramid/fixers/fix_bfg_imports.py @@ -1,3 +1,5 @@ +import os +import re import sys from lib2to3.refactor import get_fixers_from_package @@ -165,13 +167,40 @@ class FixBfgImports(fixer_base.BaseFix): if new_name: node.replace(Name(new_name, prefix=bare_name.prefix)) +BFG_INCLUDES_RE = ( + r'include\s+?package\s*?=\s*?[\'\"]repoze\.bfg\.includes[\'\"]') +BFG_NS_RE = ( + r'xmlns\s*?=\s*?[\'\"]http://namespaces\.repoze\.org/bfg[\'\"]') + +INCLUDES = re.compile(BFG_INCLUDES_RE, re.MULTILINE) +NS = re.compile(BFG_NS_RE, re.MULTILINE) + +def fix_zcml(path): + for root, dirs, files in os.walk(path): + for file in files: + if file.endswith('.zcml'): + absfile = os.path.join(root, file) + text = open(absfile, 'rb').read() + newt =INCLUDES.sub('include package="pyramid.includes"', text) + newt = NS.sub('xmlns="http://pyramid.pylonshq.com"', newt) + if text != newt: + newf = open(absfile, 'wb') + newf.write(newt) + newf.flush() + newf.close() + + for dir in dirs: + if dir.startswith('.'): + dirs.remove(dir) + def main(argv=None): if argv is None: argv = sys.argv path = argv[1] - fixer_names = get_fixers_from_package('repoze.bfg.fixers') + fixer_names = get_fixers_from_package('pyramid.fixers') tool = RefactoringTool(fixer_names) tool.refactor([path], write=True) + fix_zcml(path) if __name__ == '__main__': main() |
