Пример #1
0
def main():

    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:], "hi", ["help", "ignorecase"])

    except getopt.GetoptError:
        usage()

    ignorecase = False

    for opt, arg in opts:
        if opt in ( "-h", "--help" ):
            print_help()
        if opt in ( "-i", "--ignorecase" ):
            ignorecase = True

    if not len( args ) == 1: usage()


    for dirname, dirnames, filenames in os.walk('.'):
        for filename in filenames:
            fullname = os.path.join(dirname, filename)

            if myregex.is_cfile(filename) or myregex.is_jsfile(filename):
                file = open(fullname, "r")
                for line in file:
                    if line[-1] == '\n': line = line[:-1]

                    if ignorecase: research = re.search( sys.argv[1], line, re.I )
                    else: research = re.search( sys.argv[1], line )

                    if research: print fullname + ": " + line

                file.close()
Пример #2
0
def main():

    try:
        opts, args = getopt.gnu_getopt(
            sys.argv[1:],
            "h",
            ["help"]
        )

    except getopt.GetoptError:
        print_usage()

    for opt, arg in opts:
        if opt in ( "-h", "--help" ): print_help()

    if len(sys.argv) != 4: 
        print_usage()

    print "** This is silent killer, don't use it without care! ** "

    for root, dirs, files in os.walk( sys.argv[3] ):
        for file in [f for f in files if myregex.is_cfile(f) or myregex.is_jsfile(f) ]:
            change_file = False
            apath = os.path.abspath(root)
            fullpath =  os.path.join(apath, file)
            fd = open(fullpath)
            for line in fd:
                if re.search(sys.argv[1], line):
                    change_file = True

            fd.close()

            if change_file:
                change_file = False
                print fullpath
                command = perl + get_sed(sys.argv[1], sys.argv[2]) + fullpath
                os.system(command)