def changeTexts(text, newtext="", dir=None, ext="py"): # parameters if dir is None: dir = os.getcwd() # run print "=== file walk ===" filenames = fileNames(dir, ext) print "\n=== changing files ===" for filename in filenames: changeText(filename, text, newtext)
def insertNotices(notice_filename, linecount=2, dir=None, ext="py"): # params if dir is None: dir = os.getcwd() try: notice = fileText(notice_filename) notice_start = "\n".join(notice.splitlines()[:7]) except IOError: notice = notice_start = None # now, run? print("\ndir: %s\next: %s\nlinecount: %s\nfirst text lines:\n%s\n" % (dir, ext, linecount, notice_start)) answer = raw_input(">>> write notice in files? (y/n)") if not (answer.lower() == "y"): end() # yes, run! print("=== file walk ===") print(linecount, dir) filenames = fileNames(dir, ext) print("\n=== writing notice ===") for filename in filenames: insertNotice(filename, notice, linecount)
def insertNotices(notice_filename, linecount=2, dir=None, ext="py"): # params if dir is None: dir = os.getcwd() try: notice = fileText(notice_filename) notice_start = '\n'.join(notice.splitlines()[:7]) except IOError: notice = notice_start = None # now, run? print ("\ndir: %s\next: %s\nlinecount: %s\nfirst text lines:\n%s\n" % (dir, ext, linecount, notice_start)) answer = raw_input(">>> write notice in files? (y/n)") if not (answer.lower() == 'y'): end() # yes, run! print "=== file walk ===" print linecount, dir filenames = fileNames(dir, ext) print "\n=== writing notice ===" for filename in filenames: insertNotice(filename, notice, linecount)