def ingest(record_type, **kwargs): """ Run the ingestion flow for the given :record_type:. """ datasource = acquire_data(record_type, **kwargs) validating = not kwargs.get("no_validate") if validating: ref = kwargs.get("ref") datasource = validate_data(datasource, record_type, ref) # clean up missing data for k in [k for k in datasource.keys()]: if not datasource[k] or len(datasource[k]) < 1: del datasource[k] else: print("Skipping data validation") # output to files if needed output = kwargs.get("output") if output and os.path.exists(output): print(f"Writing data files to {output}") start_time, end_time = kwargs.get("start_time"), kwargs.get("end_time") output_data(output, datasource, record_type, start_time, end_time) loading = not kwargs.get("no_load") if loading and len(datasource) > 0: load_data(datasource, record_type, **kwargs) print(f"{record_type} complete")
def SUB(register): if not validate.validate_reg(register): print "Invalid Register: %s" % register exit(1) a = int(registers.reg["A"], 16) if register == "M": b = extras.getPair('H', 'L') if extras.chkMemory(b): b = int(registers.reg[register], 16) else: print " Invalid Memory:", b exit(1) else: b = int(registers.reg[register], 16) t = a - b a = int(extras.getLowerNibble(format(a, '0x')), 2) b = int(extras.getLowerNibble(format(b, '0x')), 2) if not validate.validate_data(t): print "\n////-----UnderFlow Detected----////\n" t = format(t, "02x") t = set_flags.setCarry(t) set_flags.setFlags(a, b, t, isAbnormalFlow=True) tmp = {"A": t[1:]} else: t = format(t, "02x") set_flags.setFlags(a, b, t) tmp = {"A": t} set_flags.setFlags(a, b, t) registers.reg.update(tmp)
def SUI(data): a = int(registers.reg['A'], 16) b = int(data, 16) res = a - b res = format(res, '02x') if not validate.validate_data(int(res, 16)): res = set_flags.setCarry(res) set_flags.setFlags(a, b, res, isAbnormalFlow=True) else: set_flags.setFlags(a, b, res) registers.reg['A'] = res
def ADI(data): a = int(registers.reg['A'], 16) b = int(data, 16) res = format((a + b), '02x') a = int(extras.getLowerNibble(format(a, '0x')), 2) b = int(extras.getLowerNibble(format(b, '0x')), 2) if validate.validate_data(int(res, 16)): registers.reg['A'] = res set_flags.setFlags(a, b, res) else: print "\n Overflow Detected ADI", data print "Register Data[A]:", registers.reg['A'] exit(1)
def DAD(reg1): if validate.validate_reg(reg1): c = 0 try: reg2 = registers.reg_pair[reg1] except: print "invalid register pair", reg1 exit(1) a = int(registers.reg[reg2], 16) res = int(registers.reg['L'], 16) + a if res > 255: c = 1 res -= 256 registers.reg['L'] = format(res, '02x') a = int(registers.reg[reg1], 16) res = int(registers.reg['H'], 16) + a + c res = format(res, '02x') if not validate.validate_data(int(res, 16)): res = set_flags.setCarry(res) registers.reg['H'] = res else: print 'invalid register pair:', reg1 exit(1)
def SET(addr, data): if validate.validate_data(int(data, 16)): registers.memory[addr] = data else: print "Data Invalid.\nPlease Enter Valid Data at Memory Location: %s" % addr exit(1)
def LDA(addr): data = registers.memory[addr] if validate.validate_data(int(data, 16)): registers.reg['A'] = data else: print "Data Invalid. Please Retry"
def test_data(self): for filename in self.json_files: self.assertEqual("Valid", validate_data(filename), filename)