Anonymous avatar Anonymous committed 3993a33

more dict work; filters working

Comments (0)

Files changed (2)

     for o, a in opts:
         if o in ("-a", "--account"):
 	    sink.account = a
-	    filter = trxtsv.AccountFilter(a, filter)
+	    f = trxtsv.PathFilter(a, ('trx', 'acct',))
+	    if filter: filter = trxtsv.AndFilter(filter, f)
+	    else: filter = f
 	elif o in ("--class",):
 	    sink.splitClass = a
-	    filter = trxtsv.ClassFilter(a, filter)
+	    f = trxtsv.PathFilter(a, ('splits', '*', 'class',))
+	    if filter: filter = trxtsv.AndFilter(filter, f)
+	    else: filter = f
 	    
     trxtsv.eachFile(args, sink, filter)
 
 	else:
 	    self._row += 1
 
-	date, acct, num, desc = trx[:4]
-	datei = isoDate(date)
+	datei = isoDate(trx['date'])
 	w("<tbody class='vevent'>\n")
 	w(" <tr class='trx'><td><abbr class='dtstart %s' title='%s'>%s</abbr>"
-	  "</td>\n" % (parity(datei), datei, date))
+	  "</td>\n" % (parity(datei), datei, trx['date']))
 
-	num, splitflag, trxty = numField(num)
+	num, splitflag, trxty = numField(trx.get('num', ''))
 
-	descElt(w, 'td', desc)
+	descElt(w, 'td', trx.get('payee', ''))
 	w("<td>%s</td> <td>%s</td></tr>\n" %
-	  (num or trxty or '', acct))
+	  (num or trxty or '', trx['acct']))
 
-        for d1, d2, d3, d4, memo, category, clr, a in splits:
+        for split in splits:
 	    w("<tr class='split'><td></td><td>%s</td><td>%s</td>"
 	      "<td>%s</td><td class='amt'>%s</td></tr>\n" %
-	      (xmldata(memo), clr, xmldata(category), a))
+	      (xmldata(split.get('memo', '')),
+	       split.get('clr', ''),
+	       xmldata(split.get('L', '')),
+	       split.get('subtot', '')))
 	w("</tbody>\n\n")
 
     def close(self):
 	r = []
 	for trx in eachTrx(lines, r):
 	    if filter is None or filter(trx):
-		sink.transaction(trx[0], trx[1])
+		sink.transaction(trx['trx'], trx['splits'])
         ln = r[0]
         foot = readFooter(lines, ln)
         progress("footer: ", fn, foot)
     See isoDate(), num(), and amt() for some of the string formats.
 
     >>> d=iter(_TestLines); dummy=readHeader(d); t=eachTrx(d, []); \
-    _sortRecord(t.next())
-    [('splits', [[('cat', 'Home'), ('clr', 'R'), ('subtot', '-17.70')]]), ('trx', [('acct', 'Texans Checks'), ('date', '1/7/94'), ('memo', 'Albertsons'), ('payee', '1237')])]
+    _sr(t.next())
+    [('splits', [[('L', 'Home'), ('cat', 'Home'), ('clr', 'R'), ('subtot', '-17.70')]]), ('trx', [('acct', 'Texans Checks'), ('date', '1/7/94'), ('num', '1237'), ('payee', 'Albertsons')])]
 
     >>> d=iter(_TestLines); dummy=readHeader(d); t=eachTrx(d, []); \
-    _sortRecord(list(t)[8])
-    [('splits', [[('acct', 'MIT 97'), ('class', '9912mit-misc'), ('clr', 'R'), ('memo', '@@reciept?Palm IIIx replacement (phone order 3 Jan)'), ('subtot', '-100.00')]]), ('trx', [('acct', 'Citi Visa HI'), ('date', '1/3/00'), ('memo', '3Com/Palm Computing 888-956-7256')])]
+    _sr(list(t)[8])
+    [('splits', [[('L', '[MIT 97]/9912mit-misc'), ('acct', 'MIT 97'), ('class', '9912mit-misc'), ('clr', 'R'), ('memo', '@@reciept?Palm IIIx replacement (phone order 3 Jan)'), ('subtot', '-100.00')]]), ('trx', [('acct', 'Citi Visa HI'), ('date', '1/3/00'), ('memo', '@@reciept?Palm IIIx replacement (phone order 3 Jan)'), ('payee', '3Com/Palm Computing 888-956-7256')])]
 
 
     """
 	if v: d[k] = v
     return d
 
-def _sortRecord(r):
+def _sr(r):
     """just for testing
     """
     if type(r) is type({}):
 	it=r.items()
 	it.sort()
-	return [(k, _sortRecord(v) ) for k, v in it]
+	return [(k, _sr(v) ) for k, v in it]
     elif type(r) is type([]):
-	return [_sortRecord(v) for v in r]
+	return [_sr(v) for v in r]
     else:
 	return r
 
-TrxCols = ('date', 'acct', 'payee', 'memo')
-SplitCols = ('memo', 'cat', 'clr', 'subtot')
+TrxCols = ('date', 'acct', 'num', 'payee', 'memo')
+SplitCols = ('memo', 'L', 'clr', 'subtot')
 
 def fixSplit(rec):
     """
-    >>> fixSplit({'cat': 'Home'})
-    {'cat': 'Home'}
+    >>> _sr(fixSplit({'L': 'Home'}))
+    [('L', 'Home'), ('cat', 'Home')]
 
-    >>> fixSplit({'cat': '[MIT 97]/9912mit-misc'})
-    {'acct': 'MIT 97', 'class': '9912mit-misc'}
+    >>> _sr(fixSplit({'L': '[MIT 97]/9912mit-misc'}))
+    [('L', '[MIT 97]/9912mit-misc'), ('acct', 'MIT 97'), ('class', '9912mit-misc')]
 
-    >>> fixSplit({'cat': 'xyz/9912mit-misc'})
-    {'class': '9912mit-misc', 'cat': 'xyz'}
+    >>> _sr(fixSplit({'L': 'xyz/9912mit-misc'}))
+    [('L', 'xyz/9912mit-misc'), ('cat', 'xyz'), ('class', '9912mit-misc')]
     """
 
-    if not 'cat' in rec: return rec
+    if not 'L' in rec: return rec
 
-    s = rec['cat']
+    s = rec['L']
     if '/' in s:
 	s, cls = s.split('/')
 	rec['class'] = cls
+    if '[' in s:
+	rec['acct'] = s[1:-1]
+    else:
 	rec['cat'] = s
-    if '[' in s:
-	del rec['cat']
-	rec['acct'] = s[1:-1]
     return rec
 
 
     f(trx)
     True
 
+    >>> f=PathFilter('Citi Visa HI', ('trx', 'acct')); \
+    trx={'trx': {'date': '1/3/00', 'acct': 'Citi Visa HI', \
+    'memo': '3Com/Palm Computing 888-956-7256'}, \
+    'splits': [{'memo': '@@reciept?Palm IIIx replacement (phone order 3 Jan)',\
+    'acct': 'MIT 97', 'class': '9912mit-misc', 'clr': 'R', \
+    'amt': '-100.00'}]}; \
+    f(trx)
+    True
+
     """
     def __init__(self, v, path):
 	self._v = v
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.