mirror of
				https://github.com/python/cpython.git
				synced 2025-11-01 06:01:29 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
	
		
			564 B
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
	
		
			564 B
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
| #! /usr/local/python
 | |
| 
 | |
| # findlinksto
 | |
| #
 | |
| # find symbolic links to a given path
 | |
| 
 | |
| import posix, path, sys
 | |
| 
 | |
| def visit(pattern, dirname, names):
 | |
| 	if path.islink(dirname):
 | |
| 		names[:] = []
 | |
| 		return
 | |
| 	if path.ismount(dirname):
 | |
| 		print 'descend into', dirname
 | |
| 	n = len(pattern)
 | |
| 	for name in names:
 | |
| 		name = path.cat(dirname, name)
 | |
| 		try:
 | |
| 			linkto = posix.readlink(name)
 | |
| 			if linkto[:n] = pattern:
 | |
| 				print name, '->', linkto
 | |
| 		except posix.error:
 | |
| 			pass
 | |
| 
 | |
| def main(pattern, args):
 | |
| 	for dirname in args:
 | |
| 		path.walk(dirname, visit, pattern)
 | |
| 
 | |
| main(sys.argv[1], sys.argv[2:])
 | 
