Example #1
0
def register_vehicle(conn):

    while True:
        serialno = common.read_string('Serial Number', 15)
        if serialno == None:
            return None
        if not common.exists(conn, 'vehicle', 'serial_no', serialno):
            break
        print('The serial number of the vehicle already exists!')

    maker = common.read_string('Maker', 20)
    if maker == None:
        return None
    model = common.read_string('Model', 20)
    if model == None:
        return None
    year = common.read_int('Year', 0, 9999)
    if year == None:
        return None
    color = common.read_string('Color', 10)
    if color == None:
        return None

    while True:
        vtype = common.read_string('Type')
        if vtype == None:
            return None
        if common.exists(conn, 'vehicle_type', 'type_id', vtype):
            break
        print('The selected vehicle type does not exists!')

    try:
        curs = conn.cursor()
        curs.bindarraysize = 1
        curs.setinputsizes(15,20,20,int,10,int)
        curs.executemany('insert into vehicle values (:1,:2,:3,:4,:5,:6)',
            [(serialno,maker,model,year,color,vtype)])
        curs.close()
        conn.commit()
        return True
    except cx_Oracle.DatabaseError as e:
        error, = e.args
        if error.code == 1:
            print('Error: The serial number of the vehicle already exists!')
        elif error.code == 2291:
            print('Error: The selected vehicle type does not exists!')
        else:
            print('Unknown error', error.code,'!')
        return False
Example #2
0
def register_person(conn):
    
    while True:
        sin = common.read_string('SIN', 15)
        if sin == None:
            return None
        if not common.exists(conn, 'people', 'sin', sin):
            break
        print('A person with this social insurance number already exists!')
    
    name = common.read_string('Name', 20)
    if name == None:
        return None
    height = common.read_float('Height', 0)
    if height == None:
        return None
    weight = common.read_float('Weight', 0)
    if weight == None:
        return None
    eyecolor = common.read_string('Eye Color', 10)
    if eyecolor == None:
        return None
    haircolor = common.read_string('Hair Color', 10)
    if haircolor == None:
        return None
    addr = common.read_string('Address', 50)
    if addr == None:
        return None

    while True:
        gender = common.read_string('Gender (m/f)')
        if gender == None:
            return None
        if gender == 'm' or gender == 'f':
            break
        print('Please select either \'m\' for male or \'f\' for female!')

    if gender == None:
        return None
    birthday = common.read_date('Birthday')
    if birthday == None:
        return None
    
    try:
        curs = conn.cursor()
        curs.bindarraysize = 1
        curs.setinputsizes(15,40,float,float,10,10,50,1,8)
        curs.executemany('insert into people values (:1,:2,:3,:4,:5,:6,:7,:8,to_date(:9,\'yyyymmdd\'))',
            [(sin,name,height,weight,eyecolor,haircolor,addr,gender,format_date(birthday))])
        curs.close()
        conn.commit()
        return True
    except cx_Oracle.DatabaseError as e:
        error, = e.args
        if error.code == 1:
            print('Error: A person with this social insurance number already exists!')
        else:
            print('Unknown error', error.code,'!')
        return False
Example #3
0
    def strcpy(self, proc, argv, ctx={}):
        """
        char *strcpy(
           char *strDestination,
           const char *strSource
        );
        """
        dest, src = argv
        s = common.read_string(proc.uc_eng, src)

        common.write_string(proc.uc_eng, s, dest)
        argv[1] = s
        return dest
Example #4
0
    def _putws(self, proc, argv, ctx={}):
        """
        int _putws(
           const wchar_t *str
        );
        """
        s, = argv
        string = common.read_string(s, 2, 20)
        argv[0] = string
        rv = len(string)

        # print(string)

        return rv
Example #5
0
 def strncpy(self, proc, argv, ctx={}):
     """
     char * strncpy(
         char * destination,
         const char * source,
         size_t num
     );
     """
     dest, src, length = argv
     s = common.read_string(proc.uc_eng, src, max_chars=length)
     if len(s) < length:
         s += '\x00' * (length - len(s))
     common.write_string(proc.uc_eng, s, dest)
     argv[1] = s
     return dest
Example #6
0
def read_string(data):
    return common.read_string(data)
Example #7
0
def add_ticket(conn):
	
    while True:
        print("Enter the SIN of the violator")
        violator_no = common.read_string('SIN', 15)
        if violator_no == None:
            return None
        if common.exists(conn, 'people', 'sin', violator_no):
            break
        print('A violator with this social insurance number does not exists!')
		
    while True:
        print("Enter the SIN of the Police Officer")
        office_no = common.read_string('SIN', 15)
        if office_no == None:
            return None
        if common.exists(conn, 'people', 'sin', office_no):
            break
        print('A police officer with this social insurance number does not exists!')

    while True:
        print("Enter the Vehicle ID of the automobile used by the violator")
        vehicle_id = common.read_string('serial_no', 15)
        if vehicle_id == None:
            return None
        if common.exists(conn, 'vehicle', 'serial_no', vehicle_id):
            break
        print('A vehicle with that serial number does not exist!')
        
    while True:
        vtype = find_string('Type',10)
        if vtype == None:
            return None
        if common.exists(conn, 'ticket_type', 'vtype', vtype):
            break
        print('The selected ticket type does not exists!')
        
    vdate = common.read_date('Date of violation')
    if vdate== None:
        return None
        
    descriptions = common.read_string('Descriptions', 1024)
    if descriptions == None:
        return None
        
    place = common.read_string('Place', 20)
    if place == None:
        return None
    
       
    ticket_no = common.latest_int_key(conn,'ticket','ticket_no')
    ticket_no = (ticket_no)+1
    
    try:
        curs = conn.cursor()
        curs.bindarraysize = 1
        curs.setinputsizes(int,15,15,15,10,8,20,1024)
        curs.executemany('insert into ticket values (:1,:2,:3,:4,:5,to_date(:6,\'yyyymmdd\'),:7,:8)',[(ticket_no,violator_no,vehicle_id,office_no,vtype,format_date(vdate),place,descriptions)])
        curs.execute('select * from ticket')
        curs.close()
        conn.commit()
        return True
        
    except cx_Oracle.DatabaseError as e:
        error, = e.args
        if error.code == 1:
            print('Error: A person with this social insurance number already exists!')
        else:
            print('Unknown error', error.code,'!')
        return False    
Example #8
0
    def read_songlist(executable_filename, songlist_offset, songlist_count,
                      file_entries):
        song_metadata = {}

        with open(executable_filename, "rb") as infile:
            infile.seek(songlist_offset)

            for i in range(songlist_count):
                infile.seek(songlist_offset + i * 0x9c, 0)

                internal_title_offset, title_offset = struct.unpack(
                    "<II", infile.read(8))

                internal_title = common.read_string(
                    infile, internal_title_offset - 0xfff80)
                title = common.read_string(infile, title_offset - 0xfff80)

                difficulties = struct.unpack("<BBBBBB", infile.read(6))

                if len(title) == 0:
                    title = "%d" % i

                infile.seek(0x06, 1)
                videos_idx = struct.unpack("<HH", infile.read(4))

                infile.seek(0x0c, 1)
                main_video_idx = struct.unpack("<I", infile.read(4))[0]

                infile.seek(0x08, 1)
                overlay_palette = struct.unpack("<H", infile.read(2))[0]

                infile.seek(0xc, 1)

                overlay_idxs = []

                for _ in range(0x16 // 4):
                    overlay_type, overlay_idx = struct.unpack(
                        "<HH", infile.read(4))

                    if overlay_type != 0:
                        overlay_idxs.append(overlay_idx)

                infile.seek(2, 1)

                charts_idx = struct.unpack("<IIIIIIII", infile.read(0x20))
                sounds_idx = struct.unpack("<HHHHHHHHHHHHHHHH",
                                           infile.read(0x20))
                overlay_idx = struct.unpack("<H", infile.read(0x02))[0]

                package_metadata = {
                    'song_id': i,
                    'title': title,
                    'title_ascii': internal_title,
                    'charts': {
                        'sp_beginner': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[4] if difficulties[4] != 0 else None,
                        },
                        'sp_normal': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[2] if difficulties[2] != 0 else None,
                        },
                        'sp_hyper': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'sp_another': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'dp_beginner': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[5] if difficulties[5] != 0 else None,
                        },
                        'dp_normal': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[3] if difficulties[3] != 0 else None,
                        },
                        'dp_hyper': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[1] if difficulties[1] != 0 else None,
                        },
                        'dp_another': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[1] if difficulties[1] != 0 else None,
                        },
                    },
                    'videos': [],
                    'overlays': None,
                }

                if main_video_idx != 0xffffffff:
                    if main_video_idx >= 116:
                        main_video_idx += 116

                    file_entries[main_video_idx]['entries'] = i
                    file_entries[main_video_idx]['references'].append({
                        'filename':
                        "%s.mpg" % (title),
                        'song_id':
                        i,
                        'title':
                        title
                    })

                    package_metadata['videos'].append("%s.mpg" % (title))

                for index, file_index in enumerate(videos_idx):
                    if file_index == 0xffff:
                        # Invalid
                        continue

                    for index2, file_index2 in enumerate(videos_idx):
                        if index2 != index and file_index2 == file_index:
                            index = index2
                            break

                    if file_index >= 116:
                        file_index += 116

                    file_entries[file_index]['entries'] = i
                    file_entries[file_index]['references'].append({
                        'filename':
                        "%s [%d].mpg" % (title, index),
                        'song_id':
                        i,
                        'title':
                        title
                    })

                    package_metadata['videos'].append("%s [%d].mpg" %
                                                      (title, index))

                if overlay_idx not in [0xffff, 0x00]:
                    if overlay_idx >= 116:
                        overlay_idx += 116

                    overlay_filename = "%s.if" % title
                    file_entries[overlay_idx]['overlays'] = {
                        'exe': executable_filename,
                        'palette': overlay_palette,
                        'indexes': overlay_idxs
                    }
                    file_entries[overlay_idx]['song_id'] = i
                    file_entries[overlay_idx]['title'] = title
                    file_entries[overlay_idx]['references'].append({
                        'filename':
                        overlay_filename,
                        'song_id':
                        i,
                        'title':
                        title
                    })

                    package_metadata['overlays'] = overlay_filename

                for index, file_index in enumerate(charts_idx):
                    if file_index == 0xffffffff or file_index == 0:
                        # Invalid
                        continue

                    file_index = (file_index & 0x0fffffff) + 116
                    file_entries[file_index]['compression'] = common.decode_lz
                    file_entries[file_index]['references'].append({
                        'filename':
                        "%s [%s].ply" %
                        (title, common.DIFFICULTY_MAPPING.get(
                            index, str(index))),
                        'song_id':
                        i,
                        'title':
                        title
                    })

                    package_metadata['charts'][common.DIFFICULTY_MAPPING.get(
                        index, str(index)).lower().replace(
                            " ", "_")]['filename'] = "%s [%s].ply" % (
                                title,
                                common.DIFFICULTY_MAPPING.get(
                                    index, str(index)))

                sound_pairs = [[sounds_idx[0], sounds_idx[2]],
                               [sounds_idx[1], sounds_idx[3]],
                               [sounds_idx[4], sounds_idx[6]],
                               [sounds_idx[5], sounds_idx[7]],
                               [sounds_idx[8], sounds_idx[10]],
                               [sounds_idx[9], sounds_idx[11]],
                               [sounds_idx[12], sounds_idx[14]],
                               [sounds_idx[13], sounds_idx[15]]]

                for pair_index, pair in enumerate(sound_pairs):
                    for index, file_index in enumerate(pair):
                        is_keysound = index == 0

                        if file_index == 0xffff:
                            # Invalid
                            continue

                        if file_index >= 116:
                            file_index += 116

                        for pair_index2, pair2 in enumerate(sound_pairs):
                            if pair_index2 != pair_index and pair2[1] == pair[
                                    0]:
                                pair_index = pair_index2
                                break

                        if is_keysound:
                            file_entries[file_index]['references'].append({
                                'filename':
                                "%s [%d].wvb" % (title, pair_index),
                                'song_id':
                                i,
                                'title':
                                title
                            })

                            package_metadata['charts'][
                                common.DIFFICULTY_MAPPING.get(
                                    pair_index,
                                    str(pair_index)).lower().replace(
                                        " ",
                                        "_")]['sounds'] = "%s [%d].wvb" % (
                                            title, pair_index)

                        else:
                            file_entries[file_index]['references'].append({
                                'filename':
                                "%s [%d].pcm" % (title, pair_index),
                                'song_id':
                                i,
                                'title':
                                title
                            })

                            package_metadata['charts'][
                                common.DIFFICULTY_MAPPING.get(
                                    pair_index,
                                    str(pair_index)).lower().replace(
                                        " ", "_")]['bgm'] = "%s [%d].pcm" % (
                                            title, pair_index)

                song_metadata[i] = package_metadata

        return file_entries, song_metadata
Example #9
0
    def read_songlist(executable_filename, songlist_offset, songlist_count,
                      file_entries):
        song_metadata = {}

        with open(executable_filename, "rb") as infile:
            chart_data_buffer = infile.read()

            infile.seek(songlist_offset)

            for i in range(songlist_count):
                infile.seek(songlist_offset + i * 0x90, 0)

                internal_title_offset, title_offset = struct.unpack(
                    "<II", infile.read(8))

                internal_title = common.read_string(
                    infile, internal_title_offset - 0xff000)
                title = common.read_string(infile, title_offset - 0xff000)

                infile.seek(0x01, 1)
                difficulties = struct.unpack("<BB", infile.read(2))

                if len(title) == 0:
                    title = "%d" % i

                infile.seek(0x03, 1)
                video_idx = struct.unpack("<H", infile.read(2))[0]
                videos_idx = [video_idx]

                if video_idx != 0xffff:
                    videos_idx.append(video_idx + 1)

                infile.seek(0x1c, 1)
                overlay_palette = struct.unpack("<H", infile.read(2))[0]

                infile.seek(0x0a, 1)
                overlay_idxs = []
                for _ in range(0x1e // 6):
                    overlay_type, overlay_idx, unk = struct.unpack(
                        "<HHH", infile.read(6))

                    if overlay_type != 0:
                        overlay_idxs.append(overlay_idx)

                infile.seek(0x02, 1)

                charts_idx = struct.unpack("<IIIIII", infile.read(0x18))
                sounds_idx = struct.unpack("<HHHHHHHHHHHH", infile.read(0x18))
                overlay_idx = struct.unpack("<H", infile.read(0x02))[0]

                package_metadata = {
                    'song_id': i,
                    'title': title,
                    'title_ascii': internal_title,
                    'charts': {
                        'sp_beginner': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[1] if difficulties[1] != 0 else None,
                        },
                        'sp_normal': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[1] if difficulties[1] != 0 else None,
                        },
                        'sp_hyper': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'sp_another': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'sp_black': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'dp_beginner': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[1] if difficulties[1] != 0 else None,
                        },
                        'dp_normal': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[1] if difficulties[1] != 0 else None,
                        },
                        'dp_hyper': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'dp_another': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                        'dp_black': {
                            'filename':
                            None,
                            'sounds':
                            None,
                            'bgm':
                            None,
                            'difficulty':
                            difficulties[0] if difficulties[0] != 0 else None,
                        },
                    },
                    'videos': [],
                    'overlays': None,
                }

                for index, file_index in enumerate(videos_idx):
                    if file_index == 0xffff:
                        # Invalid
                        continue

                    for index2, file_index2 in enumerate(videos_idx):
                        if index2 != index and file_index2 == file_index:
                            index = index2
                            break

                    file_entries[file_index]['entries'] = i
                    file_entries[file_index]['references'].append({
                        'filename':
                        "%s [%d].mpg" % (title, index),
                        'song_id':
                        i,
                        'title':
                        title
                    })

                    package_metadata['videos'].append("%s [%d].mpg" %
                                                      (title, index))

                if overlay_idx not in [0xffff, 0x00]:
                    overlay_filename = "%s.if" % title
                    file_entries[overlay_idx]['overlays'] = {
                        'exe': executable_filename,
                        'palette': overlay_palette,
                        'indexes': overlay_idxs
                    }
                    file_entries[overlay_idx]['song_id'] = i
                    file_entries[overlay_idx]['title'] = title
                    file_entries[overlay_idx]['references'].append({
                        'filename':
                        overlay_filename,
                        'song_id':
                        i,
                        'title':
                        title
                    })

                    package_metadata['overlays'] = overlay_filename

                for index, file_index in enumerate(charts_idx):
                    if file_index == 0xffffffff or file_index == 0:
                        # Invalid
                        continue

                    file_entries.append({
                        'filename':
                        executable_filename,
                        'offset':
                        file_index - 0xff000,
                        'size':
                        len(chart_data_buffer) - file_index - 0xff000,
                        'compression':
                        common.decode_lz,
                        'references': [{
                            'filename':
                            "%s [%s].ply" %
                            (title,
                             common.DIFFICULTY_MAPPING.get(index, str(index))),
                            'song_id':
                            i,
                            'title':
                            title
                        }]
                    })

                    package_metadata['charts'][common.DIFFICULTY_MAPPING.get(
                        index, str(index)).lower().replace(
                            " ", "_")]['filename'] = "%s [%s].ply" % (
                                title,
                                common.DIFFICULTY_MAPPING.get(
                                    index, str(index)))

                sound_pairs = [
                    [sounds_idx[0], sounds_idx[2]],
                    [sounds_idx[1], sounds_idx[3]],
                    [sounds_idx[4], sounds_idx[6]],
                    [sounds_idx[5], sounds_idx[7]],
                    [sounds_idx[8], sounds_idx[10]],
                    [sounds_idx[9], sounds_idx[11]],
                ]

                for pair_index, pair in enumerate(sound_pairs):
                    for index, file_index in enumerate(pair):
                        is_keysound = index == 0

                        if file_index == 0xffff:
                            # Invalid
                            continue

                        for pair_index2, pair2 in enumerate(sound_pairs):
                            if pair_index2 != pair_index and pair2[1] == pair[
                                    0]:
                                pair_index = pair_index2
                                break

                        if is_keysound:
                            file_entries[file_index]['references'].append({
                                'filename':
                                "%s [%d].wvb" % (title, pair_index),
                                'song_id':
                                i,
                                'title':
                                title
                            })

                            package_metadata['charts'][
                                common.DIFFICULTY_MAPPING.get(
                                    pair_index,
                                    str(pair_index)).lower().replace(
                                        " ",
                                        "_")]['sounds'] = "%s [%d].wvb" % (
                                            title, pair_index)

                        else:
                            file_entries[file_index]['references'].append({
                                'filename':
                                "%s [%d].pcm" % (title, pair_index),
                                'song_id':
                                i,
                                'title':
                                title
                            })

                            package_metadata['charts'][
                                common.DIFFICULTY_MAPPING.get(
                                    pair_index,
                                    str(pair_index)).lower().replace(
                                        " ", "_")]['bgm'] = "%s [%d].pcm" % (
                                            title, pair_index)

                song_metadata[i] = package_metadata

        return file_entries, song_metadata
Example #10
0
def add_owner(conn):
    
    while True:
        oid = common.read_string('Owner SIN', 15)
        if oid == None:
            return None
        if common.exists(conn, 'people', 'sin', oid):
            break
        print('The social insurance number does not exists!')
    
    while True:
        vid = common.read_string('Vehicle Serial Number', 15)
        if vid == None:
            return None
        if common.exists(conn, 'vehicle', 'serial_no', vid):
            break
        print('The serial number of the vehicle does not exists!')
    
    if not common.exists2(conn, 'owner', [('vehicle_id',vid),('is_primary_owner', 'y')]):
        print('This is the first owner of the selected vehicle and will automatically be set as primary.')
        powner = 'y'
        sys.stdin.readline()
    else:
        while True:
            powner = common.read_string('Primary Owner (y/n)')
            if powner == None:
                return None
            if powner == 'n':
                break
            if powner == 'y':
                if common.exists2(conn, 'owner', [('vehicle_id',vid),('is_primary_owner', 'y')]):
                    print('There is already a primary owner for the vehicle.')
                    while True:
                        change = common.read_string('Change primary owner (y/n)')
                        if change == None:
                            return None
                        if change == 'y':
                            break
                        if change == 'n':
                            powner == 'n'
                            break
                        print('Please select either \'y\' for yes or \'n\' for no!')
                break
            print('Please select either \'y\' for yes or \'n\' for no!')
    
    try:
        curs = conn.cursor()
        conn.begin()
        if powner == 'y':
            #curs.execute('begin update owner set is_primary_owner=\'n\' where vehicle_id=?; insert into owner values (?,?,?); end',(vid,oid,vid,powner))
            curs.execute('begin update owner set is_primary_owner=\'n\' where vehicle_id=\''+vid+'\'; insert into owner values (\''+oid+'\',\''+vid+'\',\''+powner+'\'); end;')
        else:
            curs.bindarraysize = 1
            curs.setinputsizes(15,15,1)
            curs.executemany('insert into owner values (:1,:2,:3)',
                [(oid,vid,powner)])
        curs.close()
        conn.commit()
        return True
    except cx_Oracle.DatabaseError as e:
        conn.rollback()
        error, = e.args
        if error.code == 1:
            print('Error: The selected person is already an owner of this vehicle!')
        else:
            print('Unknown error', error.code,'!')
        return False
Example #11
0
def register_licence(conn):
    
    while True:
        licenceno = common.read_string('Licence Number', 15)
        if licenceno == None:
            return None
        if not common.exists(conn, 'drive_licence', 'licence_no', licenceno):
            break
        print('The licence number already exists!')

    while True:
        sin = common.read_string('SIN', 15)
        if sin == None:
            return None
        if common.exists(conn, 'drive_licence', 'sin', sin):
            print('The selected person already has a licence!')
            continue
        if common.exists(conn, 'people', 'sin', sin):
            break
        print('No person with this social insurance number exists!')

    lclass = common.read_string('Class', 10)
    if lclass == None:
        return None

    while True:
        upload = common.read_string('Upload Picture (y/n)')
        if upload == None:
            return None
        if upload == 'y':
            break
        if upload == 'n':
            image_data = None
            break
        print('Please select either \'y\' for yes or \'n\' for no!')

    if upload == 'y':
        while True:
            fimage = common.read_string_exact('Picture File')
            if fimage == None:
                return None
            if not os.path.isfile(fimage):
                print('File not found!')
                continue
            try:
                pimage = open(fimage, 'rb')
                image_data = pimage.read()
                pimage.close()
                break
            except:
                print('Failed to read image file!')
                continue
    
    issuing_date = common.read_date('Issuing Date')
    if issuing_date == None:
        return None
    issuing_date = common.format_date(issuing_date)
    expiring_date = common.read_date('Expiring Date')
    if expiring_date == None:
        return None
    expiring_date = common.format_date(expiring_date)

    try:
        curs = conn.cursor()
        curs.bindarraysize = 1
        #curs.setinputsizes(15,15,cx_Oracle.LONG_BINARY,8,8)
        #curs.executemany('insert into drive_licence values (:1,:2,:3,:4,:5)',
        #    [(licenceno,sin,lclass,image_data,issuing_date,expiring_date)])
        curs.setinputsizes(15,15,10,cx_Oracle.LONG_BINARY,8,8)
        curs.executemany('insert into drive_licence values (:1,:2,:3,:4,to_date(:5,\'yyyymmdd\'),to_date(:6,\'yyyymmdd\'))',
            [(licenceno,sin,lclass,image_data,issuing_date,expiring_date)])
        curs.close()
        conn.commit()
        return True
    except cx_Oracle.DatabaseError as e:
        error, = e.args
        if type(error) == str:
            print('Unknown error', error,'!')
        elif error.code == 1:
            print('Error: The licence number already exists or the person already has a licence!')
        elif error.code == 2291:
            print('Error: No person with this social insurance number exists!')
        else:
            print('Unknown error', error.code,'!')
        return False