Esempio n. 1
0
    def run(self):
        if not self.ta_info["topartner"] or not self.ta_info["frompartner"]:
            raise botslib.OutMessageError(
                _(u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".'), ta_info=self.ta_info
            )
        self._openoutenvelope(self.ta_info["editype"], self.ta_info["envelope"])
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript, self.scriptname, "ta_infocontent", ta_info=self.ta_info)
        # prepare data for envelope
        if botsglobal.ini.getboolean("settings", "interchangecontrolperpartner", False):
            self.ta_info["reference"] = str(botslib.unique("stxcounter_" + self.ta_info["topartner"]))
        else:
            self.ta_info["reference"] = str(botslib.unique("stxcounter_" + self.ta_info["frompartner"]))
        # build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put(
            {
                "BOTSID": "STX",
                "STDS1": self.ta_info["STX.STDS1"],
                "STDS2": self.ta_info["STX.STDS2"],
                "FROM.01": self.ta_info["frompartner"],
                "UNTO.01": self.ta_info["topartner"],
                "TRDT.01": time.strftime("%y%m%d"),
                "TRDT.02": time.strftime("%H%M%S"),
                "SNRF": self.ta_info["reference"],
            }
        )
        if self.ta_info["STX.FROM.02"]:
            self.out.put({"BOTSID": "STX", "FROM.02": self.ta_info["STX.FROM.02"]})
        if self.ta_info["STX.UNTO.02"]:
            self.out.put({"BOTSID": "STX", "UNTO.02": self.ta_info["STX.UNTO.02"]})
        if self.ta_info["STX.APRF"]:
            self.out.put({"BOTSID": "STX", "APRF": self.ta_info["STX.APRF"]})
        if self.ta_info["STX.PRCD"]:
            self.out.put({"BOTSID": "STX", "PRCD": self.ta_info["STX.PRCD"]})
        self.out.put(
            {"BOTSID": "STX"}, {"BOTSID": "END", "NMST": self.ta_info["nrmessages"]}
        )  # dummy segment; is not used
        # user exit
        botslib.tryrunscript(self.userscript, self.scriptname, "envelopecontent", ta_info=self.ta_info, out=self.out)
        # convert the tree into segments; here only the STX is written (first segment)
        self.out.checkmessage(self.out.root, self.out.defmessage)
        self.out.tree2records(self.out.root)

        # start doing the actual writing:
        tofile = botslib.opendata(self.ta_info["filename"], "wb", self.ta_info["charset"])
        tofile.write(self.out.record2string(self.out.records[0]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.records[-1]))
        tofile.close()
Esempio n. 2
0
    def run(self):
        ''' reinjects files with failed communication.
        '''
        #bots keeps track of last time automaticretrycommunication was done; reason: performance
        idta_lastretry = botslib.unique('bots__automaticretrycommunication',updatewith=self.minta4query)
        if idta_lastretry == 1:
            #this is the first time automaticretrycommunication is run.
            #do not do anything this run, in order to avoid sending older files. 
            return False    #no run
        for row in botslib.query('''SELECT MIN(idta) AS min_idta
                                    FROM filereport
                                    WHERE idta > %(idta_lastretry)s
                                    AND statust = %(statust)s ''',
                                    {'statust':ERROR,'idta_lastretry':idta_lastretry}):
            startidta = row['min_idta']
        if not startidta:
            return False    #no run
        do_retransmit = False
        for row in botslib.query('''SELECT idta,parent,numberofresends
                                    FROM ta
                                    WHERE idta > %(startidta)s
                                    AND status = %(status)s
                                    AND statust = %(statust)s ''',
                                    {'statust':ERROR,'status':EXTERNOUT,'startidta':startidta}):
            do_retransmit = True
            ta_outgoing = botslib.OldTransaction(row['idta'])
            ta_outgoing.update(retransmit=False,statust=RESEND)     #set retransmit back to False
            ta_resend = botslib.OldTransaction(row['parent'])  #parent ta with status RAWOUT; this is where the outgoing file is kept
            ta_externin = ta_resend.copyta(status=EXTERNIN,statust=DONE) #inject; status is DONE so this ta is not used further
            ta_externin.copyta(status=FILEOUT,statust=OK,numberofresends=row['numberofresends'])  #reinjected file is ready as new input

        if do_retransmit:
            return super(automaticretrycommunication, self).run()
        else:
            return False    #no run
Esempio n. 3
0
def filename_formatter(filename_mask,ta_info):
    class infilestr(str):
        ''' class for the infile-string that handles the specific format-options'''
        def __format__(self, format_spec):
            if not format_spec:
                return unicode(self)
            name,ext = os.path.splitext(unicode(self))
            if format_spec == 'ext':
                if ext.startswith('.'):
                    ext = ext[1:]
                return ext 
            if format_spec == 'name':
                return name 
            raise botslib.CommunicationOutError(_(u'Error in format of "{filename}": unknown format: "%(format)s".'),
                                                {'format':format_spec})
    unique = unicode(botslib.unique('bots_outgoing_file_name'))   #create unique part for filename
    tofilename = filename_mask.replace('*',unique)           #filename_mask is filename in channel where '*' is replaced by idta
    if '{' in tofilename :
        if botsglobal.ini.getboolean('acceptance','runacceptancetest',False):
            datetime_object = datetime.datetime.strptime("2013-01-23 01:23:45", "%Y-%m-%d %H:%M:%S")
        else:
            datetime_object = datetime.datetime.now()
        infilename = infilestr(os.path.basename(ta_info['infilename'][0])) #there is always an infile!
        tofilename = tofilename.format(infile=infilename,datetime=datetime_object,**ta_info)
    return tofilename
Esempio n. 4
0
def cleanup(do_cleanup_parameter,userscript,scriptname):
    ''' public function, does all cleanup of the database and file system.
        most cleanup functions are by default done only once a day.
    '''
    if botsglobal.ini.getboolean('acceptance','runacceptancetest',False): # no cleanup during acceptance testing
        return
    whencleanup = botsglobal.ini.get('settings','whencleanup','daily')
    if do_cleanup_parameter:  #if explicit indicated via commandline parameter 
        do_full_cleanup = True
    elif whencleanup in ['always','daily']:
        #perform full cleanup only first run of the day.
        cur_day = int(time.strftime('%Y%m%d'))    #get current date, convert to int
        if cur_day != botslib.unique('bots_cleanup_day',updatewith=cur_day):
            do_full_cleanup = True
        else:
            do_full_cleanup = False
    else:
        do_full_cleanup = False
    try:
        if do_full_cleanup:
            botsglobal.logger.info(u'Cleanup files')
            _cleandatafile()
            _cleanarchive()
            botsglobal.logger.info(u'Cleanup database')
            _cleanupsession()
            _cleanpersist()
            _cleantransactions()
            botsglobal.logger.info(u'Vacuum database')
            _vacuum()
            # postcleanup user exit in botsengine script
            botslib.tryrunscript(userscript,scriptname,'postcleanup',whencleanup=whencleanup)
            botsglobal.logger.info(u'Done full cleanup.')
        _cleanrunsnothingreceived()          #do this every run, but not logged
    except:
        botsglobal.logger.exception(u'Cleanup error.')
Esempio n. 5
0
def filename_formatter(filename_mask, ta_info):
    class infilestr(str):
        ''' class for the infile-string that handles the specific format-options'''
        def __format__(self, format_spec):
            if not format_spec:
                return unicode(self)
            name, ext = os.path.splitext(unicode(self))
            if format_spec == 'ext':
                if ext.startswith('.'):
                    ext = ext[1:]
                return ext
            if format_spec == 'name':
                return name
            raise botslib.CommunicationOutError(
                _(u'Error in format of "{filename}": unknown format: "%(format)s".'
                  ), {'format': format_spec})

    unique = unicode(botslib.unique(
        'bots_outgoing_file_name'))  #create unique part for filename
    tofilename = filename_mask.replace(
        '*', unique
    )  #filename_mask is filename in channel where '*' is replaced by idta
    if '{' in tofilename:
        if botsglobal.ini.getboolean('acceptance', 'runacceptancetest', False):
            datetime_object = datetime.datetime.strptime(
                "2013-01-23 01:23:45", "%Y-%m-%d %H:%M:%S")
        else:
            datetime_object = datetime.datetime.now()
        infilename = infilestr(os.path.basename(
            ta_info['infilename'][0]))  #there is always an infile!
        tofilename = tofilename.format(infile=infilename,
                                       datetime=datetime_object,
                                       **ta_info)
    return tofilename
Esempio n. 6
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'),
                                            {'ta_info':self.ta_info})
        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)
        #prepare data for envelope
        if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
            self.ta_info['reference'] = unicode(botslib.unique('stxcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(botslib.unique('stxcounter_' + self.ta_info['frompartner']))
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({'BOTSID':'STX',
                        'STDS1':self.ta_info['STX.STDS1'],
                        'STDS2':self.ta_info['STX.STDS2'],
                        'FROM.01':self.ta_info['frompartner'],
                        'UNTO.01':self.ta_info['topartner'],
                        'TRDT.01':botslib.strftime('%y%m%d'),
                        'TRDT.02':botslib.strftime('%H%M%S'),
                        'SNRF':self.ta_info['reference']})
        if self.ta_info['STX.FROM.02']:
            self.out.put({'BOTSID':'STX','FROM.02':self.ta_info['STX.FROM.02']})
        if self.ta_info['STX.UNTO.02']:
            self.out.put({'BOTSID':'STX','UNTO.02':self.ta_info['STX.UNTO.02']})
        if self.ta_info['STX.APRF']:
            self.out.put({'BOTSID':'STX','APRF':self.ta_info['STX.APRF']})
        if self.ta_info['STX.PRCD']:
            self.out.put({'BOTSID':'STX','PRCD':self.ta_info['STX.PRCD']})
        self.out.put({'BOTSID':'STX'},{'BOTSID':'END','NMST':self.ta_info['nrmessages']})  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
        #convert the tree into segments; here only the STX is written (first segment)
        self.out.checkmessage(self.out.root,self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)

        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()
Esempio n. 7
0
def unique(domein):
    ''' generate unique number within range domein.
        uses db to keep track of last generated number.
        if domein not used before, initialized with 1.
    '''
    return str(botslib.unique(domein))
Esempio n. 8
0
 def run(self):
     if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
         raise botslib.OutMessageError(
             _(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'
               ), {'ta_info': self.ta_info})
     self._openoutenvelope()
     self.ta_info.update(self.out.ta_info)
     botslib.tryrunscript(self.userscript,
                          self.scriptname,
                          'ta_infocontent',
                          ta_info=self.ta_info)
     #prepare data for envelope
     isa09date = botslib.strftime('%y%m%d')
     #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     #mapping overrules.
     if self.ta_info['testindicator'] and self.ta_info[
             'testindicator'] != '0':  #'0' is default value (in db)
         testindicator = self.ta_info['testindicator']
     else:
         testindicator = self.ta_info['ISA15']
     #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean('settings',
                                  'interchangecontrolperpartner', False):
         self.ta_info['reference'] = unicode(
             botslib.unique('isacounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = unicode(
             botslib.unique('isacounter_' + self.ta_info['frompartner']))
     #ISA06 and GS02 can be different; eg ISA06 is a service provider.
     #ISA06 and GS02 can be in the syntax....
     isa06sender = self.ta_info.get('ISA06', self.ta_info['frompartner'])
     isa06sender = isa06sender.ljust(15)  #add spaces; is fixed length
     gs02sender = self.ta_info.get('GS02', self.ta_info['frompartner'])
     #also for ISA08 and GS03
     isa08receiver = self.ta_info.get('ISA08', self.ta_info['topartner'])
     isa08receiver = isa08receiver.ljust(15)  #add spaces; is fixed length
     gs03receiver = self.ta_info.get('GS03', self.ta_info['topartner'])
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put(
         {
             'BOTSID': 'ISA',
             'ISA01': self.ta_info['ISA01'],
             'ISA02': self.ta_info['ISA02'],
             'ISA03': self.ta_info['ISA03'],
             'ISA04': self.ta_info['ISA04'],
             'ISA05': self.ta_info['ISA05'],
             'ISA06': isa06sender,
             'ISA07': self.ta_info['ISA07'],
             'ISA08': isa08receiver,
             'ISA09': isa09date,
             'ISA10': botslib.strftime('%H%M'),
             'ISA11': self.ta_info[
                 'ISA11'],  #if ISA version > 00403, replaced by reprtion separator
             'ISA12': self.ta_info['version'],
             'ISA13': self.ta_info['reference'],
             'ISA14': self.ta_info['ISA14'],
             'ISA15': testindicator
         },
         strip=False
     )  #MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length
     self.out.put({'BOTSID': 'ISA'}, {
         'BOTSID': 'IEA',
         'IEA01': '1',
         'IEA02': self.ta_info['reference']
     })
     gs08messagetype = self.ta_info['messagetype'][3:]
     if gs08messagetype[:6] < '004010':
         gs04date = botslib.strftime('%y%m%d')
     else:
         gs04date = botslib.strftime('%Y%m%d')
     self.out.put({'BOTSID': 'ISA'}, {
         'BOTSID': 'GS',
         'GS01': self.ta_info['functionalgroup'],
         'GS02': gs02sender,
         'GS03': gs03receiver,
         'GS04': gs04date,
         'GS05': botslib.strftime('%H%M'),
         'GS06': self.ta_info['reference'],
         'GS07': self.ta_info['GS07'],
         'GS08': gs08messagetype
     })
     self.out.put({'BOTSID': 'ISA'}, {'BOTSID': 'GS'}, {
         'BOTSID': 'GE',
         'GE01': self.ta_info['nrmessages'],
         'GE02': self.ta_info['reference']
     })  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,
                          self.scriptname,
                          'envelopecontent',
                          ta_info=self.ta_info,
                          out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.checkmessage(self.out.root, self.out.defmessage)
     self.out.checkforerrorlist()
     self.out.tree2records(self.out.root)
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                               self.ta_info['charset'])
     isa_string = self.out.record2string(self.out.lex_records[0:1])
     #ISA has the used separators at certain positions. Normally bots would give errors for this (can not use sep as data) or compress these aways. So this is hardcoded.
     if self.ta_info['version'] < '00403':
         isa_string = isa_string[:103] + self.ta_info[
             'field_sep'] + self.ta_info['sfield_sep'] + isa_string[103:]
     else:
         isa_string = isa_string[:82] + self.ta_info[
             'reserve'] + isa_string[83:103] + self.ta_info[
                 'field_sep'] + self.ta_info['sfield_sep'] + isa_string[103:]
     tofile.write(isa_string)  #write ISA
     tofile.write(self.out.record2string(
         self.out.lex_records[1:2]))  #write GS
     self.writefilelist(tofile)
     tofile.write(self.out.record2string(
         self.out.lex_records[2:]))  #write GE and IEA
     tofile.close()
Esempio n. 9
0
    def run(self):
        self._openoutenvelope(self.ta_info['editype'],
                              self.ta_info['envelope'])
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'ta_infocontent',
                             ta_info=self.ta_info)

        #version dependent enveloping
        writeUNA = False
        if self.ta_info['version'] < '4':
            date = time.strftime('%y%m%d')
            reserve = ' '
            if self.ta_info['charset'] != 'UNOA':
                writeUNA = True
        else:
            date = time.strftime('%Y%m%d')
            reserve = self.ta_info['reserve']
            if self.ta_info['charset'] not in ['UNOA', 'UNOB']:
                writeUNA = True

        #UNB counter is per sender or receiver
        if botsglobal.ini.getboolean('settings',
                                     'interchangecontrolperpartner', False):
            self.ta_info['reference'] = str(
                botslib.unique('unbcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = str(
                botslib.unique('unbcounter_' + self.ta_info['frompartner']))

        #testindicator is more complex:
        if self.ta_info['testindicator'] and self.ta_info[
                'testindicator'] != '0':  #first check value from ta; do not use default
            testindicator = '1'
        elif self.ta_info['UNB.0035'] != '0':  #than check values from grammar
            testindicator = '1'
        else:
            testindicator = ''
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({
            'BOTSID': 'UNB',
            'S001.0001': self.ta_info['charset'],
            'S001.0002': self.ta_info['version'],
            'S002.0004': self.ta_info['frompartner'],
            'S003.0010': self.ta_info['topartner'],
            'S004.0017': date,
            'S004.0019': time.strftime('%H%M'),
            '0020': self.ta_info['reference']
        })
        #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
        if self.ta_info['UNB.S002.0007']:
            self.out.put({
                'BOTSID': 'UNB',
                'S002.0007': self.ta_info['UNB.S002.0007']
            })
        if self.ta_info['UNB.S003.0007']:
            self.out.put({
                'BOTSID': 'UNB',
                'S003.0007': self.ta_info['UNB.S003.0007']
            })
        if self.ta_info['UNB.0026']:
            self.out.put({'BOTSID': 'UNB', '0026': self.ta_info['UNB.0026']})
        if testindicator:
            self.out.put({'BOTSID': 'UNB', '0035': testindicator})
        self.out.put({'BOTSID': 'UNB'}, {
            'BOTSID': 'UNZ',
            '0036': self.ta_info['nrmessages'],
            '0020': self.ta_info['reference']
        })  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'envelopecontent',
                             ta_info=self.ta_info,
                             out=self.out)
        #convert the tree into segments; here only the UNB is written (first segment)
        self.out.normalisetree(self.out.root)
        self.out.tree2records(self.out.root)

        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                                  self.ta_info['charset'])
        if writeUNA or self.ta_info['forceUNA']:
            tofile.write('UNA' + self.ta_info['sfield_sep'] +
                         self.ta_info['field_sep'] + self.ta_info['decimaal'] +
                         self.ta_info['escape'] + reserve +
                         self.ta_info['record_sep'] +
                         self.ta_info['add_crlfafterrecord_sep'])
        tofile.write(self.out._record2string(self.out.records[0]))
        self.writefilelist(tofile)
        tofile.write(self.out._record2string(self.out.records[-1]))
        tofile.close()
Esempio n. 10
0
def unique(domein,updatewith=None):
    ''' generate unique number per domain.
        uses db to keep track of last generated number.
    '''
    return str(botslib.unique(domein,updatewith))
Esempio n. 11
0
 def run(self):
     if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
         raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'),
                                         {'ta_info':self.ta_info})
     self._openoutenvelope()
     self.ta_info.update(self.out.ta_info)
     botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)
     #prepare data for envelope
     isa09date = botslib.strftime('%y%m%d')
     #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     #mapping overrules.
     if self.ta_info['testindicator'] and self.ta_info['testindicator'] != '0':    #'0' is default value (in db)
         testindicator = self.ta_info['testindicator']
     else:
         testindicator = self.ta_info['ISA15']
     #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
         self.ta_info['reference'] = unicode(botslib.unique('isacounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = unicode(botslib.unique('isacounter_' + self.ta_info['frompartner']))
     #ISA06 and GS02 can be different; eg ISA06 is a service provider.
     #ISA06 and GS02 can be in the syntax....
     isa06sender = self.ta_info.get('ISA06',self.ta_info['frompartner'])
     isa06sender = isa06sender.ljust(15)    #add spaces; is fixed length
     gs02sender = self.ta_info.get('GS02',self.ta_info['frompartner'])
     #also for ISA08 and GS03
     isa08receiver = self.ta_info.get('ISA08',self.ta_info['topartner'])
     isa08receiver = isa08receiver.ljust(15)    #add spaces; is fixed length
     gs03receiver = self.ta_info.get('GS03',self.ta_info['topartner'])
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put({'BOTSID':'ISA',
                     'ISA01':self.ta_info['ISA01'],
                     'ISA02':self.ta_info['ISA02'],
                     'ISA03':self.ta_info['ISA03'],
                     'ISA04':self.ta_info['ISA04'],
                     'ISA05':self.ta_info['ISA05'],
                     'ISA06':isa06sender,
                     'ISA07':self.ta_info['ISA07'],
                     'ISA08':isa08receiver,
                     'ISA09':isa09date,
                     'ISA10':botslib.strftime('%H%M'),
                     'ISA11':self.ta_info['ISA11'],      #if ISA version > 00403, replaced by reprtion separator
                     'ISA12':self.ta_info['version'],
                     'ISA13':self.ta_info['reference'],
                     'ISA14':self.ta_info['ISA14'],
                     'ISA15':testindicator},strip=False)         #MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'IEA','IEA01':'1','IEA02':self.ta_info['reference']})
     gs08messagetype = self.ta_info['messagetype'][3:]
     if gs08messagetype[:6] < '004010':
         gs04date = botslib.strftime('%y%m%d')
     else:
         gs04date = botslib.strftime('%Y%m%d')
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS',
                                     'GS01':self.ta_info['functionalgroup'],
                                     'GS02':gs02sender,
                                     'GS03':gs03receiver,
                                     'GS04':gs04date,
                                     'GS05':botslib.strftime('%H%M'),
                                     'GS06':self.ta_info['reference'],
                                     'GS07':self.ta_info['GS07'],
                                     'GS08':gs08messagetype})
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS'},{'BOTSID':'GE','GE01':self.ta_info['nrmessages'],'GE02':self.ta_info['reference']})  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.checkmessage(self.out.root,self.out.defmessage)
     self.out.checkforerrorlist()
     self.out.tree2records(self.out.root)
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
     isa_string = self.out.record2string(self.out.lex_records[0:1])
     #ISA has the used separators at certain positions. Normally bots would give errors for this (can not use sep as data) or compress these aways. So this is hardcoded.
     if self.ta_info['version'] < '00403':
         isa_string = isa_string[:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + isa_string[103:] 
     else:
         isa_string = isa_string[:82] +self.ta_info['reserve'] + isa_string[83:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + isa_string[103:]
     tofile.write(isa_string)                                     #write ISA
     tofile.write(self.out.record2string(self.out.lex_records[1:2]))  #write GS
     self.writefilelist(tofile)
     tofile.write(self.out.record2string(self.out.lex_records[2:])) #write GE and IEA
     tofile.close()
Esempio n. 12
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'),
                                            {'ta_info':self.ta_info})

        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)

        #version dependent enveloping
        if self.ta_info['version'] < '4':
            date = botslib.strftime('%y%m%d')
            reserve = ' '
        else:
            date = botslib.strftime('%Y%m%d')
            reserve = self.ta_info['reserve']

        #UNB reference is counter is per sender or receiver
        if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
            self.ta_info['reference'] = unicode(botslib.unique('unbcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(botslib.unique('unbcounter_' + self.ta_info['frompartner']))
        #testindicator is more complex:
        if self.ta_info['testindicator'] and self.ta_info['testindicator'] != '0':    #first check value from ta; do not use default
            testindicator = '1'
        elif self.ta_info['UNB.0035'] != '0':   #than check values from grammar
            testindicator = '1'
        else:
            testindicator = ''
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({'BOTSID':'UNB',
                        'S001.0001':self.ta_info['charset'],
                        'S001.0002':self.ta_info['version'],
                        'S002.0004':self.ta_info['frompartner'],
                        'S003.0010':self.ta_info['topartner'],
                        'S004.0017':date,
                        'S004.0019':botslib.strftime('%H%M'),
                        '0020':self.ta_info['reference']})
        #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
        for field in ('S001.0080','S001.0133','S002.0007','S002.0008','S002.0042',
                      'S003.0007','S003.0014','S003.0046','S005.0022','S005.0025',
                      '0026','0029','0031','0032'):
            if self.ta_info['UNB.'+field]:
                self.out.put({'BOTSID':'UNB',field:self.ta_info['UNB.'+field]})
        if testindicator:
            self.out.put({'BOTSID':'UNB','0035': testindicator})
        self.out.put({'BOTSID':'UNB'},{'BOTSID':'UNZ','0036':self.ta_info['nrmessages'],'0020':self.ta_info['reference']})  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
        #convert the tree into segments; here only the UNB is written (first segment)
        self.out.checkmessage(self.out.root,self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)
        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
        if self.ta_info['forceUNA'] or self.ta_info['charset'] != 'UNOA':
            tofile.write('UNA'+self.ta_info['sfield_sep']+self.ta_info['field_sep']+self.ta_info['decimaal']+self.ta_info['escape']+ reserve +self.ta_info['record_sep']+self.ta_info['add_crlfafterrecord_sep'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()
Esempio n. 13
0
def unique(domein, updatewith=None):
    ''' generate unique number per domain.
        uses db to keep track of last generated number.
    '''
    return unicode(botslib.unique(domein, updatewith))
Esempio n. 14
0
 def run(self):
     self._openoutenvelope(self.ta_info['editype'],
                           self.ta_info['envelope'])
     self.ta_info.update(self.out.ta_info)
     #need to know the functionalgroup code:
     defmessage = grammar.grammarread(self.ta_info['editype'],
                                      self.ta_info['messagetype'])
     self.ta_info['functionalgroup'] = defmessage.syntax['functionalgroup']
     botslib.tryrunscript(self.userscript,
                          self.scriptname,
                          'ta_infocontent',
                          ta_info=self.ta_info)
     #prepare data for envelope
     ISA09date = time.strftime('%y%m%d')
     #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     #mapping overrules.
     if self.ta_info['testindicator'] and self.ta_info[
             'testindicator'] != '0':  #'0' is default value (in db)
         testindicator = self.ta_info['testindicator']
     else:
         testindicator = self.ta_info['ISA15']
     #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean('settings',
                                  'interchangecontrolperpartner', False):
         self.ta_info['reference'] = str(
             botslib.unique('isacounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = str(
             botslib.unique('isacounter_' + self.ta_info['frompartner']))
     #ISA06 and GS02 can be different; eg ISA06 is a service provider.
     #ISA06 and GS02 can be in the syntax....
     ISA06 = self.ta_info.get('ISA06', self.ta_info['frompartner'])
     GS02 = self.ta_info.get('GS02', self.ta_info['frompartner'])
     #also for ISA08 and GS03
     ISA08 = self.ta_info.get('ISA08', self.ta_info['topartner'])
     GS03 = self.ta_info.get('GS03', self.ta_info['topartner'])
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put({
         'BOTSID': 'ISA',
         'ISA01': self.ta_info['ISA01'],
         'ISA02': self.ta_info['ISA02'],
         'ISA03': self.ta_info['ISA03'],
         'ISA04': self.ta_info['ISA04'],
         'ISA05': self.ta_info['ISA05'],
         'ISA06': ISA06,
         'ISA07': self.ta_info['ISA07'],
         'ISA08': ISA08,
         'ISA09': ISA09date,
         'ISA10': time.strftime('%H%M'),
         'ISA11': self.ta_info[
             'ISA11'],  #if ISA version > 00403, replaced by reprtion separator
         'ISA12': self.ta_info['version'],
         'ISA13': self.ta_info['reference'],
         'ISA14': self.ta_info['ISA14'],
         'ISA15': testindicator
     })
     self.out.put({'BOTSID': 'ISA'}, {
         'BOTSID': 'IEA',
         'IEA01': '1',
         'IEA02': self.ta_info['reference']
     })
     GS08 = self.ta_info['messagetype'][3:]
     if GS08[:6] < '004010':
         GS04date = time.strftime('%y%m%d')
     else:
         GS04date = time.strftime('%Y%m%d')
     self.out.put({'BOTSID': 'ISA'}, {
         'BOTSID': 'GS',
         'GS01': self.ta_info['functionalgroup'],
         'GS02': GS02,
         'GS03': GS03,
         'GS04': GS04date,
         'GS05': time.strftime('%H%M'),
         'GS06': self.ta_info['reference'],
         'GS07': self.ta_info['GS07'],
         'GS08': GS08
     })
     self.out.put({'BOTSID': 'ISA'}, {'BOTSID': 'GS'}, {
         'BOTSID': 'GE',
         'GE01': self.ta_info['nrmessages'],
         'GE02': self.ta_info['reference']
     })  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,
                          self.scriptname,
                          'envelopecontent',
                          ta_info=self.ta_info,
                          out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.normalisetree(self.out.root)
     self.out.tree2records(self.out.root)
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                               self.ta_info['charset'])
     ISAstring = self.out._record2string(self.out.records[0])
     if self.ta_info['version'] < '00403':
         ISAstring = ISAstring[:103] + self.ta_info[
             'field_sep'] + self.ta_info['sfield_sep'] + ISAstring[
                 103:]  #hack for strange characters at end of ISA; hardcoded
     else:
         ISAstring = ISAstring[:82] + self.ta_info['reserve'] + ISAstring[
             83:103] + self.ta_info['field_sep'] + self.ta_info[
                 'sfield_sep'] + ISAstring[
                     103:]  #hack for strange characters at end of ISA; hardcoded
     tofile.write(ISAstring)  #write ISA
     tofile.write(self.out._record2string(self.out.records[1]))  #write GS
     self.writefilelist(tofile)
     tofile.write(self.out._record2string(self.out.records[-2]))  #write GE
     tofile.write(self.out._record2string(self.out.records[-1]))  #write IEA
     tofile.close()
     if self.ta_info[
             'functionalgroup'] != 'FA' and botslib.checkconfirmrules(
                 'ask-x12-997',
                 idroute=self.ta_info['idroute'],
                 idchannel=self.ta_info['tochannel'],
                 topartner=self.ta_info['topartner'],
                 frompartner=self.ta_info['frompartner'],
                 editype=self.ta_info['editype'],
                 messagetype=self.ta_info['messagetype']):
         self.ta_info['confirmtype'] = u'ask-x12-997'
         self.ta_info['confirmasked'] = True
Esempio n. 15
0
 def run(self):
     self._openoutenvelope(self.ta_info['editype'],self.ta_info['envelope'])
     self.ta_info.update(self.out.ta_info)
     botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)
     
     #version dependent enveloping
     writeUNA = False
     if self.ta_info['version']<'4':
         date = time.strftime('%y%m%d')
         reserve = ' '
         if self.ta_info['charset'] != 'UNOA':
             writeUNA = True
     else:
         date = time.strftime('%Y%m%d')
         reserve = self.ta_info['reserve']
         if self.ta_info['charset'] not in ['UNOA','UNOB']:
             writeUNA = True
     
     #UNB counter is per sender or receiver
     if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
         self.ta_info['reference'] = str(botslib.unique('unbcounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = str(botslib.unique('unbcounter_' + self.ta_info['frompartner']))
     
     #testindicator is more complex:
     if self.ta_info['testindicator'] and self.ta_info['testindicator']!='0':    #first check value from ta; do not use default
         testindicator = '1'
     elif self.ta_info['UNB.0035'] != '0':   #than check values from grammar
         testindicator = '1'
     else:
         testindicator = ''
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put({'BOTSID':'UNB',
                     'S001.0001':self.ta_info['charset'],
                     'S001.0002':self.ta_info['version'],
                     'S002.0004':self.ta_info['frompartner'],
                     'S003.0010':self.ta_info['topartner'],
                     'S004.0017':date,
                     'S004.0019':time.strftime('%H%M'),
                     '0020':self.ta_info['reference']})
     #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
     if self.ta_info['UNB.S002.0007']:
         self.out.put({'BOTSID':'UNB','S002.0007': self.ta_info['UNB.S002.0007']})
     if self.ta_info['UNB.S003.0007']:
         self.out.put({'BOTSID':'UNB','S003.0007': self.ta_info['UNB.S003.0007']})
     if self.ta_info['UNB.0026']:
         self.out.put({'BOTSID':'UNB','0026': self.ta_info['UNB.0026']})
     if testindicator:
         self.out.put({'BOTSID':'UNB','0035': testindicator})
     self.out.put({'BOTSID':'UNB'},{'BOTSID':'UNZ','0036':self.ta_info['nrmessages'],'0020':self.ta_info['reference']})  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.normalisetree(self.out.root)
     self.out.tree2records(self.out.root)
     
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
     if writeUNA or self.ta_info['forceUNA']:
         tofile.write('UNA'+self.ta_info['sfield_sep']+self.ta_info['field_sep']+self.ta_info['decimaal']+self.ta_info['escape']+ reserve +self.ta_info['record_sep']+self.ta_info['add_crlfafterrecord_sep'])
     tofile.write(self.out._record2string(self.out.records[0]))
     self.writefilelist(tofile)
     tofile.write(self.out._record2string(self.out.records[-1]))
     tofile.close()
Esempio n. 16
0
 def run(self):
     self._openoutenvelope(self.ta_info['editype'],self.ta_info['envelope'])
     self.ta_info.update(self.out.ta_info)
     #need to know the functionalgroup code:
     defmessage = grammar.grammarread(self.ta_info['editype'],self.ta_info['messagetype'])
     self.ta_info['functionalgroup'] = defmessage.syntax['functionalgroup']
     botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info)
     #prepare data for envelope
     ISA09date = time.strftime('%y%m%d')
     #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     #mapping overrules. 
     if self.ta_info['testindicator'] and self.ta_info['testindicator']!='0':    #'0' is default value (in db)
         testindicator = self.ta_info['testindicator']
     else:
         testindicator = self.ta_info['ISA15']
     #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False):
         self.ta_info['reference'] = str(botslib.unique('isacounter_' + self.ta_info['topartner']))
     else:
         self.ta_info['reference'] = str(botslib.unique('isacounter_' + self.ta_info['frompartner']))
     #ISA06 and GS02 can be different; eg ISA06 is a service provider.
     #ISA06 and GS02 can be in the syntax....
     ISA06 = self.ta_info.get('ISA06',self.ta_info['frompartner'])
     GS02 = self.ta_info.get('GS02',self.ta_info['frompartner'])
     #also for ISA08 and GS03
     ISA08 = self.ta_info.get('ISA08',self.ta_info['topartner'])
     GS03 = self.ta_info.get('GS03',self.ta_info['topartner'])
     #build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put({'BOTSID':'ISA',
                     'ISA01':self.ta_info['ISA01'],
                     'ISA02':self.ta_info['ISA02'],
                     'ISA03':self.ta_info['ISA03'],
                     'ISA04':self.ta_info['ISA04'],
                     'ISA05':self.ta_info['ISA05'],
                     'ISA06':ISA06,
                     'ISA07':self.ta_info['ISA07'],
                     'ISA08':ISA08,
                     'ISA09':ISA09date,
                     'ISA10':time.strftime('%H%M'),
                     'ISA11':self.ta_info['ISA11'],      #if ISA version > 00403, replaced by reprtion separator
                     'ISA12':self.ta_info['version'],
                     'ISA13':self.ta_info['reference'],
                     'ISA14':self.ta_info['ISA14'],
                     'ISA15':testindicator})
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'IEA','IEA01':'1','IEA02':self.ta_info['reference']})
     GS08 = self.ta_info['messagetype'][3:]
     if GS08[:6]<'004010':
         GS04date = time.strftime('%y%m%d')
     else:
         GS04date = time.strftime('%Y%m%d')
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS',
                                     'GS01':self.ta_info['functionalgroup'],
                                     'GS02':GS02,
                                     'GS03':GS03,
                                     'GS04':GS04date,
                                     'GS05':time.strftime('%H%M'),
                                     'GS06':self.ta_info['reference'],
                                     'GS07':self.ta_info['GS07'],
                                     'GS08':GS08})
     self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS'},{'BOTSID':'GE','GE01':self.ta_info['nrmessages'],'GE02':self.ta_info['reference']})  #dummy segment; is not used
     #user exit
     botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out)
     #convert the tree into segments; here only the UNB is written (first segment)
     self.out.normalisetree(self.out.root)
     self.out.tree2records(self.out.root)
     #start doing the actual writing:
     tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset'])
     ISAstring = self.out._record2string(self.out.records[0])
     if self.ta_info['version']<'00403':
         ISAstring = ISAstring[:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + ISAstring[103:] #hack for strange characters at end of ISA; hardcoded
     else:
         ISAstring = ISAstring[:82] +self.ta_info['reserve'] + ISAstring[83:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + ISAstring[103:] #hack for strange characters at end of ISA; hardcoded
     tofile.write(ISAstring)                                     #write ISA
     tofile.write(self.out._record2string(self.out.records[1]))  #write GS
     self.writefilelist(tofile)
     tofile.write(self.out._record2string(self.out.records[-2])) #write GE
     tofile.write(self.out._record2string(self.out.records[-1])) #write IEA
     tofile.close()
     if self.ta_info['functionalgroup']!='FA' and botslib.checkconfirmrules('ask-x12-997',idroute=self.ta_info['idroute'],idchannel=self.ta_info['tochannel'],
                                                                             topartner=self.ta_info['topartner'],frompartner=self.ta_info['frompartner'],
                                                                             editype=self.ta_info['editype'],messagetype=self.ta_info['messagetype']):
         self.ta_info['confirmtype'] = u'ask-x12-997'
         self.ta_info['confirmasked'] = True
Esempio n. 17
0
def unique(domein):
    ''' generate unique number within range domein.
        uses db to keep track of last generated number.
        if domein not used before, initialized with 1.
    '''
    return str(botslib.unique(domein))
Esempio n. 18
0
    def run(self):
        if not self.ta_info["topartner"] or not self.ta_info["frompartner"]:
            raise botslib.OutMessageError(
                _(u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".'), ta_info=self.ta_info
            )

        self._openoutenvelope(self.ta_info["editype"], self.ta_info["envelope"])
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript, self.scriptname, "ta_infocontent", ta_info=self.ta_info)

        # version dependent enveloping
        write_una = False
        if self.ta_info["version"] < "4":
            date = time.strftime("%y%m%d")
            reserve = " "
            if self.ta_info["charset"] != "UNOA":
                write_una = True
        else:
            date = time.strftime("%Y%m%d")
            reserve = self.ta_info["reserve"]
            if self.ta_info["charset"] not in ["UNOA", "UNOB"]:
                write_una = True

        # UNB counter is per sender or receiver
        if botsglobal.ini.getboolean("settings", "interchangecontrolperpartner", False):
            self.ta_info["reference"] = str(botslib.unique("unbcounter_" + self.ta_info["topartner"]))
        else:
            self.ta_info["reference"] = str(botslib.unique("unbcounter_" + self.ta_info["frompartner"]))

        # testindicator is more complex:
        if (
            self.ta_info["testindicator"] and self.ta_info["testindicator"] != "0"
        ):  # first check value from ta; do not use default
            testindicator = "1"
        elif self.ta_info["UNB.0035"] != "0":  # than check values from grammar
            testindicator = "1"
        else:
            testindicator = ""
        # build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put(
            {
                "BOTSID": "UNB",
                "S001.0001": self.ta_info["charset"],
                "S001.0002": self.ta_info["version"],
                "S002.0004": self.ta_info["frompartner"],
                "S003.0010": self.ta_info["topartner"],
                "S004.0017": date,
                "S004.0019": time.strftime("%H%M"),
                "0020": self.ta_info["reference"],
            }
        )
        # the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
        for field in (
            "S001.0080",
            "S001.0133",
            "S002.0007",
            "S002.0008",
            "S002.0042",
            "S003.0007",
            "S003.0014",
            "S003.0046",
            "S005.0022",
            "S005.0025",
            "0026",
            "0029",
            "0031",
            "0032",
        ):
            if self.ta_info["UNB." + field]:
                self.out.put({"BOTSID": "UNB", field: self.ta_info["UNB." + field]})
        if testindicator:
            self.out.put({"BOTSID": "UNB", "0035": testindicator})
        self.out.put(
            {"BOTSID": "UNB"}, {"BOTSID": "UNZ", "0036": self.ta_info["nrmessages"], "0020": self.ta_info["reference"]}
        )  # dummy segment; is not used
        # user exit
        botslib.tryrunscript(self.userscript, self.scriptname, "envelopecontent", ta_info=self.ta_info, out=self.out)
        # convert the tree into segments; here only the UNB is written (first segment)
        self.out.checkmessage(self.out.root, self.out.defmessage)
        self.out.tree2records(self.out.root)

        # start doing the actual writing:
        tofile = botslib.opendata(self.ta_info["filename"], "wb", self.ta_info["charset"])
        if write_una or self.ta_info["forceUNA"]:
            tofile.write(
                "UNA"
                + self.ta_info["sfield_sep"]
                + self.ta_info["field_sep"]
                + self.ta_info["decimaal"]
                + self.ta_info["escape"]
                + reserve
                + self.ta_info["record_sep"]
                + self.ta_info["add_crlfafterrecord_sep"]
            )
        tofile.write(self.out.record2string(self.out.records[0]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.records[-1]))
        tofile.close()
        if self.ta_info["messagetype"][:6] != "CONTRL" and botslib.checkconfirmrules(
            "ask-edifact-CONTRL",
            idroute=self.ta_info["idroute"],
            idchannel=self.ta_info["tochannel"],
            topartner=self.ta_info["topartner"],
            frompartner=self.ta_info["frompartner"],
            editype=self.ta_info["editype"],
            messagetype=self.ta_info["messagetype"],
        ):
            self.ta_info["confirmtype"] = u"ask-edifact-CONTRL"
            self.ta_info["confirmasked"] = True
Esempio n. 19
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(
                _(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'
                  ), {'ta_info': self.ta_info})

        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'ta_infocontent',
                             ta_info=self.ta_info)

        #version dependent enveloping
        if self.ta_info['version'] < '4':
            date = botslib.strftime('%y%m%d')
            reserve = ' '
        else:
            date = botslib.strftime('%Y%m%d')
            reserve = self.ta_info['reserve']

        #UNB reference is counter is per sender or receiver
        if botsglobal.ini.getboolean('settings',
                                     'interchangecontrolperpartner', False):
            self.ta_info['reference'] = unicode(
                botslib.unique('unbcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(
                botslib.unique('unbcounter_' + self.ta_info['frompartner']))
        #testindicator is more complex:
        if self.ta_info['testindicator'] and self.ta_info[
                'testindicator'] != '0':  #first check value from ta; do not use default
            testindicator = '1'
        elif self.ta_info['UNB.0035'] != '0':  #than check values from grammar
            testindicator = '1'
        else:
            testindicator = ''
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({
            'BOTSID': 'UNB',
            'S001.0001': self.ta_info['charset'],
            'S001.0002': self.ta_info['version'],
            'S002.0004': self.ta_info['frompartner'],
            'S003.0010': self.ta_info['topartner'],
            'S004.0017': date,
            'S004.0019': botslib.strftime('%H%M'),
            '0020': self.ta_info['reference']
        })
        #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account)
        for field in ('S001.0080', 'S001.0133', 'S002.0007', 'S002.0008',
                      'S002.0042', 'S003.0007', 'S003.0014', 'S003.0046',
                      'S005.0022', 'S005.0025', '0026', '0029', '0031',
                      '0032'):
            if self.ta_info['UNB.' + field]:
                self.out.put({
                    'BOTSID': 'UNB',
                    field: self.ta_info['UNB.' + field]
                })
        if testindicator:
            self.out.put({'BOTSID': 'UNB', '0035': testindicator})
        self.out.put({'BOTSID': 'UNB'}, {
            'BOTSID': 'UNZ',
            '0036': self.ta_info['nrmessages'],
            '0020': self.ta_info['reference']
        })  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'envelopecontent',
                             ta_info=self.ta_info,
                             out=self.out)
        #convert the tree into segments; here only the UNB is written (first segment)
        self.out.checkmessage(self.out.root, self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)
        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                                  self.ta_info['charset'])
        if self.ta_info['forceUNA'] or self.ta_info['charset'] != 'UNOA':
            tofile.write('UNA' + self.ta_info['sfield_sep'] +
                         self.ta_info['field_sep'] + self.ta_info['decimaal'] +
                         self.ta_info['escape'] + reserve +
                         self.ta_info['record_sep'] +
                         self.ta_info['add_crlfafterrecord_sep'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()
Esempio n. 20
0
 def run(self):
     if not self.ta_info["topartner"] or not self.ta_info["frompartner"]:
         raise botslib.OutMessageError(
             _(u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".'), ta_info=self.ta_info
         )
     self._openoutenvelope(self.ta_info["editype"], self.ta_info["envelope"])
     self.ta_info.update(self.out.ta_info)
     # need to know the functionalgroup code:
     defmessage = grammar.grammarread(self.ta_info["editype"], self.ta_info["messagetype"])
     self.ta_info["functionalgroup"] = defmessage.syntax["functionalgroup"]
     botslib.tryrunscript(self.userscript, self.scriptname, "ta_infocontent", ta_info=self.ta_info)
     # prepare data for envelope
     isa09date = time.strftime("%y%m%d")
     # test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator'])
     # mapping overrules.
     if self.ta_info["testindicator"] and self.ta_info["testindicator"] != "0":  #'0' is default value (in db)
         testindicator = self.ta_info["testindicator"]
     else:
         testindicator = self.ta_info["ISA15"]
     # ~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator
     if botsglobal.ini.getboolean("settings", "interchangecontrolperpartner", False):
         self.ta_info["reference"] = str(botslib.unique("isacounter_" + self.ta_info["topartner"]))
     else:
         self.ta_info["reference"] = str(botslib.unique("isacounter_" + self.ta_info["frompartner"]))
     # ISA06 and GS02 can be different; eg ISA06 is a service provider.
     # ISA06 and GS02 can be in the syntax....
     isa06sender = self.ta_info.get("ISA06", self.ta_info["frompartner"])
     isa06sender = isa06sender.ljust(15)  # add spaces; is fixed length
     gs02sender = self.ta_info.get("GS02", self.ta_info["frompartner"])
     # also for ISA08 and GS03
     isa08receiver = self.ta_info.get("ISA08", self.ta_info["topartner"])
     isa08receiver = isa08receiver.ljust(15)  # add spaces; is fixed length
     gs03receiver = self.ta_info.get("GS03", self.ta_info["topartner"])
     # build the envelope segments (that is, the tree from which the segments will be generated)
     self.out.put(
         {
             "BOTSID": "ISA",
             "ISA01": self.ta_info["ISA01"],
             "ISA02": self.ta_info["ISA02"],
             "ISA03": self.ta_info["ISA03"],
             "ISA04": self.ta_info["ISA04"],
             "ISA05": self.ta_info["ISA05"],
             "ISA06": isa06sender,
             "ISA07": self.ta_info["ISA07"],
             "ISA08": isa08receiver,
             "ISA09": isa09date,
             "ISA10": time.strftime("%H%M"),
             "ISA11": self.ta_info["ISA11"],  # if ISA version > 00403, replaced by reprtion separator
             "ISA12": self.ta_info["version"],
             "ISA13": self.ta_info["reference"],
             "ISA14": self.ta_info["ISA14"],
             "ISA15": testindicator,
         },
         strip=False,
     )  # MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length
     self.out.put({"BOTSID": "ISA"}, {"BOTSID": "IEA", "IEA01": "1", "IEA02": self.ta_info["reference"]})
     gs08messagetype = self.ta_info["messagetype"][3:]
     if gs08messagetype[:6] < "004010":
         gs04date = time.strftime("%y%m%d")
     else:
         gs04date = time.strftime("%Y%m%d")
     self.out.put(
         {"BOTSID": "ISA"},
         {
             "BOTSID": "GS",
             "GS01": self.ta_info["functionalgroup"],
             "GS02": gs02sender,
             "GS03": gs03receiver,
             "GS04": gs04date,
             "GS05": time.strftime("%H%M"),
             "GS06": self.ta_info["reference"],
             "GS07": self.ta_info["GS07"],
             "GS08": gs08messagetype,
         },
     )
     self.out.put(
         {"BOTSID": "ISA"},
         {"BOTSID": "GS"},
         {"BOTSID": "GE", "GE01": self.ta_info["nrmessages"], "GE02": self.ta_info["reference"]},
     )  # dummy segment; is not used
     # user exit
     botslib.tryrunscript(self.userscript, self.scriptname, "envelopecontent", ta_info=self.ta_info, out=self.out)
     # convert the tree into segments; here only the UNB is written (first segment)
     self.out.checkmessage(self.out.root, self.out.defmessage)
     self.out.tree2records(self.out.root)
     # start doing the actual writing:
     tofile = botslib.opendata(self.ta_info["filename"], "wb", self.ta_info["charset"])
     isa_string = self.out.record2string(self.out.records[0])
     if self.ta_info["version"] < "00403":
         isa_string = (
             isa_string[:103] + self.ta_info["field_sep"] + self.ta_info["sfield_sep"] + isa_string[103:]
         )  # hack for strange characters at end of ISA; hardcoded
     else:
         isa_string = (
             isa_string[:82]
             + self.ta_info["reserve"]
             + isa_string[83:103]
             + self.ta_info["field_sep"]
             + self.ta_info["sfield_sep"]
             + isa_string[103:]
         )  # hack for strange characters at end of ISA; hardcoded
     tofile.write(isa_string)  # write ISA
     tofile.write(self.out.record2string(self.out.records[1]))  # write GS
     self.writefilelist(tofile)
     tofile.write(self.out.record2string(self.out.records[-2]))  # write GE
     tofile.write(self.out.record2string(self.out.records[-1]))  # write IEA
     tofile.close()
     if self.ta_info["functionalgroup"] != "FA" and botslib.checkconfirmrules(
         "ask-x12-997",
         idroute=self.ta_info["idroute"],
         idchannel=self.ta_info["tochannel"],
         topartner=self.ta_info["topartner"],
         frompartner=self.ta_info["frompartner"],
         editype=self.ta_info["editype"],
         messagetype=self.ta_info["messagetype"],
     ):
         self.ta_info["confirmtype"] = u"ask-x12-997"
         self.ta_info["confirmasked"] = True
Esempio n. 21
0
    def run(self):
        if not self.ta_info['topartner'] or not self.ta_info['frompartner']:
            raise botslib.OutMessageError(
                _(u'In enveloping "frompartner" or "topartner" unknown: "%(ta_info)s".'
                  ), {'ta_info': self.ta_info})
        self._openoutenvelope()
        self.ta_info.update(self.out.ta_info)
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'ta_infocontent',
                             ta_info=self.ta_info)
        #prepare data for envelope
        if botsglobal.ini.getboolean('settings',
                                     'interchangecontrolperpartner', False):
            self.ta_info['reference'] = unicode(
                botslib.unique('stxcounter_' + self.ta_info['topartner']))
        else:
            self.ta_info['reference'] = unicode(
                botslib.unique('stxcounter_' + self.ta_info['frompartner']))
        #build the envelope segments (that is, the tree from which the segments will be generated)
        self.out.put({
            'BOTSID': 'STX',
            'STDS1': self.ta_info['STX.STDS1'],
            'STDS2': self.ta_info['STX.STDS2'],
            'FROM.01': self.ta_info['frompartner'],
            'UNTO.01': self.ta_info['topartner'],
            'TRDT.01': botslib.strftime('%y%m%d'),
            'TRDT.02': botslib.strftime('%H%M%S'),
            'SNRF': self.ta_info['reference']
        })
        if self.ta_info['STX.FROM.02']:
            self.out.put({
                'BOTSID': 'STX',
                'FROM.02': self.ta_info['STX.FROM.02']
            })
        if self.ta_info['STX.UNTO.02']:
            self.out.put({
                'BOTSID': 'STX',
                'UNTO.02': self.ta_info['STX.UNTO.02']
            })
        if self.ta_info['STX.APRF']:
            self.out.put({'BOTSID': 'STX', 'APRF': self.ta_info['STX.APRF']})
        if self.ta_info['STX.PRCD']:
            self.out.put({'BOTSID': 'STX', 'PRCD': self.ta_info['STX.PRCD']})
        self.out.put({'BOTSID': 'STX'}, {
            'BOTSID': 'END',
            'NMST': self.ta_info['nrmessages']
        })  #dummy segment; is not used
        #user exit
        botslib.tryrunscript(self.userscript,
                             self.scriptname,
                             'envelopecontent',
                             ta_info=self.ta_info,
                             out=self.out)
        #convert the tree into segments; here only the STX is written (first segment)
        self.out.checkmessage(self.out.root, self.out.defmessage)
        self.out.checkforerrorlist()
        self.out.tree2records(self.out.root)

        #start doing the actual writing:
        tofile = botslib.opendata(self.ta_info['filename'], 'wb',
                                  self.ta_info['charset'])
        tofile.write(self.out.record2string(self.out.lex_records[0:1]))
        self.writefilelist(tofile)
        tofile.write(self.out.record2string(self.out.lex_records[1:2]))
        tofile.close()