def initializeRoomBookingDB(location, force=False): """ Modifies Indico main database. - location list Creates necessary branches in room booking database. - rooms branch - bookings branch - several indexes """ indicoRoot = MaKaC.common.DBMgr.getInstance().getDBConnection().root() root = DALManagerCERN().getRoot() # 1. Location ----------------------------------------------------------- initialLocation = Location(location, FactoryCERN) if force or not indicoRoot.has_key('RoomBookingLocationList'): indicoRoot['RoomBookingLocationList'] = [initialLocation] if force or not indicoRoot.has_key('DefaultRoomBookingLocation'): indicoRoot['DefaultRoomBookingLocation'] = location # 2. Rooms & Bookings --------------------------------------------------- # Create rooms branch if force or not root.has_key('Rooms'): root['Rooms'] = IOBTree() # Create reservations branch if force or not root.has_key('Reservations'): root['Reservations'] = IOBTree() # Create blocking branch if force or not root.has_key('RoomBlocking'): root['RoomBlocking'] = OOBTree() root['RoomBlocking']['Blockings'] = IOBTree() root['RoomBlocking']['Indexes'] = OOBTree() root['RoomBlocking']['Indexes']['OwnerBlockings'] = OOBTree() root['RoomBlocking']['Indexes']['DayBlockings'] = CalendarDayIndex() root['RoomBlocking']['Indexes']['RoomBlockings'] = OOBTree() # Create indexes if force or not root.has_key('RoomReservationsIndex'): root['RoomReservationsIndex'] = OOBTree() if force or not root.has_key('UserReservationsIndex'): root['UserReservationsIndex'] = OOBTree() if force or not root.has_key('DayReservationsIndex'): root['DayReservationsIndex'] = OOBTree() if force or not root.has_key('RoomDayReservationsIndex'): root['RoomDayReservationsIndex'] = OOBTree() # Create possible equipment branch if force or not root.has_key('EquipmentList'): root['EquipmentList'] = {} # update Catalog with new rb indexes Catalog.updateDB() DALManagerCERN().commit()
def initializeRoomBookingDB(location, force=False): """ Modifies Indico main database. - location list Creates necessary branches in room booking database. - rooms branch - bookings branch - several indexes """ indicoRoot = MaKaC.common.DBMgr.getInstance().getDBConnection().root() root = DALManagerCERN().root # 1. Location ----------------------------------------------------------- initialLocation = Location(location, FactoryCERN) if force or not indicoRoot.has_key('RoomBookingLocationList'): indicoRoot['RoomBookingLocationList'] = [initialLocation] print "Locations branch created (Indico db)" if force or not indicoRoot.has_key('DefaultRoomBookingLocation'): indicoRoot['DefaultRoomBookingLocation'] = location print "Default location set to " + location # 2. Rooms & Bookings --------------------------------------------------- # Create rooms branch if force or not root.has_key('Rooms'): root['Rooms'] = IOBTree() print "Rooms branch created" # Create reservations branch if force or not root.has_key('Reservations'): root['Reservations'] = IOBTree() print "Reservations branch created" # Create indexes if force or not root.has_key('RoomReservationsIndex'): root['RoomReservationsIndex'] = OOBTree() print "Room => Reservations Index branch created" if force or not root.has_key('UserReservationsIndex'): root['UserReservationsIndex'] = OOBTree() print "User => Reservations Index branch created" if force or not root.has_key('DayReservationsIndex'): root['DayReservationsIndex'] = OOBTree() print "Day => Reservations Index branch created" # Create possible equipment branch if force or not root.has_key('EquipmentList'): root['EquipmentList'] = {} print "Equipment branch created" AvatarHolder().invalidateRoomManagerIdList() print "Cached list of room managers invalidated" DALManagerCERN().commit()
def deleteRoomBookingBranches(force=False): """ !!! REMOVES DATA !!! Deletes all branches related to room booking, from both main and room booking databases. """ if not force: raise Exception('nothing done') indicoRoot = MaKaC.common.DBMgr.getInstance().getDBConnection().root() root = DALManagerCERN().getRoot() minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() # 1. INDICO ----------------------------------------- minfo.setRoomBookingModuleActive(False) if indicoRoot.get('RoomBookingLocationList'): del indicoRoot['RoomBookingLocationList'] if indicoRoot.get('DefaultRoomBookingLocation'): del indicoRoot['DefaultRoomBookingLocation'] # 2. ROOM BOOKING ------------------------------------ if root.get('Rooms'): del root['Rooms'] if root.get('Reservations'): del root['Reservations'] if root.get('RoomBlocking'): del root['RoomBlocking'] # Create indexes if root.get('RoomReservationsIndex'): del root['RoomReservationsIndex'] if root.get('UserReservationsIndex'): del root['UserReservationsIndex'] # Create possible equipment branch if root.get('EquipmentList'): del root['EquipmentList'] DALManagerCERN().commit()