?? dvd-server,v
字號(hào):
head 1.6;
access;
symbols;
locks
cbbrowne:1.6; strict;
comment @# @;
1.6
date 2000.06.25.05.27.30; author cbbrowne; state Exp;
branches;
next 1.5;
1.5
date 2000.06.25.02.29.53; author cbbrowne; state Exp;
branches;
next 1.4;
1.4
date 2000.06.24.03.27.58; author cbbrowne; state Exp;
branches;
next 1.3;
1.3
date 2000.06.21.05.18.05; author cbbrowne; state Exp;
branches;
next 1.2;
1.2
date 2000.06.21.01.20.28; author cbbrowne; state Exp;
branches;
next 1.1;
1.1
date 2000.06.19.06.19.06; author cbbrowne; state Exp;
branches;
next ;
desc
@@
1.6
log
@Sundry updates...
@
text
@#!/usr/bin/env python
import CORBA, sys, regex, string, random, time, shelve, bsddb, os
from string import split, strip, joinfields
from random import randint
from time import localtime, strftime, time
### Connect Associative arrays to Files
SHDISKS=bsddb.btopen("disks.db", "c")
SHMEMBERS=bsddb.btopen("members.db", "c")
SHRENTALS=bsddb.btopen("rentals.db", "c")
SHRESERVATIONS=bsddb.btopen("reservations.db", "c")
SHTITLES=bsddb.btopen("titles.db", "c")
class SETUPCOUNTERS:
def maxforall(self):
self.maxfordisks()
self.maxformembers()
self.maxfortitles()
def maxfordisks(self):
if DBMAX.has_key("disks"):
max = DBMAX["disks"]
else:
max = 1
try:
i=SHDISKS.first()
while i != None:
iint = string.atoi(i)
if iint > max:
max=iint+1
i=SHDISKS.next(i)
except:
DBMAX["disks"] = max
def maxformembers(self):
if DBMAX.has_key("members"):
max = DBMAX["members"]
else:
max = 1
try:
i=SHMEMBERS.first()
while i != None:
iint = string.atoi(i)
if iint > max:
max=iint+1
i=SHMEMBERS.next(i)
except:
DBMAX["members"] = max
def maxfortitles(self):
if DBMAX.has_key("titles"):
max = DBMAX["titles"]
else:
max = 1
try:
i=SHTITLES.first()
while i != None:
iint = string.atoi(i)
if iint > max:
max=iint+1
i=SHTITLES.next(i)
except:
DBMAX["titles"] = max
### Now, for utilities...
def idtostring (id):
return "%d" % id
uname = os.uname()
hostname = uname[1]
def logit(type, info):
try:
LOGORB.addlog(LOG.loginfo(hostname=hostname,
userid="%d" % os.getuid(),
application="dvd-server",
messagetype=type,
shortmessage=info))
except:
print "logging server broken!"
### Initialization of non-ORB stuff...
FACTORYOBJECT = {}
DBMAX = {}
ERRNDICT = {
0 : "DVD_SUCCESS" ,
-1 : "DVD_ERR_NO_FILE" ,
-2 : "DVD_ERR_BAD_TABLE" ,
-3 : "DVD_ERR_NO_MEMBER_TABLE" ,
-4 : "DVD_ERR_BAD_MEMBER_TABLE",
-5 : "DVD_ERR_BAD_TITLE_TABLE" ,
-6 : "DVD_ERR_BAD_DISK_TABLE" ,
-7 : "DVD_ERR_BAD_SEEK" ,
-8 : "DVD_ERR_NULL_POINTER" ,
-9 : "DVD_ERR_BAD_WRITE" ,
-10 : "DVD_ERR_BAD_READ" ,
-11 : "DVD_ERR_NOT_FOUND" ,
-12 : "DVD_ERR_NO_MEMORY" ,
-13 : "DVD_ERR_BAD_RENTAL_TABLE" ,
-14 : "DVD_ERR_BAD_RESERVE_TABLE" }
ERRMSGDICT = {
"DVD_SUCCESS" : "no error",
"DVD_ERR_NO_FILE" : "cannot open file",
"DVD_ERR_BAD_TABLE" : "corrupt table file",
"DVD_ERR_NO_MEMBER_TABLE" : "no member table",
"DVD_ERR_BAD_MEMBER_TABLE" : "corrupt member table",
"DVD_ERR_BAD_TITLE_TABLE" : "corrupt title table",
"DVD_ERR_BAD_DISK_TABLE" : "corrupt disk table",
"DVD_ERR_BAD_RENTAL_TABLE" : "corrupt rental table",
"DVD_ERR_BAD_RESERVE_TABLE" : "corrupt reserve table",
"DVD_ERR_BAD_SEEK" : "cannot seek in file",
"DVD_ERR_NULL_POINTER" : "null data pointer",
"DVD_ERR_BAD_WRITE" : "cannot write to file",
"DVD_ERR_BAD_READ" : "cannot read file",
"DVD_ERR_NOT_FOUND" : "no match found",
"DVD_ERR_NO_MEMORY" : "out of memory"}
SETUP=SETUPCOUNTERS()
SETUP.maxforall()
class FACTORY:
def UTILITIESFactory(self):
try:
return FACTORYOBJECT["utilities"]
except:
logit("Factory", "Create Utility Interface")
new_instance = POA.DVD.UTILITIES(UTILITIES())
poa.activate_object(new_instance)
FACTORYOBJECT["utilities"] = poa.servant_to_reference(new_instance)
return FACTORYOBJECT["utilities"]
def MEMBERSHIPFactory(self):
try:
return FACTORYOBJECT["membership"]
except:
logit("Factory", "Create Membership Interface")
new_instance = POA.DVD.MEMBERSHIP(MEMBERSHIP())
poa.activate_object(new_instance)
FACTORYOBJECT["membership"] = poa.servant_to_reference(new_instance)
return FACTORYOBJECT["membership"]
def TITLINGFactory(self):
try:
return FACTORYOBJECT["titling"]
except:
logit("Factory", "Create Titling Interface")
new_instance = POA.DVD.TITLING(TITLING())
poa.activate_object(new_instance)
FACTORYOBJECT["titling"] = poa.servant_to_reference(new_instance)
return FACTORYOBJECT["titling"]
def DISKSFactory(self):
try:
return FACTORYOBJECT["disks"]
except:
logit("Factory", "Create Disks Interface")
new_instance = POA.DVD.DISKS(DISKS())
poa.activate_object(new_instance)
FACTORYOBJECT["disks"] = poa.servant_to_reference(new_instance)
return FACTORYOBJECT["disks"]
def RENTALFactory(self):
try:
return FACTORYOBJECT["rentals"]
except:
logit("Factory", "Create Rental Interface")
new_instance = POA.DVD.RENTAL(RENTAL())
poa.activate_object(new_instance)
FACTORYOBJECT["rentals"] = poa.servant_to_reference(new_instance)
return FACTORYOBJECT["rentals"]
def RESERVATIONSFactory(self):
try:
return FACTORYOBJECT["reservations"]
except:
logit("Factory", "Create Reservations Interface")
new_instance = POA.DVD.RESERVATIONS(RESERVATIONS())
poa.activate_object(new_instance)
FACTORYOBJECT["reservations"] = poa.servant_to_reference(new_instance)
return FACTORYOBJECT["reservations"]
### Functions to pack/unpack the DBM file information
def destringizereservationinfo(sres):
rout=DVD.RESERVATIONS.reservation
(mbr, ttl, dd)=string.split(sres, "\\")
rout.memberid=string.atoi(mbr)
rout.titleid=string.atoi(ttl)
rout.due=dd
return rout
def stringizereservation(res):
return string.join(("%d"%res.memberid, "%d"%res.titleid, res.due), "\\")
def destringizerentinfo(srental):
rout=DVD.RENTAL.rentinfo
(dsk, mbr, dd) = string.split(srental, "\\")
rout.diskid=string.atoi(dsk)
rout.memberid=string.atoi(mbr)
rout.due=dd
return rout
def stringizerentinfo(rrec):
return string.join(("%d"%rrec.diskid, "%d"%rrec.memberid, rrec.due), "\\")
def destringizedisk(sdisk):
disk=DVD.DISKS.dvddisks()
(sd, st) = string.split(sdisk, "\\")
disk.diskid = string.atoi(sd)
disk.titleid = string.atoi(st)
return disk
def stringizedisk(disk):
return string.join(("%d"%disk.diskid, "%d"%disk.titleid), "\\")
def stringizetitle(title):
return string.join(("%d" % title.titleid, title.titletext, title.asin, title.director, title.genre, title.classification, title.actor1, title.actor2, title.releasedate, title.rentalcost, title.image), "\\")
def destringizetitle(stitle):
title=DVD.TITLING.dvdtitles()
(mttl, title.titletext, title.asin, title.director, title.genre, title.classification, title.actor1, title.actor2, title.releasedate, title.rentalcost, title.image) = string.split(stitle, "\\")
title.titleid=string.atoi(mttl)
return title
def stringizemember(member):
return string.join(("%d" % member.memberid, member.memberno,
member.title, member.fname, member.lname,
member.houseflatref, member.address1,
member.address2, member.town, member.state,
member.phone, member.zipcode), "\\")
def destringizemember(smember):
member=DVD.MEMBERSHIP.storemembers()
(mid, member.memberno, member.title, member.fname, member.lname,
member.houseflatref, member.address1, member.address2,
member.town, member.state, member.phone, member.zipcode) = string.split(smember, "\\")
member.memberid=string.atoi(mid)
return member
class MEMBERSHIP:
def set (self, recordtoupdate):
logit("Membership", "Set contents for %d" %
recordtoupdate.memberid)
SHMEMBERS[idtostring(recordtoupdate.memberid)]= stringizemember(recordtoupdate)
SHMEMBERS.sync()
def get (self, memberid):
try:
record=SHMEMBERS[idtostring(memberid)]
except:
logit("Membership", "Failure of get() contents for member %d" % memberid)
print "Couldn't get member", memberid
raise DVD.MEMBERSHIP.NOSUCHMEMBER
logit("Membership", "Success of get() contents for member %d"
% memberid)
return destringizemember(record)
def delete (self, memberid):
try:
del SHMEMBERS[idtostring(memberid)]
logit("Membership", "delete contents for %d" % memberid)
SHMEMBERS.sync()
except:
raise DVD.MEMBERSHIP.NOSUCHMEMBER
def create (self, recordtoadd):
lastid = DBMAX["members"]
lastid = lastid + 1
logit("Membership", "Create new member record - %d" % lastid)
DBMAX["members"] = lastid
recordtoadd.memberid = lastid
recordtoadd.memberno = "%d" % lastid
SHMEMBERS[idtostring(lastid)]=stringizemember(recordtoadd)
SHMEMBERS.sync()
logit("Membership", "Create new member for %d" % lastid)
return lastid
def search (self, lname):
rseq = []
try:
(key,value)=SHMEMBERS.first()
while 1 == 1:
lst=string.split(value, "\\")
surname=lst[4]
if string.upper(surname) == string.upper(lname):
rseq.append (string.atoi(key))
(key,value)=SHMEMBERS.next()
except:
done = ""
logit("Membership", "Search for %s" % lname)
rseq.sort()
return rseq
def idfromnumber (self, memberno):
logit("Membership", "id-to-number for %s" % memberno)
try:
(key,value)=SHMEMBERS.first()
while 1 == 1:
lst = string.split(value, "\\")
no = lst[1]
if no == memberno:
return string.atoi(key)
(key,value) = SHMEMBERS.next()
except:
raise DVD.MEMBERSHIP.NOSUCHMEMBER
class TITLING:
def set (self, recordtoupdate):
try:
SHTITLES[idtostring(recordtoupdate.titleid)]= stringizetitle(recordtoupdate)
SHTITLES.sync()
except:
logit("TITLING", "Failure of set() contents for title %d"
% recordtoupdate.titleid)
logit("TITLING", "Success of set() contents for title %d" %
recordtoupdate.titleid)
def get (self, titleid):
try:
record=SHTITLES[idtostring(titleid)]
except:
logit("TITLING", "failure of get() contents for title %d"
% titleid)
raise DVD.TITLING.NOSUCHTITLE
logit("TITLING", "Success of get() contents for title %d" % titleid)
return destringizetitle(record)
def delete (self, titleid):
try:
del SHTITLES[idtostring(titleid)]
SHTITLES.sync()
logit("Titling", "delete contents for %d" % titleid)
except:
raise DVD.TITLING.NOSUCHTITLE
def create (self, recordtoadd):
lastid = DBMAX["titles"]
lastid = lastid + 1
logit("Titling", "Create new title record - %d" % lastid)
DBMAX["titles"] = lastid
recordtoadd.memberid = lastid
SHTITLES[idtostring(lastid)]=stringizetitle(recordtoadd)
SHTITLES.sync()
return lastid
def search (self, title, name):
rseq = []
try:
(key,value)=SHTITLES.first()
while 1 == 1:
lst=string.split(value, "\\")
titletext=lst[1]
director=lst[3]
actor1=lst[6]
actor2=lst[7]
keep="NO"
if string.upper(director) == string.upper(name):
keep = "YES"
if string.upper(actor1) == string.upper(name):
keep = "YES"
if string.upper(actor2) == string.upper(name):
keep = "YES"
if string.upper(titletext) == string.upper(title):
keep = "YES"
if keep == "YES":
rseq.append (string.atoi(key))
(key,value)=SHTITLES.next()
except:
done = ""
logit("Titling", "Search for %s" % title)
#rseq.sort(lambda x, y: x-y)
rseq.sort()
return rseq
class DISKS:
def set (self, recordtoupdate):
try:
SHDISKS[idtostring(recordtoupdate.diskid)]= stringizedisk(recordtoupdate)
SHDISKS.sync()
except:
logit("DISKS", "Failure to set %d" % recordtoupdate.diskid)
logit("DISKS", "Success of set() contents for disk %d" % recordtoupdate.diskid)
def get (self, diskid):
try:
record=SHDISKS[idtostring(diskid)]
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -