#!/usr/local/bin/python
import sys,os,string,regex,regsub,time
import pgext
from HTMLgen import *
# Other constants...
#
NO = FALSE = 0
YES = TRUE = 1
text_bar = 60* "-"
RED = "#993300"
GREEN = "#336600"
BLACK = "#000000"
WHITE = "#FFFFFF"
LIGHT_GREY = "#E7E7E7"
GREY = "#C0C0C0"
DARK_GREY = "#6F6F6F"
# ====================================================================================================
# Define directories where things come from and go to...
#
in_base_dir = "/home/kevan/computer_collection"
in_picture_dir = os.path.join(in_base_dir,"pictures")
in_html_dir = os.path.join(in_base_dir,"html")
base_url = "/kevan"
base_dir = "/home/kevan/public_html"
base_url_collection = os.path.join (base_url,"collection")
base_dir_collection = os.path.join (base_dir,"collection")
base_url_images = os.path.join (base_url_collection,"images")
base_dir_images = os.path.join (base_dir_collection,"images")
base_url_pictures = os.path.join (base_url_collection,"pictures")
base_dir_pictures = os.path.join (base_dir_collection,"pictures")
# functions that return specific filenames and urls...
def make_manufacturer_dir (resource):
directory = os.path.join (base_dir_collection, "manufacturer-"+resource)
if not os.path.isdir (directory):
os.mkdir (directory, 0755)
def manufacturer_index_href (resource,ptype):
dir = os.path.join (base_url_collection,"manufacturer-"+resource)
return os.path.join (dir,"index-%s.html"%(ProductType[ptype][ProductType_resource]))
def manufacturer_index_file (resource,ptype):
dir = os.path.join (base_dir_collection,"manufacturer-"+resource)
return os.path.join (dir,"index-%s.html"%(ProductType[ptype][ProductType_resource]))
def product_page_href (mres,pres):
dir = os.path.join (base_url_collection,"manufacturer-"+mres)
return os.path.join (dir,"%s.html"%(pres))
def product_page_file (mres,pres):
dir = os.path.join (base_dir_collection,"manufacturer-"+mres)
return os.path.join (dir,"%s.html"%(pres))
def product_picture_href (mres,pres,size):
return os.path.join (base_url_pictures,"%s-%s-%s.jpg"%(mres,pres,size))
def product_picture_file (mres,pres,size):
return os.path.join (base_dir_pictures,"%s-%s-%s.jpg"%(mres,pres,size))
def ptype_index_href (name):
return os.path.join (base_url_collection,name)
def ptype_index_file (name):
return os.path.join (base_dir_collection,name)
def static_page_href (name):
return os.path.join (base_url_collection,name)
def static_page_file (name):
return os.path.join (base_dir_collection,name)
def other_collectors_href (): return os.path.join (base_url_collection,"other_collectors.html")
def other_collectors_file (): return os.path.join (base_dir_collection,"other_collectors.html")
def plain_text_href (): return os.path.join (base_url_collection,"catalogue.txt")
def plain_text_file (): return os.path.join (base_dir_collection,"catalogue.txt")
def dot_image_size_file (): return os.path.join (base_dir_collection,".image_sizes")
# ====================================================================================================
# The db_query function keeps track of the queries made so that we can do some
# performance tuning...
#
dq_diff = {}
dq_count = 0
dq_queries = {}
def db_query (str):
global dq_diff,dq_count,dq_queries
dq_count = dq_count + 1
dq_diff[str] = 1
try:
dq_queries[str] = dq_queries[str] + 1
except KeyError:
dq_queries[str] = 1
result = dbase_connection.query(str)
return result.getresult()
# ====================================================================================================
# There are a number of static tables that only need to be read once...
#
def read_static_tables ():
print "Reading static tables..."
# --------------------------------------------------
print " item_status"
global ItemStatus,ItemStatus_name,ItemStatus_desc
ItemStatus = {}
for its_id,its_nm,its_desc in db_query ("SELECT its_id,its_nm,its_desc from item_status"):
ItemStatus[its_id] = (its_nm,its_desc)
ItemStatus_name = 0
ItemStatus_desc = 1
# --------------------------------------------------
print " product_type"
global ProductType,ProductTypeIdList,ProductType_name,ProductType_file,ProductType_resource
ProductType = {}
ProductTypeIdList = []
for ptyp_id,ptyp_nm,ptyp_file,ptyp_res in db_query ("SELECT ptyp_id,ptyp_nm,ptyp_file,ptyp_res " +
"FROM product_type " +
"ORDER BY ptyp_id"):
ptyp_id = string.atoi(ptyp_id)
ProductType[ptyp_id] = (ptyp_nm,ptyp_file,ptyp_res)
ProductTypeIdList.append (ptyp_id)
ProductType_name = 0
ProductType_file = 1
ProductType_resource = 2
# --------------------------------------------------
print " product counts"
global ProductCount,ProductCount_name
ProductCount = {}
result = db_query ("select p.ptyp_id,pt.ptyp_nm,count(prd_id) " +
"from product p,product_type pt " +
"where p.ptyp_id = pt.ptyp_id " +
"group by p.ptyp_id,pt.ptyp_nm ")
for ptyp_id,ptyp_nm,count in result:
ProductCount[ptyp_id] = (ptyp_nm,count)
ProductCount_name = 0
ProductCount_count = 1
# --------------------------------------------------
print " product_subtype"
global ProductSubType,ProductSubType_name,ProductSubType_desc
ProductSubType = {}
for pst_id,pst_nm,pst_desc in db_query ("SELECT pst_id,pst_nm,pst_desc from product_subtype"):
ProductSubType[pst_id] = (pst_nm,pst_desc)
ProductSubType_name = 0
ProductSubType_desc = 1
# --------------------------------------------------
print " manufacturer"
global ManufacturerName,Manufacturer_CommonName,Manufacturer_FullName
ManufacturerName = {}
for man_id, man_full_nm, man_cmn_nm in db_query ("SELECT man_id, man_full_nm, man_cmn_nm FROM manufacturer"):
ManufacturerName[man_id] = (man_cmn_nm,man_full_nm)
Manufacturer_CommonName = 0
Manufacturer_FullName = 1
# ====================================================================================================
class MyContainer (Container):
def start_tag (self):
return ""
def end_tag (self):
return ""
class Big(Text):
def __repr__(self):
return '%s' % self.text
class Small(Text):
def __repr__(self):
return '%s' % self.text
# ====================================================================================================
def heading_one (doc,title):
if 1:
doc.append (Paragraph(Font (Big(Bold(Italic(title))), face = "Helvetica, Arial", color = RED)))
else:
htable = TableLite (border = 0, cellspacing = 0, cellpadding = 2, width="100%")
htable.append (TR(TD(Font (Big(Bold(title)), face = "Helvetica, Arial", color = RED),
bgcolor=WHITE)))
doc.append (htable)
# ====================================================================================================
class CompColDoc (Document):
"""A document class specifically designed for my computer collection pages."""
# --------------------------------------------------------------------------------
def __init__ (self):
self.contents = []
self.heading = ""
self.has_menu = YES
self.title = ""
self.description = ""
self.keywords = []
self.dir_level = None
self.manufacturer_list = []
self.product_list = []
self.current_product = None
self.menu_selection = 202
self.main_sections = (
(202, 'Home', 'index.html'),
(101, 'Computers', 'prod_computers.html'),
(102, 'Calculators', 'prod_calculators.html'),
(103, 'Peripherals', 'prod_peripherals.html'),
(104, 'Video Games', 'prod_video_games.html'),
(107, 'Hand Held Games', 'prod_hand_held_games.html'),
)
self.other_pages = (
(203, 'Can You Help', 'can_you_help.html'),
(301, 'Other Collectors', 'other_collectors.html'),
(201, 'Creating These Pages', 'creation.html'),
)
# --------------------------------------------------------------------------------
def __repr__(self):
global base_url_images
s = DOCTYPE
# first work out what level of sub directory we are in and create relative links for graphics...
if self.dir_level == None:
base_url_images = os.path.join (base_url_collection,"images")
else:
if self.dir_level == 0:
base_url_images = "images"
elif self.dir_level == 1:
base_url_images = "../images"
# ------------------------------------------------------------
# Obviously we start with the head element...
s = s + "
\n"
# ------------------------------------------------------------
# Output the title, and some meta, link elements...
s = s + "Kevan's Computer Bits - %s\n"%(self.title)
if self.description:
s = s + "\n"%(self.description)
if self.keywords:
s = s + "\n"%(string.joinfields(self.keywords,", "))
s = s + "\n"
s = s + "\n"
s = s + "\n"
s = s + "\n"
s = s + "\n"
s = s + "\n"
# ------------------------------------------------------------
# Start the body...
s = s + '\n'%(GREEN,GREEN,GREEN)
s = s + '\n'
# everything is wrapped in a table...
s = s + '
\n'
s = s + '
\n'
# ------------------------------------------------------------
# first column contains the menus...
s = s + '
\n'
s = s + '\n'%(base_url_images)
s = s + '
\n'
if self.product_list:
cspan_arrow = 1
cspan_text = 2
else:
cspan_arrow = 2
cspan_text = 1
for list in (self.main_sections,self.other_pages):
if list is self.main_sections:
s = s + '
'%(RED)
s = s + 'Main Sections...'%(WHITE)
s = s + '
\n'
else:
s = s + '
'%(RED)
s = s + 'Other Pages...'%(WHITE)
s = s + '
\n"
# second column contains a vertical bar...
s = s + '
\n'%(WHITE,base_url_images)
# the third column contains the main content...
s = s + '
\n'
s = s + '
\n'
s = s + '
'
s = s + '
'
s = s + '\n'%(base_url_images)
s = s + ''%(base_url_images)
s = s + '
'
s = s + '
\n'
s = s + '
'
# If we are doing a heading...
s = s + '
'
s = s + '\n'%(base_url_images)
if self.heading:
s = s + '%s'%(RED,self.heading)
else:
s = s + ' '
s = s + '
'
s = s + '
\n'
s = s + '
\n'%(WHITE,base_url_images)
s = s + '
\n'%(GREEN,base_url_images)
s = s + '
\n'%(base_url_images)
s = s + '
\n'
for object in self.contents:
s = s + str(object)
s = s + '
\n'
s = s + '
\n'
s = s + '
\n'
s = s + '
\n'
s = s + "
\n"
# ------------------------------------------------------------
# and a new table for the copyrights etc.
tstr = time.asctime(time.localtime (time.time()))
s = s + '
\n'
s = s + '
\n'%(base_url_images)
s = s + '
\n'%(GREEN,base_url_images)
s = s + '
\n'%(base_url_images)
s = s + "
\n"
s = s + "
\n"
s = s + '''
Created by:
Kevan Heydon
on %s\n'''%(tstr)
s = s + '''
The pictures of my computers in these pages are
Copyright Kevan Heydon, 1996,1997,1998. You may use them for non-commercial
purposes as long as they are properly attributed to me.\n'''
s = s + "