Learning by doing: Reading books and trying to understand the (code) examples
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.

23 lines
894 B

  1. from zipprocessor import ZipProcessorComp
  2. import sys
  3. import os
  4. class ZipReplace:
  5. def __init__(self, search_string, replace_string):
  6. self.search_string = search_string
  7. self.replace_string = replace_string
  8. def process(self, zipprocessor):
  9. """perform a search and replace on all files in the temporary directory"""
  10. for filename in os.listdir(zipprocessor.temp_directory):
  11. with open(zipprocessor._full_filename(filename)) as file:
  12. contents = file.read()
  13. contents = contents.replace(self.search_string,
  14. self.replace_string)
  15. with open(zipprocessor._full_filename(filename), "w") as file:
  16. file.write(contents)
  17. if __name__ == "__main__":
  18. zipreplace = ZipReplace(*sys.argv[2:4])
  19. ZipProcessorComp(sys.argv[1], zipreplace).process_zip()