예제 #1
0
 def __init__(self, db_file):
     self.db = Database(db_file)
     self.rwlock = ReadWriteLock()
예제 #2
0
                    dest="fortune",
                    help="Write a new fortune to the database.")
parser.add_argument("-i",
                    "--interactive",
                    action="store_true",
                    dest="interactive",
                    default=False,
                    help="Interactive session with the fortune database.")
opts = parser.parse_args()

# -----------------------------------------------------------------------------
# The main program
# -----------------------------------------------------------------------------

# Create the database object
db = Database("dbs/fortune.db")

if not opts.interactive:
    # Run in the normal mode
    if opts.fortune is not None:
        db.write(opts.fortune)
    else:
        print(db.read())

else:
    # Run in the interactive mode
    def menu():
        print("""\
Choose one of the following commands:
    r            ::  read a random fortune from the database,
    w <FORTUNE>  ::  write a new fortune into the database,