Example #1
0
def _sed(r, regexpr, repl, force=False, recursive=False, dpath_list=None):
    if True:
        import utool as ut
        force = ut.smart_cast2(force)
        include_patterns = [
            '*.py', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.pyx',
            '*.pxi', '*.cmake', 'CMakeLists.txt'
        ]
        ut.sed(regexpr,
               repl,
               force=force,
               recursive=recursive,
               dpath_list=dpath_list,
               verbose=True,
               include_patterns=include_patterns)
        return
    else:
        #_grep(r, [repl], dpath_list=dpath_list, recursive=recursive)
        force = rutil.cast(force, bool)
        recursive = rutil.cast(recursive, bool)
        import utool as ut
        pyext = ut.get_argflag('--pyext')
        if pyext:
            include_patterns = ['*.py']
        else:
            include_patterns = [
                '*.py', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h',
                '*.pyx', '*.pxi', '*.cmake', 'CMakeLists.txt'
            ]
        if ut.get_argflag('--all'):
            include_patterns = ['*']
        #if ut.get_argflag('--tex'):
        include_patterns = ['*.tex']
        if dpath_list is None:
            dpath_list = [os.getcwd()]
        regexpr = extend_regex(regexpr)
        #import re
        print('sed-ing %r' % (dpath_list, ))
        print(' * regular include_patterns : %r' % (include_patterns, ))
        print(' * (orig) regular expression : %r' % (regexpr, ))
        print(' * (origstr) regular expression : %s' % (regexpr, ))
        #regexpr = re.escape(regexpr)
        print(' * regular expression : %r' % (regexpr, ))
        print(' * (str)regular expression : %s' % (regexpr, ))
        print(' * replacement        : %r' % (repl, ))
        print(' * recursive: %r' % (recursive, ))
        print(' * force: %r' % (force, ))
        if '\x08' in regexpr:
            print('Remember \\x08 != \\b')
            print('subsituting for you for you')
            regexpr = regexpr.replace('\x08', '\\b')
            print(' * regular expression : %r' % (regexpr, ))

        # Walk through each directory recursively
        num_changed = 0
        for fpath in _matching_fnames(dpath_list,
                                      include_patterns,
                                      recursive=recursive):
            num_changed += len(__regex_sedfile(fpath, regexpr, repl, force))
        print('total lines changed = %r' % (num_changed, ))
Example #2
0
def _sed(r, regexpr, repl, force=False, recursive=False, dpath_list=None):
    import utool as ut
    force = ut.smart_cast2(force)
    include_patterns = ['*.py', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.pyx', '*.pxi', '*.cmake', 'CMakeLists.txt']
    ut.sed(regexpr, repl, force=force, recursive=recursive,
           dpath_list=dpath_list, verbose=True, include_patterns=include_patterns)
    return
 def set_param(iiter, actionkey, value, viz_index_=viz_index_):
     """
     value = 'search_K=3'
     """
     paramkey, paramval = value.split('=')
     print('parsing value=%r' % (value,))
     def strip_quotes(str_):
         dq = ut.DOUBLE_QUOTE
         sq = ut.SINGLE_QUOTE
         return str_.strip(dq).strip(sq).strip(dq)
     # Sanatize
     paramkey = strip_quotes(paramkey.strip())
     paramval = ut.smart_cast2(strip_quotes(paramval.strip()))
     print('setting cfgdict[%r]=%r' % (paramkey, paramval))
     iiter.iterable[iiter.index][paramkey] = paramval
Example #4
0
def _sed(r, regexpr, repl, force=False, recursive=False, dpath_list=None):
    if True:
        import utool as ut

        force = ut.smart_cast2(force)
        ut.sed(regexpr, repl, force=force, recursive=recursive, dpath_list=dpath_list, verbose=True)
        return
    else:
        # _grep(r, [repl], dpath_list=dpath_list, recursive=recursive)
        force = rutil.cast(force, bool)
        recursive = rutil.cast(recursive, bool)
        import utool as ut

        pyext = ut.get_argflag("--pyext")
        if pyext:
            include_patterns = ["*.py"]
        else:
            include_patterns = ["*.py", "*.cxx", "*.cpp", "*.hxx", "*.hpp", "*.c", "*.h", "*.pyx", "*.pxi"]
        if ut.get_argflag("--all"):
            include_patterns = ["*"]
        # if ut.get_argflag('--tex'):
        include_patterns = ["*.tex"]
        if dpath_list is None:
            dpath_list = [os.getcwd()]
        regexpr = extend_regex(regexpr)
        # import re
        print("sed-ing %r" % (dpath_list,))
        print(" * regular include_patterns : %r" % (include_patterns,))
        print(" * (orig) regular expression : %r" % (regexpr,))
        print(" * (origstr) regular expression : %s" % (regexpr,))
        # regexpr = re.escape(regexpr)
        print(" * regular expression : %r" % (regexpr,))
        print(" * (str)regular expression : %s" % (regexpr,))
        print(" * replacement        : %r" % (repl,))
        print(" * recursive: %r" % (recursive,))
        print(" * force: %r" % (force,))
        if "\x08" in regexpr:
            print("Remember \\x08 != \\b")
            print("subsituting for you for you")
            regexpr = regexpr.replace("\x08", "\\b")
            print(" * regular expression : %r" % (regexpr,))

        # Walk through each directory recursively
        num_changed = 0
        for fpath in _matching_fnames(dpath_list, include_patterns, recursive=recursive):
            num_changed += len(__regex_sedfile(fpath, regexpr, repl, force))
        print("total lines changed = %r" % (num_changed,))
Example #5
0
    def set_param(iiter, actionkey, value, viz_index_=viz_index_):
        """
        value = 'search_K=3'
        """
        paramkey, paramval = value.split('=')
        print('parsing value=%r' % (value, ))

        def strip_quotes(str_):
            dq = ut.DOUBLE_QUOTE
            sq = ut.SINGLE_QUOTE
            return str_.strip(dq).strip(sq).strip(dq)

        # Sanatize
        paramkey = strip_quotes(paramkey.strip())
        paramval = ut.smart_cast2(strip_quotes(paramval.strip()))
        print('setting cfgdict[%r]=%r' % (paramkey, paramval))
        iiter.iterable[iiter.index][paramkey] = paramval