Пример #1
0
    '*.html',  # text file names
    '*.c',
    '*.cxx',
    '*.h',
    '*.i',
    '*.out',  # in this package
    'README*',
    'makefile*',
    'output*',
    '*.note'
]

if __name__ == '__main__':
    errmsg = 'Required first argument missing: "todos" or "tounix"'
    assert (len(sys.argv) >= 2 and sys.argv[1] in ['todos', 'tounix']), errmsg

    if len(sys.argv) > 2:  # glob anyhow: '*' not applied on dos
        patts = sys.argv[2:]  # though not really needed on linux
    filelists = map(glob.glob, patts)  # name matches in this dir only

    count = 0
    for list in filelists:
        for fname in list:
            if listonly:
                print count + 1, '=>', fname
            else:
                convertEndlines(sys.argv[1], fname)
            count += 1

    print 'Visited %d files' % count
 def visitfile(self, fullname):                        # match on basename
     basename = os.path.basename(fullname)             # to make result same
     for patt in patts:                                # else visits fewer 
         if fnmatch.fnmatch(basename, patt):
             convertEndlines(self.context, fullname)
             self.fcount = self.fcount + 1             # could break here
            matches = []
            for patt in patts:
                findcmd = 'find . -name "%s" -print' % patt  # run find command
                lines = os.popen(findcmd).readlines()        # remove endlines
                matches.append(map(string.strip, lines))     # lambda x: x[:-1]
    except:
        assert 0, 'Sorry - cannot find files'
    if debug: print matches
    return matches

if __name__ == '__main__':
    from fixeoln_dir import patts
    from fixeoln_one import convertEndlines

    errmsg = 'Required first argument missing: "todos" or "tounix"'
    assert (len(sys.argv) >= 2 and sys.argv[1] in ['todos', 'tounix']), errmsg

    if len(sys.argv) > 2:                  # quote in unix shell 
        patts = sys.argv[2:]               # else tries to expand
    matches = findFiles(patts)

    count = 0
    for matchlist in matches:                 # a list of lists
        for fname in matchlist:               # one per pattern
            if listonly:
                print count+1, '=>', fname 
            else:  
                convertEndlines(sys.argv[1], fname)
            count = count + 1
    print 'Visited %d files' % count
Пример #4
0
 def visitfile(self, fullname):  # match on basename
     basename = os.path.basename(fullname)  # to make result same
     for patt in patts:  # else visits fewer
         if fnmatch.fnmatch(basename, patt):
             convertEndlines(self.context, fullname)
             self.fcount += 1  # could break here