File: utilities.py

package info (click to toggle)
jsonpickle 4.0.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,864 kB
  • sloc: python: 6,788; javascript: 654; makefile: 125; sh: 68
file content (14 lines) | stat: -rw-r--r-- 529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import os
import sys


def ensure_no_files_overwritten(expected_contents):
    # ensure we don't overwrite the user's files, if they run it on their machine
    if os.path.exists("example.json"):
        with open("example.json", "r") as f:
            contents = f.read()
        if contents != expected_contents:
            # exit with a non-zero error code
            sys.exit(
                "I don't want to overwrite the example.json file in my current directory! Please delete example.txt and try again!"
            )