您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

45 行
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))