Example #1
0
def changeText(filename, text, newtext=""):
    ''' *Change* (or *remove*) text in this file.
        -- called by changeFiles '''
    filetext = fileText(filename)
    if text in filetext:
        filetext = filetext.replace(text, newtext)
        f = file(filename, 'w')
        f.write(filetext)
        f.close()
        print "file: %s" % filename
def changeText(filename, text, newtext=""):
    ''' *Change* (or *remove*) text in this file.
        -- called by changeFiles '''
    filetext = fileText(filename)
    if text in filetext:
        filetext = filetext.replace(text, newtext)
        f = file(filename, 'w')
        f.write(filetext)
        f.close()
        print "file: %s" % filename
Example #3
0
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)