### Python modules ### from datetime import datetime import os import pickle import time ### User Modules ### import db import login import my_logger ### Logging ### logger = my_logger.create_logger(__name__) class Tools(): """ Class that holds the information for the tools inventory and provides methods to interact with the information. """ def __init__(self): # Stores the checked out equipment to a given username in the form: # {user: [timestamp, bldg, items]} db.update_db() self._state_file = os.path.join(*'resources state.pickle'.split()) self.transactions = self._load_transactions() ### Private Functions ### def _make_timestamp(self): """ Gets the current time as a timestamp.
import shelve from datetime import datetime from time import mktime ### User Modules ### import my_logger ### Globals ### RSC_D = 'resources' DB_F = os.path.join(RSC_D, 'tools') FILES = ('tools', 'keys') DAT_FILE = os.path.join(RSC_D, '%s.dat') ### Logging ### logger = my_logger.create_logger(__name__) ### Public Functions ### def update_db(): """ Populates the tools database with the inventory read from the .dat file. """ logger.debug("Entered") if not os.path.exists(DB_F): logger.debug("No tools database") for f in FILES: with open(DAT_FILE % f, 'r') as temp: check_items(map(str.strip, temp.read().split()))