Exemplo n.º 1
0
    def open(self):
        #  If .db files exist, read them. If not, create them.
        if os.path.isfile('data/City.db') and os.path.isfile(
                'data/Country.db'):
            print 'The pipeline has been opened!'
            self.city = MainBody.fakeopen('data/City.db')
            self.country = MainBody.fakeopen('data/Country.db')

        else:
            print "Have to create db files! Don't panic!"
            print "The pipeline has been opened!"
            self.city = MainBody.fakeopen('data/City.db')
            self.country = MainBody.fakeopen('data/Country.db')
            city_handle = open(self.city_path, 'r')
            country_handle = open(self.country_path, 'r')
            for city in city_handle:
                elm_list = city.split('\t')
                try:
                    self.city[elm_list[2]].append(elm_list)
                except:
                    self.city[elm_list[2]] = [elm_list]

            for country in country_handle:
                elm_list = country.split('\t')
                self.country[elm_list[0]] = elm_list

            self.country.sync()
            self.city.sync()
Exemplo n.º 2
0
 def Get(self, key):
     self.db = MainBody.fakeopen(self.filename)
     key = str(key)
     try:
         # Meta data
         return self.db[key]
     finally:
         self.db.sync()
Exemplo n.º 3
0
 def Remove(self, key):
     self.db = MainBody.fakeopen(self.filename)
     key = str(key)
     try:
         print self.db.keys()
         if key not in self.db.keys():
             raise LookupError
         del self.db[key]
     except LookupError:
         print "Error: there is no %s exist" %key
     self.db.sync()
Exemplo n.º 4
0
 def Put(self, key, data):
     self.db = MainBody.fakeopen(self.filename)
     key = str(key)
     self.db[key] = data
     if key in self.db.keys():
         # print str(key) + " in db"
         print "show db keys after PUT " + key + " " +str(self.db.keys())
     else:
         print str(key) + " not in db"
         return
     self.db.sync()
Exemplo n.º 5
0
 def __init__(self, filename):
     self.filename = filename
     self.getdb = MainBody.fakeopen(self.filename)
Exemplo n.º 6
0
import MainBody
import concurracy
from timeit import Timer

test = MainBody.fakeopen('cs542.db')
print 'Puting "A" in'
print 'Size: 1048000 Bytes'
test['A'] = bytearray(1048000)
test.sync()
print 'Puting "B" in'
print 'Size: 1048000 Bytes'
test['B'] = bytearray(1048000)
test.sync()
print 'Puting "C" in'
print 'Size: 1048000 Bytes'
test['C'] = bytearray(1048000)
test.sync()
print 'Puting "D" in'
print 'Size: 1048000 Bytes'
test['D'] = bytearray(1048000)
test.sync()
print 'Deleting "B"'
del test['B']
print 'Puting "E" in'
print 'Size: 1048000/2 Bytes'
test['E'] = bytearray(1048000 / 2)
print 'Puting "F" in'
print 'Size: 1048000 Bytes'
test['F'] = bytearray(1048000)
test.sync()
del test['C']
Exemplo n.º 7
0
import MainBody
import concurracy
from timeit import Timer

test = MainBody.fakeopen('cs542.db')
print 'Puting "A" in'
print 'Size: 1048000 Bytes'
test['A'] = bytearray(1048000)
test.sync()
print 'Puting "B" in'
print 'Size: 1048000 Bytes'
test['B'] = bytearray(1048000)
test.sync()
print 'Puting "C" in'
print 'Size: 1048000 Bytes'
test['C'] = bytearray(1048000)
test.sync()
print 'Puting "D" in'
print 'Size: 1048000 Bytes'
test['D'] = bytearray(1048000)
test.sync()
print 'Deleting "B"'
del test['B']
print 'Puting "E" in'
print 'Size: 1048000/2 Bytes'
test['E'] = bytearray(1048000/2)
print 'Puting "F" in'
print 'Size: 1048000 Bytes'
test['F'] = bytearray(1048000)
test.sync()
del test['C']
Exemplo n.º 8
0
import MainBody
from timeit import Timer

test = MainBody.fakeopen('Test01.db')
print 'Puting "A" in'
print 'Size: 1048000 Bytes'
test['A'] = bytearray(1048000)
test.sync()
print 'Puting "B" in'
print 'Size: 1048000 Bytes'
test['B'] = bytearray(1048000)
test.sync()
print 'Puting "C" in'
print 'Size: 1048000 Bytes'
test['C'] = bytearray(1048000)
test.sync()
print 'Puting "D" in'
print 'Size: 1048000 Bytes'
test['D'] = bytearray(1048000)
test.sync()
print 'Deleting "B"'
del test['B']
print 'Puting "E" in'
print 'Size: 1048000/2 Bytes'
test['E'] = bytearray(1048000 / 2)
print 'Puting "F" in'
print 'Size: 1048000 Bytes'
test['F'] = bytearray(1048000)
test.sync()
del test['C']
print 'Deleting "C"'
Exemplo n.º 9
0
 def __init__(self, testing):
     super().__init__()
     self.setupUi(self)
     self.backk = MainBody.MainWindow(self)
     self.pushButton_1.pressed.connect(self.exitt)
     self.showScore(testing)
Exemplo n.º 10
0
 def __init__(self, filename):
     self.filename = filename
     self.db = MainBody.open(self.filename)
     self.lock = Lock()