コード例 #1
0
 def aods_append(self):
     try:
         with open(self.args.inputfilename, encoding='utf8') as fd:
             inputdataJSON = fd.read()
     except (OSError, IOError) as e:
         logging.error('could not read inputfile, because: %s' %(repr(e)))
         sys.exit(1)
     try:
         appendList = json.loads(inputdataJSON)
     except Exception as e:
         raise JSONdecodeError
     if not isinstance(appendList, list):
         raise PMPInputRecNoDictError('JSON input file must contain a list of dict')
     if len(appendList) == 0:
         raise PMPInputRecNoDictError('JSON input file must contain a non-empty list of dict')
     if not isinstance(appendList[0], dict):
         raise PMPInputRecNoDictError('JSON input file: first object in list is not a dict')
     self.aods = self.aodsFileHandler.readFile() # does validation as well
     inputRecSeq = 0
     for inputDataRaw in appendList:
         inputRec = InputRecord(inputDataRaw)
         wrapperRec = WrapperRecord('elements', inputRec, self.args)
         inputRecSeq += 1
         policyDict = self.aods_read(use='internal')  # get latest version
         logging.debug("%d rectype=%s pk=%s" % (inputRecSeq, inputRec.rec.rectype, inputRec.rec.primarykey))
         inputRec.validate(policyDict)
         lastHash = self.aods['AODS'][self.lastSeq][0]
         logging.debug("%d lastHash: " % inputRecSeq + lastHash)
         wrapperRec_final = wrapperRec.getRec(self.lastSeq + 1, lastHash)
         self.aods['AODS'].append(wrapperRec_final)
     self.aodsFileHandler.save(self.aods, self.args.noxmlsign)
コード例 #2
0
 def aods_create(self):
     inputDataRaw = {"record": ["header", "",
                                "columns: hash, seq, delete, [rectype, pk, a1, a2, ..], "
                                "datetimestamp, registrant, submitter]" ],
                     "delete": False}
     inputRec = InputRecord(inputDataRaw)
     wrapperRec = WrapperRecord('elements', inputRec, self.args)
     seedVal_str = str(datetime.now())
     seedVal_bytes = base64.b64encode(hashlib.sha256(seedVal_str.encode('ascii')).digest())
     if self.args.debug: seedVal_bytes = 'fixedValueForDebugOnly'.encode('ascii')
     logging.debug("0 seedVal: " + seedVal_bytes.decode('ascii'))
     self.aodsFileHandler.create({"AODS": [wrapperRec.getRec(0, seedVal_bytes.decode('ascii'))]}, self.args.noxmlsign)