1. import argparse
  2. import base64
  3. import os
  4. def encode_filepath(filepath):
  5. """Encodes a filepath using base64 for debugging purposes."""
  6. try:
  7. with open(filepath, 'rb') as f:
  8. data = f.read()
  9. encoded_data = base64.b64encode(data).decode('utf-8') # encode to string
  10. return encoded_data
  11. except FileNotFoundError:
  12. return f"Error: File not found: {filepath}"
  13. except Exception as e:
  14. return f"Error: {e}"
  15. def main():
  16. """CLI interface for encoding filepaths."""
  17. parser = argparse.ArgumentParser(description="Encode filepaths using base64 for debugging.")
  18. parser.add_argument("filepath", help="The filepath to encode.")
  19. args = parser.parse_args()
  20. encoded_string = encode_filepath(args.filepath)
  21. print(encoded_string)
  22. if __name__ == "__main__":
  23. main()

Add your comment