Exemplo n.º 1
0
from smart_replacer import SmartReplacer
from smart_copy import SmartCopy
import re

######
## Replace example
######
def callback_func1(groups, match, replace):
    """An example callback method to convert specific groups to upper case"""
    string = match
    for group in groups:
        if group == 'php':
            string = string.replace(group,group.upper())
    return match,string

bulk_replace = SmartReplacer('./')

bulk_replace.add_path_filter('exclude','\.git')
bulk_replace.add_path_filter('match','.*\.txt$')

bulk_replace.add_search_filter({'regex':['<(\?)(php)',],'replace':'not be','callback': callback_func1 })

bulk_replace.run() # replace=True to actually replace the files

######
## Smart copy example: make a prunned copy of my puppet dev repository, with only the .pp and .erb files
######

archiver = SmartCopy() # extends SmartFileManip
archiver.set_opts(['prune_empty','full_copy','purge_existing'])
archiver.copy_from('/Users/nickshobe/Projects/puppet_repo')
#!/usr/bin/python

from smart_replacer import SmartReplacer
from smart_copy import SmartCopy
import re

######
## Replace example
######

bulk_replace = SmartReplacer("/Users/will5324/Projects/cloudGod")

bulk_replace.add_path_filter("exclude", ".git")
bulk_replace.add_path_filter("match", ".*\.py$")

bulk_replace.add_search_filter({"substr": ["libcloud.types"], "replace": "libcloud.compute.types"})

bulk_replace.run(replace=False)  # replace=True to actually replace the files

# bulk_replace.path_debug(2)