def _netListCreator(netlist_data):
    # Create fresh set of gate_codes for making NetList
    createGateCodes()

    global Gate_Codes, gate_codes_file_path

    with open(gate_codes_file_path) as gc:
        Gate_Codes = json.load(gc)
        print("Gate_Codes Loaded Successfully")

    net_list_file_path = filePath().netlist_txt_path()

    with open(net_list_file_path, 'w') as nl:
        for data in netlist_data:
            if data[0] == 'not':
                netlist = _netListHelper(data[0],
                                         inputs=1,
                                         quantity=int(data[1]))
            else:
                netlist = _netListHelper(data[0], int(data[1]), int(data[2]))
            nl.write(netlist)
            nl.write('\n')

    # Finally modify the gate counts used in netlist generation
    # for future changes
    with open(gate_codes_file_path, 'w') as gc:
        json.dump(Gate_Codes, gc)
def writeParsedComponents():
    '''Write the succesfully parsed components to `DataFiles/parsed_components.json`'''
    filepath = filePath().parsed_comp_data_path()

    global parsed_components_list

    with open(filepath, 'w') as wpc:
        json.dump(parsed_components_list, wpc)
コード例 #3
0
def create_in_out_conn_sections():
    ''' Create `#input`, `#output` & `#connections` sections in the `netlist.txt`'''
    netlist_path = filePath().netlist_txt_path()
    with open(netlist_path, 'a') as fp:
        fp.write('''
        \n#inputs\n\n
        \n#outputs\n\n
        \n#connections\n\n''')
def createNetlist():
    '''This is this script's main function, to be called to create a `netlist.txt` file'''
    parsed_components_file_path = filePath().parsed_comp_data_path()
    with open(parsed_components_file_path) as pc:
        data = json.load(pc)
        print(data, type(data))
        _netListCreator(data)

    # parse all nets data to `/DataFiles/all_nets.json`
    parse_all_nets()
コード例 #5
0
def components_mssg_find():
    global sample_data_mssg
    comp_mssg_path = filePath().default_components_mssg_path()

    try:
        with open(comp_mssg_path, 'r') as cm:
            sample_data_mssg = cm.read()
    except FileNotFoundError:
        print(
            "File 'DataFiles/comp_mssg.txt' is missing or corrupt. Please reinstall the program."
        )
        exit()
def logicGatesList():
    lg_path = filePath().logic_gates_info_path()

    logic_gates = None
    try:
        with open(lg_path) as lg:
            logic_gates = lg.read().split()  # List of logic gates
    except FileNotFoundError:
        print(
            "'DataFiles/DigitalComponents/logic_gates.txt' is corrupt or does not exists. Please reinstall the program."
        )
        exit()

    return logic_gates
コード例 #7
0
from InternalWorkingScripts.FilesPath.file_paths import filePath

import json

netlist_path = filePath().netlist_txt_path()
all_inputs_path = filePath().all_inputs_path()


def create_json(data):
    with open(all_inputs_path, 'w') as fp:
        json.dump(data, fp, indent=4)


def parse_input_nets():

    global all_inputs_path
    all_inputs = {}

    with open(netlist_path) as fp:
        for line in fp:
            if line.startswith(
                    '#'):  # This is when we reach the `#inputs` section
                break
            if line == '\n':
                continue
            if line.startswith('in'):
                nets_with_in = line.split()
                #removing "in"
                nets = nets_with_in[1:]
                # component_name + o = output_net_name
                nets_out = nets[0] + "o"
コード例 #8
0
import os, time
from shutil import Error
from pathlib import Path
from Checkers.pathCheck import checkPath
from concurrent.futures import ThreadPoolExecutor as pool
from InternalWorkingScripts.FilesPath.file_paths import filePath
from InternalWorkingScripts.PopUpMessage.popUp import popUp

# Components.txt file path for creation, for user interactions
comp_path = filePath().components_txt_path()

sample_data_mssg = ""  # Will save sample_data text


def components_mssg_find():
    global sample_data_mssg
    comp_mssg_path = filePath().default_components_mssg_path()

    try:
        with open(comp_mssg_path, 'r') as cm:
            sample_data_mssg = cm.read()
    except FileNotFoundError:
        print(
            "File 'DataFiles/comp_mssg.txt' is missing or corrupt. Please reinstall the program."
        )
        exit()


def fileMaker():
    global sample_data_mssg
    # Create File Path, if it doesn't exists
コード例 #9
0
from InternalWorkingScripts.FilesPath.file_paths import filePath

import json
import re

from itertools import zip_longest

netlist_file_path = filePath().netlist_txt_path()
all_components_path = filePath().all_components_path()


def create_json(data):
    with open(all_components_path, 'w') as fp:
        json.dump(data, fp, indent=4)


def find_op_connections_nets(comp_name, nets, flag=0):
    output_nets = re.compile(rf'{comp_name}o\d*')
    if flag == 0:
        return output_nets.findall(nets)
    else:
        regx = re.compile(rf'^{comp_name}o?\d*')
        connections = []
        for n in nets:
            if regx.search(n) != None:
                continue
            connections.append(n)
        return connections


def parse_component_nets():
コード例 #10
0
# Make this script so that it will run, only after the first chages are observed in `netlist.txt`

from InternalWorkingScripts.FilesPath.file_paths import filePath
from Checkers import ifModified
from InternalWorkingScripts import simulate

from time import sleep
from pathlib import Path

filepath = filePath().netlist_txt_path()


def detect_change(filepath):
    change = ifModified(filepath)
    return change


def MonitorNetlistChanges():
    '''Continuously Monitor `netlist.txt` file for changes and take appropriate actions'''

    global filepath

    while True:
        print("Detecting")
        changed = detect_change(filepath)
        if changed:
            print("Netlist Change Detected")
            simulate()
        else:
            sleep(1)
コード例 #11
0
from InternalWorkingScripts.FilesPath.file_paths import filePath
from ._sections import create_in_out_conn_sections
import json

netlist_path = filePath().netlist_txt_path()
all_nets_path = filePath().all_nets_path()


def parse_all_nets():
    all_nets = {}
    with open(netlist_path) as fp:
        for line in fp:
            nets = line.split()
            # removing the component name
            nets = nets[1:]
            for n in nets:
                all_nets[n] = "ND"  # Using `ND` for not defined

    with open(all_nets_path, 'w') as fp:
        json.dump(all_nets, fp, indent=4)

    create_in_out_conn_sections()
コード例 #12
0
from InternalWorkingScripts.FilesPath.file_paths import filePath
from Checkers.pathCheck import checkPath

import json


Gate_Codes = {
    'and' : ['a',1],
    'or' : ['o',1],
    'not' : ['n',1],
    'nand': ['na',1],
    'nor' : ['no',1],
    'xor' : ['xo',1],
    'xnor': ['xn',1]
}

gate_codes_file_path = filePath().gate_codes_path()

def createGateCodes():
    global gate_codes_file_path, GateCodes

    try:
        with open(gate_codes_file_path,'w') as gc:
            json.dump(Gate_Codes,gc)

    except FileExistsError as e:
        print(f"Remove `Gate_Codes.json` file from: {str(gate_codes_file_path)}")
        print("Run the main_script again")
        exit()