From 6f19024d79f091f1310ed547d7a1eb93b457e07e Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 25 Oct 2010 12:35:23 -0400 Subject: fix ZCML too --- pyramid/fixers/fix_bfg_imports.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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() -- cgit v1.2.3