Example #1
0
    def __init__(self, fnFrag, grandParFrag, data=None, listonly=0):

        FileVisitor.__init__(self, data, listonly)

        self.nFiles = {}
        self.fnFrag = fnFrag
        self.grandParFrag = grandParFrag
        print 'Looking for filenames containing ', self.fnFrag
        print '... with grandparent directory containing', self.grandParFrag
Example #2
0
 def visitfile(self, fullname):
     FileVisitor.visitfile(self, fullname)
     try:
         lines = open(fullname, 'r').readlines()      # fails for binary files
     except UnicodeDecodeError:
         if self.trace > 0: print('Skipped non-text file:', fullname)
     else:
         if (len(lines) > 0            and
             lines[0].startswith('#!') and            # or lines[0][0:2] == '#!'
             'python' in lines[0]                     # or lines[0].find() != -1
             ):
             self.clist.append(fullname)
             if not self.listOnly:
                 lines[0] = self.changeTo + '\n'
                 open(fullname, 'w').writelines(lines)
Example #3
0
 def visitfile(self, fullname):
     FileVisitor.visitfile(self, fullname)
     try:
         lines = open(fullname, 'r').readlines()  # fails for binary files
     except UnicodeDecodeError:
         if self.trace > 0: print('Skipped non-text file:', fullname)
     else:
         if (len(lines) > 0 and lines[0].startswith('#!')
                 and  # or lines[0][0:2] == '#!'
                 'python' in lines[0]  # or lines[0].find() != -1
             ):
             self.clist.append(fullname)
             if not self.listOnly:
                 lines[0] = self.changeTo + '\n'
                 open(fullname, 'w').writelines(lines)
 def visitfile(self, fullname):
     FileVisitor.visitfile(self, fullname)
     try:
         lines = open(fullname, "r").readlines()  # fails for binary files
     except UnicodeDecodeError:
         if self.trace > 0:
             print("Skipped non-text file:", fullname)
     else:
         if (
             len(lines) > 0
             and lines[0].startswith("#!")
             and "python" in lines[0]  # or lines[0][0:2] == '#!'  # or lines[0].find() != -1
         ):
             self.clist.append(fullname)
             if not self.listOnly:
                 lines[0] = self.changeTo + "\n"
                 open(fullname, "w").writelines(lines)
Example #5
0
 def visitfile(self, filepath):
     FileVisitor.visitfile(self, filepath)
     if filepath.endswith('.pyc'):
         print(filepath)
         #os.remove(filepath)
         self.context += 1
Example #6
0
 def __init__(self, trace=0):
     FileVisitor.__init__(self, context=0, trace=trace)
 def visitfile(self, filepath):
     FileVisitor.visitfile(self, filepath)
     for ext in self.srcExts:
         if filepath.endswith(ext):
             self.visitsource(filepath, ext)
             break
 def __init__(self, trace=0):
     FileVisitor.__init__(self, trace=trace)
     self.srcLines = self.srcFiles = 0
     self.extSums = {ext: {'files': 0, 'lines': 0} for ext in self.srcExts}
Example #9
0
 def __init__(self, trace=1):
     FileVisitor.__init__(self, trace=trace)
     self.srclines = self.srcFiles = 0
     self.extSums = {ext: dict(files=0, lines=0) for ext in self.srcExts}
Example #10
0
 def __init__(self, fromDir, toDir, trace=True):
     self.fromDirLen = len(fromDir) + 1            #walk得到的路径除最顶层目录外的路径索引,用来slice字符串
     self.toDir      = toDir
     FileVisitor.__init__(self, trace=trace)
Example #11
0
 def visitfile(self, filepath):
     FileVisitor.visitfile(self, filepath)
     if filepath.endswith('.pyc'):
         print(filepath) 
         #os.remove(filepath)
         self.context += 1
 def visitfile(self, filepath):
     FileVisitor.visitfile(self, filepath)
     if filepath.endswith('.py'):
         print(filepath) 
         self.context.append((os.path.getsize(filepath), filepath))
 def __init__(self, trace=1):
     FileVisitor.__init__(self, trace=trace)
     self.srcLines = self.srcFiles = 0
     self.extSums = {ext: dict(files=0, lines=0) for ext in self.srcExts}
Example #14
0
	def __init__(self, fromDir, toDir, trace=True):
		self.fromDirLen = len(fromDir) + 1
		self.toDir      = toDir
		FileVisitor.__init__(self, trace=trace)
Example #15
0
 def __init__(self, changeTo=changeToDefault, listonly=False, trace=0):
     FileVisitor.__init__(self, trace=trace)
     self.changeTo = changeTo
     self.listOnly = listonly
     self.clist = []
 def __init__(self, listonly=0):
     FileVisitor.__init__(self, listonly=listonly)
     self.ccount = 0
Example #17
0
 def __init__(self, changeTo=changeToDefault, listonly=False, trace=0):
     FileVisitor.__init__(self, trace=trace)
     self.changeTo = changeTo
     self.listOnly = listonly
     self.clist    = []
 def visitfile(self, filename):
     FileVisitor.visitfile(self, filename)
     self.rename(filename)
 def visitdir(self, dirname):
     FileVisitor.visitdir(self, dirname)
     self.rename(dirname)
 def visitfile(self, filepath):
     FileVisitor.visitfile(self, filepath)
     for ext in self.srcExts:
         if filepath.endswith(ext):
             self.visitsource(filepath, ext)
             break
Example #21
0
 def visitfile(self, filepath):
     FileVisitor.visitfile(self, filepath)
     if filepath.endswith('.py'):
         print(filepath)
         self.context.append((os.path.getsize(filepath), filepath))
Example #22
0
 def __init__(self, fromDir, toDir, trace=True):
     self.fromDirLen = len(fromDir) + 1
     self.toDir = toDir
     FileVisitor.__init__(self, trace=trace)
 def __init__(self, trace=0):
     FileVisitor.__init__(self, context=[], trace=trace)