[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/reports/src/adapters/filters/Standard/Base...
From: |
Jason Cater |
Subject: |
gnue/reports/src/adapters/filters/Standard/Base... |
Date: |
Mon, 07 Apr 2003 18:28:38 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jason Cater <address@hidden> 03/04/07 18:28:38
Modified files:
reports/src/adapters/filters/Standard/Base/psutils:
PrinterDefinition.py
Log message:
more work
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
Patches:
Index:
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py
diff -c
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py:1.7
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py:1.8
***
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py:1.7
Mon Apr 7 04:45:51 2003
---
gnue/reports/src/adapters/filters/Standard/Base/psutils/PrinterDefinition.py
Mon Apr 7 18:28:38 2003
***************
*** 42,47 ****
--- 42,53 ----
class PrinterDefinition:
def __init__(self, location):
+ self.__symbols__ = {}
+ self.__uioptions__ = {}
+ self.__properties__ = {}
+ self.__defaults__ = {}
+ self.__values__ = {}
+
self.loadFile(location)
***************
*** 61,106 ****
# Process each line of the file
#
line = handle.readline()
! while line is not None:
line = line.strip()
! # Skip blank lines, comments (*%), and "query" (*?) keywords.
! # We skip the query keywords as we have no intention of
! # getting intimate with a printer and asking it questions.
! if line[:2] in ('','*%','*?'):
line = handle.readline()
continue
# Get stuff to the left of the colon
# (Can either be a Keyword, or a Keyword + Option)
! keyword, data = line.split(':',2)
! # Dump the leading asterick and trailing colon
! # (not sure if the .strip() is necessary :)
! keyword = keyword[1:-1].strip()
# Clean up the data line
! data.strip()
# Do we have an Option, or just a Keyword?
try:
! keyword, option = keyword.split()
! except:
! option = None
! isSymbol = 0
# ^Data means Data is a Symbol
if data[:1] == '^':
! isSymbol = 1
! data = date[1:]
# Double Quotes means data is Quoted... treat specially
elif data[:1] == '"':
# If last character is a quote, then this is a single-line string
! if data[:-1] == '"':
data = data[1:-1]
# otherwise, we need to grab the rest of the data
--- 67,130 ----
# Process each line of the file
#
line = handle.readline()
! while line != '':
line = line.strip()
! # Skip blank lines and comments (*%).
! if line[:2] in ('','*%'):
line = handle.readline()
continue
+ ##print "Line: %s" % line
+
# Get stuff to the left of the colon
# (Can either be a Keyword, or a Keyword + Option)
! try:
! keyword, data = line.split(':',1)
! except ValueError:
! keyword = line
! data = ''
!
! # Dump the leading asterick (not sure
! # if the .strip() is necessary)
! keyword = keyword[1:].strip()
! print " Found Key Word: %s" % keyword
# Clean up the data line
! data = data.strip()
# Do we have an Option, or just a Keyword?
try:
! d = keyword.split(' ')
! keyword = d[0]
! option = string.join(d[1:],' ')
!
! # Options can be in the format Name/Friendly Name
! # The Friendly Name part is called a "translation"
! try:
! option, option_translation = option.split('/',1)
! ## print " Option/Trans=[%s] [%s]/[%s]" % (keyword, option,
option_translation)
! except ValueError:
! option_translation = option
! ## print " Option=%s" % (option)
! except ValueError:
! option = None
# ^Data means Data is a Symbol
if data[:1] == '^':
! # Create a wrapper, so the app developer doesn't
! # have to distinguish between data being a symbol
! # and being a string. _SymbolData acts like a string.
! data = _SymbolData(self, data[1:])
# Double Quotes means data is Quoted... treat specially
elif data[:1] == '"':
# If last character is a quote, then this is a single-line string
! if data[-1:] == '"' and len(data) > 1:
data = data[1:-1]
# otherwise, we need to grab the rest of the data
***************
*** 112,123 ****
# Find the next '*End' marker
line = handle.readline()
! while line != None and line.strip() != '*End'"
data += line
line = handle.readline()
# If we never hit an *End, then this isn't a valid file.
! if line is None:
raise InvalidPPDFormat, 'Not a valid PPD file... missing *End'
# Get rid of the closing quote
--- 136,147 ----
# Find the next '*End' marker
line = handle.readline()
! while line != None and line.strip() != '*End':
data += line
line = handle.readline()
# If we never hit an *End, then this isn't a valid file.
! if line == '':
raise InvalidPPDFormat, 'Not a valid PPD file... missing *End'
# Get rid of the closing quote
***************
*** 136,143 ****
--- 160,183 ----
# Handle any imports
if keyword == 'Import':
+ print " Importing another file"
self.loadFile(data)
+ elif keyword == 'SymbolValue':
+ print " Setting symbol %s" % option[1:]
+ if not self.__symbols__.has_key(option[1:]):
+ self.__symbols__[option[1:]] = data
+
+ # Keywords we don't need to keep.
+ # We include all "query" keywords (*?....)
+ elif keyword in ('End','SymbolLength','SymbolEnd') \
+ or keyword[:1] == '?':
+ pass
+
+ elif keyword[:7] == 'Default':
+ print " Setting default value for %s" % keyword[7:]
+ if not self.__defaults__.has_key(keyword[7:]):
+ self.__defaults__[keyword[7:]] = data
# Next in line, please!
line = handle.readline()
***************
*** 148,153 ****
--- 188,209 ----
handle.close()
+ class _SymbolData:
+ def __init__(self, handler, symbol):
+ self.handler = handler
+ self.symbol = symbol
+
+ def __str__(self):
+ try:
+ return self.__value__
+ except:
+ try:
+ self.__value__ = val = self.handler.__symbols__[self.symbol]
+ return val
+ except KeyError:
+ raise InvalidPPDFormat, 'Symbol %s referenced, but not defined." %
(self.symbol)'
+
+
# Used by the class above to convert a
# hex-encoded string to a binary string.
***************
*** 165,167 ****
--- 221,228 ----
# Precompile our regular expression
_hexre = re.compile(r'<.*?>')
+
+
+ if __name__ == '__main__':
+ import sys
+ PrinterDefinition(sys.argv[1])
\ No newline at end of file
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/03
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/03
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/07
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/07
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/07
- gnue/reports/src/adapters/filters/Standard/Base...,
Jason Cater <=
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/15
- gnue/reports/src/adapters/filters/Standard/Base..., Jason Cater, 2003/04/22