Last active
December 30, 2020 18:52
-
-
Save ross-spencer/f9aff2ef857869eeb78ce12413112652 to your computer and use it in GitHub Desktop.
Creating Skeleton Files in Batches Suitable for Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Create Skeleton sample files for testing.""" | |
from __future__ import print_function | |
import os | |
import random | |
import sys | |
# Hex and extension belong to Spectrum .TZX data version 1. FMT/1000. | |
BIN="\x5A\x58\x54\x61\x70\x65\x21\x1A\x01" | |
EXT="tzx" | |
NUMBER=10 | |
SIZE=10 | |
OBJECTS="objects" | |
def bytes(n): | |
for i in range(n): | |
yield chr(random.randint(0, 255)) | |
def makeloc(): | |
try: | |
os.makedirs(OBJECTS) | |
except OSError: | |
pass | |
def main(): | |
makeloc() | |
no=NUMBER | |
size=SIZE | |
try: | |
no=int(sys.argv[1]) | |
except (IndexError, ValueError): | |
pass | |
try: | |
size=int(sys.argv[2]) | |
except (IndexError, ValueError): | |
pass | |
for i in range(no): | |
name = os.path.join(OBJECTS, "{:09d}-skeleton.{}".format(i, EXT)) | |
size_ = (1024 * 1024 * size) - len(BIN) | |
with open(name, "wb") as skeleton_file: | |
skeleton_file.write(BIN) | |
for byte in bytes(4): | |
skeleton_file.write(byte) | |
skeleton_file.write('0' * size_) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment