You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.1 KiB

  1. import os
  2. import shutil
  3. import fnmatch
  4. from jinja2 import Template
  5. def pattern_filter(file, patterns=None):
  6. if patterns is None:
  7. return True
  8. for p in patterns:
  9. if fnmatch.fnmatch(file, p):
  10. return True
  11. return False
  12. def find(paths, patterns=None):
  13. certificates = []
  14. for root, dirs, files in os.walk(paths):
  15. for file in files:
  16. if pattern_filter(file, patterns.split(',')):
  17. certificates.append({'path': os.path.normpath(os.path.join(root, file))})
  18. return certificates
  19. def copy(source, destination, basename=None, mode='0755'):
  20. if not os.path.exists(destination):
  21. os.makedirs(destination)
  22. shutil.copy2(src=source, dst=destination)
  23. file_path = os.path.join(destination, os.path.basename(source))
  24. os.chmod(file_path, int(mode, 8))
  25. if basename:
  26. os.rename(file_path, os.path.join(destination, basename))
  27. def template(source, context, destination):
  28. jinja_template = Template(open(source).read())
  29. with open(destination, 'w') as f:
  30. f.write(jinja_template.render(context))