summaryrefslogtreecommitdiff
path: root/subplot/data.py
diff options
context:
space:
mode:
Diffstat (limited to 'subplot/data.py')
-rw-r--r--subplot/data.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/subplot/data.py b/subplot/data.py
index 2a54037..f3faf2b 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -5,14 +5,17 @@ import random
import yaml
-def create_file_with_random_data(ctx, filename=None):
- N = 128
- data = "".join(chr(random.randint(0, 255)) for i in range(N)).encode("UTF-8")
+def create_file_with_given_data(ctx, filename=None, data=None):
+ logging.debug(f"creating file {filename} with {data!r}")
dirname = os.path.dirname(filename) or "."
- logging.debug(f"create_file_with_random_data: dirname={dirname}")
os.makedirs(dirname, exist_ok=True)
- with open(filename, "wb") as f:
- f.write(data)
+ open(filename, "wb").write(data.encode("UTF-8"))
+
+
+def create_file_with_random_data(ctx, filename=None):
+ N = 128
+ data = "".join(chr(random.randint(0, 255)) for i in range(N))
+ create_file_with_given_data(ctx, filename=filename, data=data)
def create_nonutf8_filename(ctx, dirname=None):