Ejemplo n.º 1
0
def exportcsv(dataType):

    c = setting()
    l = logger('exportData')
    databasePath = c.get('parser', 'db_path')
    db = dbConnection(databasePath, l)
    try:
        filename = c.get('exportcsv',
                         'output_path') + '/export-data-' + dataType + '.csv'
        file = open(filename, "w")
        writer = csv.writer(file,
                            delimiter=',',
                            quotechar='"',
                            quoting=csv.QUOTE_ALL)
        data = []
        if 'station' == dataType:
            headers = db.getAllStationInfoHeaders()
            data = db.getAllStationInfo()
        elif 'train' == dataType:
            headers = db.getAllTrainInfoHeaders()
            data = db.getAllTrainInfo()
        # Writing the values
        writer.writerow(list(headers))
        for row in data:
            writer.writerow(list(row))
        file.close()

    except (IOError, Exception) as e:
        print e
Ejemplo n.º 2
0
def exportcsv(dataType):

    c = setting()
    l = logger('exportData')
    databasePath = c.get('parser', 'db_path')
    db = dbConnection(databasePath, l)
    try:
        filename= c.get ('exportcsv', 'output_path') + '/export-data-' + dataType + '.csv'
        file  = open(filename, "w")
        writer = csv.writer(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
        data = []
        if 'station' == dataType:
            headers = db.getAllStationInfoHeaders()
            data = db.getAllStationInfo()
        elif 'train' == dataType:
            headers = db.getAllTrainInfoHeaders()
            data = db.getAllTrainInfo()
        # Writing the values
        writer.writerow(list(headers))
        for row in data:
            writer.writerow(list(row))
        file.close()

    except (IOError, Exception) as e:
            print e
Ejemplo n.º 3
0
 def __init__(self, databasePath, systemType):
     self.systemType = systemType
     self.logging = logger(self.systemType)
     self.databasePath = databasePath
     self.db = dbConnection(self.databasePath, self.logging)
     self.writer = publish(self.logging)
     self.__cfg = setting()
     self.__ticketPrint = False
Ejemplo n.º 4
0
 def __init__(self):
     self.c = setting()
     self.logging = logger('export')
     databasePath = self.c.get('parser', 'db_path')
     self.db = dbConnection(databasePath, self.logging)
     self.writeCsv()
     dataClean = int(self.c.get('exportcsv', 'data_clean'))
     if 1 == int(dataClean):
         self.db.deleteAllTicketDetails()
Ejemplo n.º 5
0
 def __init__(self):
     self.c = setting()
     self.logging = logger('export')
     databasePath = self.c.get('parser', 'db_path')
     self.db = dbConnection(databasePath, self.logging)
     self.writeCsv()
     dataClean = int(self.c.get('exportcsv', 'data_clean'))
     if 1 == int(dataClean):
         self.db.deleteAllTicketDetails()
Ejemplo n.º 6
0
    def __detectionData(debug, sampleFile):
        dataType = 'prs'
        packet = ''
        try:
            if 0 == int(debug):
                c = setting()
                serialPortName = c.get('parser', 'serial_port_name')
                if serialPortName == '0':
                    serialPortName = 0
                fh = serial.Serial(serialPortName)
            else:
                fh = open(sampleFile)
                # Getting the sub string of serial data
            read = True
            checkPacketCount = 0
            while read:
                try:
                    start = fh.read(1)
                except serial.SerialException as e:
                    continue

                if start.strip() != "":
                    data = Readttys.__byteToHex(start)
                    #print data
                    # Check the uts unique code in getting data and decide what it is
                    if '^$' in packet:
                        #print packet
                        dataType = 'uts'
                        read = False
                    elif data == "1B":
                        packetData = Readttys.__byteToHex(packet)
                        packet = ""
                        checkPacketCount += 1
                        if '1B5B306D' == packetData:
                            dataType = 'uts-dumb'
                            read = False

                    if Readttys.checkDataSize == checkPacketCount:
                        read = False
                    packet += start
            fh.close()
        except BaseException as e:
            print 'Error in reading the data :'
            print e
            sys.exit(0)

        return dataType
Ejemplo n.º 7
0
    def __detectionData(debug, sampleFile):
        dataType = 'prs'
        packet = ''
        try:
            if 0 == int(debug):
                c = setting()
                serialPortName = c.get('parser', 'serial_port_name')
                if serialPortName == '0':
                    serialPortName = 0
                fh = serial.Serial(serialPortName)
            else:
                fh = open(sampleFile)
                # Getting the sub string of serial data
            read = True
            checkPacketCount = 0
            while read:
                start = fh.read(1)
                if start.strip() != "":
                    data = Readttys.__byteToHex(start)

                    #print data
                    # Check the uts unique code in getting data and decide what it is
                    if '^$' in packet:
                        #print packet
                        dataType = 'uts'
                        read = False
                    elif data == "1B":
                        packetData = Readttys.__byteToHex(packet)
                        packet = ""
                        checkPacketCount += 1
                        if '1B5B306D' == packetData:
                            dataType = 'uts-dumb'
                            read = False

                    if Readttys.checkDataSize == checkPacketCount:
                        read = False
                    packet += start
            fh.close()
        except BaseException as e:
            print 'Error in reading the data :'
            print e
            sys.exit(0)

        return dataType
Ejemplo n.º 8
0
    def __detectionData(debug, sampleFile):
        dataType = "prs"
        packet = ""
        try:
            if 0 == int(debug):
                c = setting()
                serialPortName = c.get("parser", "serial_port_name")
                if serialPortName == "0":
                    serialPortName = 0
                fh = serial.Serial(serialPortName)
            else:
                fh = open(sampleFile)
                # Getting the sub string of serial data
            read = True
            checkPacketCount = 0
            while read:
                start = fh.read(1)
                if start.strip() != "":
                    data = Readttys.__byteToHex(start)

                    # print data
                    # Check the uts unique code in getting data and decide what it is
                    if "^$" in packet:
                        # print packet
                        dataType = "uts"
                        read = False
                    elif data == "1B":
                        packetData = Readttys.__byteToHex(packet)
                        packet = ""
                        checkPacketCount += 1
                        if "1B5B306D" == packetData:
                            dataType = "uts-dumb"
                            read = False

                    if Readttys.checkDataSize == checkPacketCount:
                        read = False
                    packet += start
            fh.close()
        except BaseException as e:
            print "Error in reading the data :"
            print e
            sys.exit(0)

        return dataType
Ejemplo n.º 9
0
def importcsv(dataType):

    c = setting()
    l = logger('exportData')
    databasePath = c.get('parser', 'db_path')
    db = dbConnection(databasePath, l)
    try:
        filename = c.get('exportcsv',
                         'output_path') + '/import-data-' + dataType + '.csv'
        reader = csv.reader(open(filename, 'r'), delimiter=',')

        if 'station' == dataType:
            tablename = 'stationinfo'
        elif 'train' == dataType:
            tablename = 'traininfo'

        rowno = 1
        fields = ''
        for data in reader:
            if 1 == rowno:
                # Validating colums
                validColumns(dataType, data)
                # Drop the schema of table
                try:
                    db.cursor.execute('drop table ' + tablename)
                except Exception as e:
                    pass
                # create the table
                sql = createTable(tablename, data)
                db.cursor.execute(sql)
                # build the insert query
                sql = insertTable(tablename, data)
            else:
                # execute the  insert query
                try:
                    db.cursor.execute(sql, data)
                    db.connection.commit()
                except (IOError, Exception) as e:
                    print 'Error: Inserting row :' + e
            rowno += 1
        #db.connection.commit()
    except (IOError, Exception) as e:
        print e
Ejemplo n.º 10
0
def importcsv(dataType):

    c = setting()
    l = logger('exportData')
    databasePath = c.get('parser', 'db_path')
    db = dbConnection(databasePath, l)
    try:
        filename= c.get ('exportcsv', 'output_path') + '/import-data-' + dataType + '.csv'
        reader = csv.reader(open(filename, 'r'), delimiter=',')

        if 'station' == dataType:
            tablename = 'stationinfo'
        elif 'train' == dataType:
            tablename = 'traininfo'

        rowno = 1
        fields = ''
        for data in reader:
            if 1 == rowno:
                # Validating colums
                validColumns(dataType, data)
                # Drop the schema of table
                try:
                    db.cursor.execute('drop table ' + tablename)
                except Exception as e:
                    pass
                # create the table
                sql = createTable(tablename, data)
                db.cursor.execute(sql)
                # build the insert query
                sql = insertTable(tablename, data)
            else:
                # execute the  insert query
                try:
                    db.cursor.execute(sql, data)
                    db.connection.commit()
                except (IOError, Exception) as e:
                    print 'Error: Inserting row :' + e
            rowno += 1
        #db.connection.commit()
    except (IOError, Exception) as e:
            print e
Ejemplo n.º 11
0
    def main():
        c = setting()
        debug = c.get('parser', 'debug')
        testDataFile = c.get('parser', 'test_data_file')
        dataType = c.get('default', 'counter_type')
        dataType = dataType.lower()

        if 'prs' != dataType and 'uts' != dataType and 'uts-dumb' != dataType and 'uts-db' != dataType:
            dataType = Readttys.__detectionData(debug, testDataFile)

        if 'prs' == dataType:
            r = readerprs(c.get('parser', 'db_path'), dataType)
            print "PRS"
        elif 'uts-dumb' == dataType or 'uts-db' == dataType:
            r = readerutsdumb(c.get('parser', 'db_path'), dataType)
            print "UTS-Dumb"
        elif 'uts' == dataType:
            r = readeruts(c.get('parser', 'db_path'), dataType)
            print "UTS"

        if 0 == int(debug):
            r.readSerialport()
        else:
            r.readSampleFile(testDataFile)
Ejemplo n.º 12
0
    def main():
        c = setting()
        debug = c.get("parser", "debug")
        testDataFile = c.get("parser", "test_data_file")
        dataType = c.get("default", "counter_type")
        dataType = dataType.lower()

        if "prs" != dataType and "uts" != dataType and "uts-dumb" != dataType and "uts-db" != dataType:
            dataType = Readttys.__detectionData(debug, testDataFile)

        if "prs" == dataType:
            r = readerprs(c.get("parser", "db_path"), dataType)
            print "PRS"
        elif "uts-dumb" == dataType or "uts-db" == dataType:
            r = readerutsdumb(c.get("parser", "db_path"), dataType)
            print "UTS-Dumb"
        elif "uts" == dataType:
            r = readeruts(c.get("parser", "db_path"), dataType)
            print "UTS"

        if 0 == int(debug):
            r.readSerialport()
        else:
            r.readSampleFile(testDataFile)
Ejemplo n.º 13
0
    def main():
        c = setting()
        debug = c.get('parser', 'debug')
        testDataFile = c.get('parser', 'test_data_file')
        dataType = c.get('default', 'counter_type')
        dataType = dataType.lower()

        if 'prs' != dataType and 'uts' != dataType and 'uts-dumb' != dataType and 'uts-db' != dataType:
            dataType = Readttys.__detectionData(debug, testDataFile)

        if 'prs' == dataType:
            r = readerprs(c.get('parser', 'db_path'), dataType)
            print "PRS"
        elif 'uts-dumb' == dataType or 'uts-db' == dataType:
            r = readerutsdumb(c.get('parser', 'db_path'), dataType)
            print "UTS-Dumb"
        elif 'uts' == dataType:
            r = readeruts(c.get('parser', 'db_path'), dataType)
            print "UTS"

        if 0 == int(debug):
            r.readSerialport()
        else:
            r.readSampleFile(testDataFile)
Ejemplo n.º 14
0
    def __init__(self, logging):
        self.__cfg = setting()
        self.logging = logging

        self.dataDist['logoutmsg'] = self.__cfg.get('parser', 'logout_msg')
Ejemplo n.º 15
0
 def __init__(self, systemType):
     self.c = setting()
     self.readttylog = self.c.get('default', 'readttylog')
     if '0' != self.readttylog:
         file = self.c.get('logging', 'file_path') + '/tty-' + systemType + '.log'
         logging.basicConfig(filename=file, filemode='w', level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(message)s')