Dec-27-2017, 08:32 PM
Here's an example that creates two json files, and can read it back for a test
This requires python 3.2 or later
it will create two json files in a sub-directory named data
EnigmaPaths.py
This requires python 3.2 or later
it will create two json files in a sub-directory named data
EnigmaPaths.py
from pathlib import Path class EnigmaPaths: def __init__(self): self.homepath = Path('.') self.datapath = self.homepath / 'data' self.imagepath = self.homepath / 'image' self.enigma_info = self.datapath / 'enigma_info.json' self.color_info = self.datapath / 'color_info.json' self.patchboard_image = self.imagepath / 'patchboard.ppm'InitializationData.py
import EnigmaPaths import json class InitializationData: def __init__(self): self.epath = EnigmaPaths.EnigmaPaths() self.epath.datapath.mkdir(exist_ok=True) self.init_data = { 'rotor_info': { 'rotor1_info': { 'name': 'rotor1', 'cipher': 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', 'notches': ['R'], }, 'rotor2_info': { 'name': 'rotor2', 'cipher': 'AJDKSIRUXBLHWTMCQGZNPYFVOE', 'notches': ['F'] }, 'rotor3_info': { 'name': 'rotor3', 'cipher': 'BDFHJLCPRTXVZNYEIWGAKMUSQO', 'notches': ['W'] }, 'rotor4_info': { 'name': 'rotor4', 'cipher': 'ESOVPZJAYQUIRHXLNFTGKDCMWB', 'notches': ['K'] }, 'rotor5_info': { 'name': 'rotor5', 'cipher': 'VZBRGITYUPSDNHLXAWMJQOFECK', 'notches': ['A'] }, # Rotor 6 - 8 available on Kriegsmarine M3 and M4 only 'rotor6_info': { 'name': 'rotor6', 'cipher': 'JPGVOUMFYQBENHZRDKASXLICTW', 'notches': ['A', 'N'] }, 'rotor7_info': { 'name': 'rotor7', 'cipher': 'NZJHGRCXMYSWBOUFAIVLPEKQDT', 'notches': ['A', 'N'] }, 'rotor8_info': { 'name': 'rotor8', 'cipher': 'FKQHTLXOCBJSPDZRAMEWNIUYGV', 'notches': ['A', 'N'] }, }, 'reflector_B': 'YRUHQSLDPXNGOKMIEBFZCWVJAT', 'reflector_C': 'FVPJIAOYEDRZXWGCTKUQSBNMHL', 'unencoded': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' } with self.epath.enigma_info.open('w') as f: json.dump(self.init_data, f) class Colors: ''' Colors from the the w3schools themes website: main: https://www.w3schools.com/w3css/w3css_colors.asp themes: https://www.w3schools.com/w3css/w3css_color_themes.asp and specifically portions of the w3-theme-black theme css for this theme can be found here: https://www.w3schools.com/lib/w3-theme-black.css ''' def __init__(self): self.epath = EnigmaPaths.EnigmaPaths() self.color_theme_black = { '.w3_theme_l5': { 'color': '#000', 'background-color': '#f0f0f0' }, '.w3-theme-l4': { 'color': '#000', 'background-color': '#cccccc' }, '.w3-theme-l3': { 'color': '#fff', 'background-color': '#999999' }, '.w3-theme-l2': { 'color': '#fff', 'background-color': '#666666' }, '.w3-theme-l1': { 'color': '#fff', 'background-color': '#333333' }, '.w3-theme-d1': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme-d2': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme-d3': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme-d4': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme-d5': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme-light': { 'color': '#000', 'background-color': '#f0f0f0' }, '.w3-theme-dark': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme-action': { 'color': '#fff', 'background-color': '#000000' }, '.w3-theme': { 'color': '#fff', 'background-color': '#000000' }, '.w3-text-theme': { 'color': '#000000' }, '.w3-border-theme': { 'border-color': '#000000' }, '.w3-hover-theme:hover': { 'color': '#fff', 'background-color': '#000000' }, '.w3-hover-text-theme': { 'color': '#000000' }, '.w3-hover-border-theme': { 'border-color': '#000000' } } with self.epath.color_info.open('w') as f: json.dump(self.color_theme_black, f) def test_read(self): with self.epath.color_info.open() as f: self.init_data = json.load(f) if __name__ == '__main__': InitializationData() Colors()