Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Finds files based on patterns (supporting wildcards *?[-])
  3. # Prints matching filenames or otherwise "NOT FOUND"
  4. # Exits with code 1 if at least one pattern doesn't match
  5.  
  6. from __future__ import print_function
  7. import glob
  8. import sys
  9. import os
  10.  
  11. pattern_list = ["LIP$DATE",
  12. "thefile.txt",
  13. "*$VAR1*",
  14. "*.py"]
  15.  
  16.  
  17. def replace_value(motif):
  18. motif = motif.replace("$DATE", "20190331")
  19. motif = motif.replace("$VAR1", "VALUE1")
  20. return motif
  21.  
  22.  
  23. def find_file(pattern):
  24. dirname = os.path.expanduser("~/data/read/")
  25. return glob.glob1(dirname, pattern)
  26.  
  27.  
  28. all_found = True
  29. for p in pattern_list:
  30. assigned_value = replace_value(p)
  31. matching_list = find_file(assigned_value)
  32. if len(matching_list) == 0:
  33. print("[%s]: NOT FOUND" % assigned_value, file=sys.stderr)
  34. all_found = False
  35. else:
  36. print("[%s]: %s" % (assigned_value, str(matching_list)))
  37.  
  38.  
  39. if all_found:
  40. sys.exit(0)
  41. else:
  42. sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement