Exemplo n.º 1
0
 def write_local_dbf_by_del(self, records):
     for record in records:
         if self.get_comp_result(record) != 1:
             dbf.delete(record)
     records.pack()
     select_records = len(records)
     records.close()
     self.log.debug('task%s:%s write %s.dbf success' %
                    (self.id, self.fileid, self.id))
     return select_records
Exemplo n.º 2
0
    def deletefromupdate(self):
        logging.info('Deleting info abount updates')
        table = dbf.Table(self.pathtodbf + '/1SUPDTS.DBF')
        with table.open(mode=dbf.READ_WRITE):
            for record in table:
                if record['dbsign'] == dbsign:
                    if record['typeid'] in self.objects:
                        if record['objid'].rstrip() in self.objects[
                                record['typeid']]:
                            dbf.delete(record)

            table.pack()
        logging.info('Deleting info abount updates - done')
Exemplo n.º 3
0
    def deletefromupdate(self):
        logging.info('Deleting info abount updates')
        filename = os.path.join(self.pathtodbf, '1SUPDTS.DBF')
        indexfile = os.path.join(self.pathtodbf, '1SUPDTS.CDX')
        table = dbf.Table(filename)
        with table.open(mode=dbf.READ_WRITE):
            for record in table:
                if record['dbsign'] == dbsign:
                    if record['typeid'] in self.objects:
                        if record['objid'].rstrip() in self.objects[
                                record['typeid']]:
                            dbf.delete(record)

            table.pack()
        if os.path.exists(indexfile):
            os.remove(indexfile)
        logging.info('Deleting info abount updates - done')
Exemplo n.º 4
0
 def write_local_dbf_by_append(self, data_list):
     new_records = data_list
     # if not new_records: return False
     tmp_dbf = os.path.abspath('tmp/%s.dbf' % self.id)
     if not os.path.exists('tmp'): os.mkdir('tmp')
     try:
         modelpath = os.path.abspath('dbfmodel/%s' %
                                     os.path.basename(self.filefrom))
         # 部分文件不是.dbf结尾,必须先转换成.dbf才能读写
         if not os.path.exists('dbfmodel'): os.mkdir('dbfmodel')
         if '.DBF' not in modelpath.upper(): modelpath += '.DBF'
         self.log.debug('task%s:modelpath:%s' % (self.id, modelpath))
         if 'Y' in self.config.get('newmodel', 'no').upper():
             os.remove(modelpath)
         if os.path.exists(modelpath):
             shutil.copy(modelpath, tmp_dbf)
         else:
             # 要删除,此为创建模板用
             shutil.copy(self.filefrom, modelpath)
             records = dbf.Table(modelpath)
             records.open()
             for record in records:
                 dbf.delete(record)
             records.pack()
             records.close()
             shutil.copy(modelpath, tmp_dbf)
     except:
         self.log.trace()
         self.log.error('[%s] %s copy %s to dbfmodel fail:%s' %
                        (self.id, self.fileid, self.filefrom, modelpath))
     if not os.path.exists(tmp_dbf):
         self.log.error('[%s] %s copy %s to tmp_dbf fail:%s.dbf' %
                        (self.id, self.fileid, self.filefrom, self.id))
         return False
     records = dbf.Table(tmp_dbf)
     records.open()
     if records:
         for record in records:
             dbf.delete(record)
         records.pack()
     for record in new_records:
         records.append(record)
     records.close()
     self.log.debug('[%s] %s write %s.dbf success' %
                    (self.id, self.fileid, self.id))
     return True
Exemplo n.º 5
0
mlist_tmp.open()

for x in mlist_tmp:
    for y in tbl:
        if x['fmod_list'].strip() == y[0]:
            dbf.write(x, fmod_list='%06d' % int(y[1]))
            break
for x in mlist_tmp:
    for y in tbl:
        if x['fsub_list'].strip() == y[0]:
            dbf.write(x, fsub_list='%06d' % int(y[1]))
            break
#filter out undefined (didnt replaced) record in dbf
for x in mlist_tmp:
    if len(x['fmod_list'].strip()) == 3:
        dbf.delete(x)
        continue
    if len(x['fmod_num'].strip()) == 3:
        dbf.delete(x)
        continue
    if len(x['fsub_list'].strip()) == 3:
        dbf.delete(x)
#pack the dbf
mlist_tmp.pack()
mlist_tmp.close()
###################################################################

menu = dbf.Table('./origin/menu.dbf')
menu.open()
menu.codepage = dbf.CodePage('cp936')
men = []
Exemplo n.º 6
0
lookup_db = dbf.Table('./imenu/modilist.dbf')
lookup_db.open()


def indexer(record):
    if record.fnew_list != 'm':
        return dbf.DoNotIndex
    return record.fnew_list


while 1:
    index = lookup_db.create_index(indexer)
    lookup = []
    for rec in index:
        lookup.append((rec.fmod_list, rec.fsub_list))
        dbf.delete(rec)
    if lookup == []: break
    temp = []
    for sub_list in lookup:
        #		idx = lookup_db.create_index(lambda rec: rec.fmod_list)
        #		seq = idx.search(match=sub_list[0])
        #		tmp = []
        #		for len in seq:
        #			tmp.append(len.fseq)
        #		upper = int(max(tmp)) + 1
        id = lookup_db.create_index(lambda rec: rec.fmod_list)
        flag = id.search(match=sub_list[1])
        for x in flag:
            temp.append(('',\
             sub_list[0],\
             x.fnew_list,\
Exemplo n.º 7
0
# print('ok')
# print(type(sjsfw[0]))
# print(sjsfw[1].fwgddm)
# nd_index = table.create_index(lambda rec: (rec.name, rec.desc))
mydata = dbf.pql(sjsfw, "select * where fwgddm=='0050851437'")
# mydata = sjsfw.query("select * where fwgddm=='0050851437'")
mylist = [rec for rec in sjsfw if rec['fwjsdm'] == '0050851437']
print(mydata[0])
print(mylist[0])
import shutil

shutil.copy('sjsfw.dbf', 'sjsfw_1.dbf')
sjsfw = dbf.Table('sjsfw_1.dbf')
sjsfw.open()
for table in sjsfw:
    dbf.delete(table)
sjsfw.pack()
sjsfw.close()

"create a dbf and vfp table"
# dbf_table = dbf.Table(
#     'temptable_1',
#     'name C(30); age N(3,0); birth D' , dbf_type='db3'
#     )
# dbf_table.open()
# # t1= time.clock()
# # print(t1)
# for i in range(1000):
#     for datum in (
#             ('John Doe', 31, dbf.Date(1979, 9,13)),
#             ('Ethan Furman', 102, dbf.Date(1909, 4, 1)),