示例#1
0
                    """
            t.getKey(tup[0], tally[1] - 1)
    except IndexError:
        """The tally was previously rolled back, and so
           does not need to be rolled back this time.
        """


try:
    filename = sys.argv[1]
except:
    filename = "easy.txt"

basename = os.path.splitext(os.path.basename(filename))[0]

db = crusher.Broker(basename)
clean(db)
cmd = open(filename, "r")
log = open(basename + "-votelog.txt", "w")
context = {}

for line in cmd:
    if line[-1] == "\n":
        line = line[:-1]
    line = line.split("\t")
    if commands[line[0]](db, context, log, line):
        break

cmd.close()
log.close()
results = open(basename + "-results.txt", "w")
示例#2
0
        # line = str(keys) + "\t" + str(tallies[keys]) + "\n"
        # line = str(final[keys]) + "\n"

    for keys in final:
        line = "TALLY" + "\t" + str(keys[0]) + "\t" + str(
            keys[1]) + "\t" + str(final[keys]) + "\n"
        reportFile.write(line)


## File read implementation
try:
    fileName = sys.argv[1]
except:
    fileName = "bigeasy.txt"

db = crusher.Broker(fileName)

votesFile = open(fileName, "r")
logFile = open(fileName[:-4] + "-votelog.txt", "w")
resultFile = open(fileName[:-4] + "-results.txt", "w")

tempVotes = []
for line in votesFile:
    #print(line.split()[0])
    line = line.strip()
    COMMANDS[line.split()[0]](db, tempVotes, line.split("\t"), logFile)

report(db, resultFile)
resultFile.close()
votesFile.close()
logFile.close()
示例#3
0
        for i in range(self.__len__()):
            vprint(2, '  []iter::i:', i)
            try:
                n = self.safeFetch(entryName(self.name, i))
            except:
                n = None
            vprint(2, '  []iter::n:', i)
            yield n


if __name__ == "__main__":
    import crusher
    import crusher3
    crusher.Cache = crusher3.Cache  # Add function
    crusher.DataBase = crusher3.DataBase  # Add function

    db = crusher.Broker("test_crusherdict")
    test2 = CrusherDict(db, "dict_nameA")
    test3 = CrusherDict(db, "dict_nameB")
    test4 = CrusherDict(db, "dict_nameC")

    for i in range(0, 1000):
        test2.safeStore('x', '99999')
        vprint(0, test2.safeFetch('x'))
    try:
        for tup in test2:
            vprint(0, tup)
    except:
        pass
    db.exit()
示例#4
0
            self.db.remove((key,i))
        return self.db.remove(key)
    def exit(self):
        """Persist the database in preparation to exit."""
        self.db.exit()

if __name__ == "__main__":
    import crusher
    import signal

    key=("hello","world")
    val=("by","jove")
    keystr="{}".format(key)
    
    """Create a Crusher."""
    cache=Wrapper(crusher.Broker("test_replayer"))
    
    """Store a simple key-value pair."""
    cache.store("h","v")
    
    """Store a more complex key-value pair."""
    cache.store(key,val)
    
    """Store using a key that contains a wide variety of data types."""
    cache.store(("test","m",12,-76,7.234,-8.763,10004.3422,(123,"h")),"test")
    
    try:
        """Try retrieving using the complex key."""
        print(cache.fetch(key))
    except KeyError as error:
        """It should work, but could give an error if the complex key was
示例#5
0
		else:
			# Raise checksum error is it does not match.
			# TO_DO: Again try more selections and checksum comparision
			return mostCommonFromSelection

	def __CompareChecksumWithSelection__(self, selection, checksum):
		# Will take two parameters (selection, checksum) and compare it to 
		# return boolean value. 
		if(self.__insertChecksum__(selection) == checksum):
			return True
		else:
			return False
	

if __name__ == "__main__":
	db = crusher.Broker("testDict.txt")
	db.configure("(0,0,0,0,0,0)")
	#db.configure("((1,2,3,4,5,6,7,8))")

	test = Dict(db, "test")
	key = [1, "o"]
	value = "Governor"
	test.insert(key, value)
	try:
		print(test.select(key)) # will need to except unicodeecode error in voting.py
	except UnicodeEncodeError:
		pass
	except ChecksumDoesNotMatchError:
		pass
	db.exit()
	
示例#6
0
文件: demo3-2.py 项目: csc456/test
        log.write(best)
    except:
        vprint(1, '  Exception:', sys.exc_info()[0])
        vprint(1, '  report::vote-log3 ...')


try:
    filename = sys.argv[1]
except:
    filename = "easy.txt"

basename = os.path.splitext(os.path.basename(filename))[0]

dbs = []
for i in range(1):
    dbs.append(crusher.Broker(basename + '_db' + str(i)))
# dbs.append(crusher.Broker(basename+'__db'+str(i)+'__'))

#db=crusher.Broker(basename)
log = open(basename + "-votelog.txt", "w")
cmd = open(filename, "r")
context = {}

for line in cmd:
    if line[-1] == "\n":
        line = line[:-1]
    line = line.split("\t")
    vprint(0, 'demo.py: Try cmd:' + line[0])
    if commands[line[0]](dbs, context, log, line):
        break