0ef24b1937 2011-04-06 1: #!/usr/bin/env python
0ef24b1937 2011-04-06 2:
0ef24b1937 2011-04-06 3: from __future__ import division, print_function, unicode_literals
0ef24b1937 2011-04-06 4:
0ef24b1937 2011-04-06 5: import gevent.monkey
0ef24b1937 2011-04-06 6: gevent.monkey.patch_all()
0ef24b1937 2011-04-06 7:
0ef24b1937 2011-04-06 8: import fcntl, gevent.core, gevent.pool, gevent.queue, gevent.socket, os, psycopg2, re, sys
0ef24b1937 2011-04-06 9:
0ef24b1937 2011-04-06 10: # //inclusion start
0ef24b1937 2011-04-06 11: # Copyright (C) 2010 Daniele Varrazzo <daniele.varrazzo@gmail.com>
0ef24b1937 2011-04-06 12: # and licensed under the MIT license:
0ef24b1937 2011-04-06 13:
0ef24b1937 2011-04-06 14: def gevent_wait_callback(conn, timeout=None):
0ef24b1937 2011-04-06 15: """A wait callback useful to allow gevent to work with Psycopg."""
0ef24b1937 2011-04-06 16: while 1:
0ef24b1937 2011-04-06 17: state = conn.poll()
0ef24b1937 2011-04-06 18: if state == psycopg2.extensions.POLL_OK:
0ef24b1937 2011-04-06 19: break
0ef24b1937 2011-04-06 20: elif state == psycopg2.extensions.POLL_READ:
0ef24b1937 2011-04-06 21: gevent.socket.wait_read(conn.fileno(), timeout=timeout)
0ef24b1937 2011-04-06 22: elif state == psycopg2.extensions.POLL_WRITE:
0ef24b1937 2011-04-06 23: gevent.socket.wait_write(conn.fileno(), timeout=timeout)
0ef24b1937 2011-04-06 24: else:
0ef24b1937 2011-04-06 25: raise psycopg2.OperationalError("Bad result from poll: %r" % state)
0ef24b1937 2011-04-06 26:
0ef24b1937 2011-04-06 27: if not hasattr(psycopg2.extensions, 'set_wait_callback'):
0ef24b1937 2011-04-06 28: raise ImportError("support for coroutines not available in this Psycopg version (%s)" % psycopg2.__version__)
0ef24b1937 2011-04-06 29: psycopg2.extensions.set_wait_callback(gevent_wait_callback)
0ef24b1937 2011-04-06 30:
0ef24b1937 2011-04-06 31: # //inclusion end
fc934cead1 2009-10-13 32:
fc934cead1 2009-10-13 33: # this classes processes config file and substitutes default values
fc934cead1 2009-10-13 34: class Config:
ae30851739 2010-08-12 35: __slots__ = frozenset(['_config', '_default', '_section', 'options'])
b93dc49210 2009-10-13 36: _default = {
fc934cead1 2009-10-13 37: 'log': {
fc934cead1 2009-10-13 38: 'silent': 'no',
fc934cead1 2009-10-13 39: },
fc934cead1 2009-10-13 40: 'database': {
fc934cead1 2009-10-13 41: 'host': 'localhost',
fc934cead1 2009-10-13 42: 'database': 'squidTag',
fc934cead1 2009-10-13 43: },}
fc934cead1 2009-10-13 44:
fc934cead1 2009-10-13 45: # function to read in config file
fc934cead1 2009-10-13 46: def __init__(self):
0ef24b1937 2011-04-06 47: import ConfigParser, optparse, os
ae30851739 2010-08-12 48:
d500448801 2009-10-05 49: parser = optparse.OptionParser()
d500448801 2009-10-05 50: parser.add_option('-c', '--config', dest = 'config',
d500448801 2009-10-05 51: help = 'config file location', metavar = 'FILE',
d500448801 2009-10-05 52: default = '/usr/local/etc/squid-tagger.conf')
ae30851739 2010-08-12 53: parser.add_option('-d', '--dump', dest = 'dump',
ae30851739 2010-08-12 54: help = 'dump database', action = 'store_true', metavar = 'bool',
ae30851739 2010-08-12 55: default = False)
31e69c4237 2010-08-12 56: parser.add_option('-f', '--flush-database', dest = 'flush_db',
31e69c4237 2010-08-12 57: help = 'flush previous database on load', default = False,
31e69c4237 2010-08-12 58: action = 'store_true', metavar = 'bool')
31e69c4237 2010-08-12 59: parser.add_option('-l', '--load', dest = 'load',
31e69c4237 2010-08-12 60: help = 'load database', action = 'store_true', metavar = 'bool',
31e69c4237 2010-08-12 61: default = False)
d301d9adc6 2010-08-13 62: parser.add_option('-D', '--dump-conf', dest = 'dump_conf',
d301d9adc6 2010-08-13 63: help = 'dump filtering rules', default = False, metavar = 'bool',
d301d9adc6 2010-08-13 64: action = 'store_true')
d301d9adc6 2010-08-13 65: parser.add_option('-L', '--load-conf', dest = 'load_conf',
d301d9adc6 2010-08-13 66: help = 'load filtering rules', default = False, metavar = 'bool',
d301d9adc6 2010-08-13 67: action = 'store_true')
7c13294e9f 2010-08-07 68:
ae30851739 2010-08-12 69: (self.options, args) = parser.parse_args()
7c13294e9f 2010-08-07 70:
ae30851739 2010-08-12 71: assert os.access(self.options.config, os.R_OK), "Fatal error: can't read {}".format(self.options.config)
7c13294e9f 2010-08-07 72:
0ef24b1937 2011-04-06 73: self._config = ConfigParser.ConfigParser()
ae30851739 2010-08-12 74: self._config.readfp(open(self.options.config))
fc934cead1 2009-10-13 75:
fc934cead1 2009-10-13 76: # function to select config file section or create one
d500448801 2009-10-05 77: def section(self, section):
fc934cead1 2009-10-13 78: if not self._config.has_section(section):
fc934cead1 2009-10-13 79: self._config.add_section(section)
d500448801 2009-10-05 80: self._section = section
d500448801 2009-10-05 81:
fc934cead1 2009-10-13 82: # function to get config parameter, if parameter doesn't exists the default
fc934cead1 2009-10-13 83: # value or None is substituted
d500448801 2009-10-05 84: def __getitem__(self, name):
fc934cead1 2009-10-13 85: if not self._config.has_option(self._section, name):
b93dc49210 2009-10-13 86: if self._section in self._default:
b93dc49210 2009-10-13 87: if name in self._default[self._section]:
fc934cead1 2009-10-13 88: self._config.set(self._section, name, self._default[self._section][name])
fc934cead1 2009-10-13 89: else:
fc934cead1 2009-10-13 90: self._config.set(self._section, name, None)
fc934cead1 2009-10-13 91: else:
fc934cead1 2009-10-13 92: self._config.set(self._section, name, None)
b93dc49210 2009-10-13 93: return(self._config.get(self._section, name))
d500448801 2009-10-05 94:
fc934cead1 2009-10-13 95: # initializing and reading in config file
d500448801 2009-10-05 96: config = Config()
d500448801 2009-10-05 97:
fad48b740c 2012-07-07 98: import logging, logging.handlers
fad48b740c 2012-07-07 99: logger = logging.getLogger('squidTag')
fad48b740c 2012-07-07 100: logger.setLevel(logging.INFO)
fad48b740c 2012-07-07 101: handler = logging.handlers.SysLogHandler('/dev/log')
fad48b740c 2012-07-07 102: handler.setFormatter(logging.Formatter(str('squidTag[%(process)s]: %(message)s')))
fad48b740c 2012-07-07 103: logger.addHandler(handler)
39b97ced92 2011-06-05 104:
39b97ced92 2011-06-05 105: # tiny wrapper around a file to make reads from it geventable
39b97ced92 2011-06-05 106: # or should i move this somewhere?
39b97ced92 2011-06-05 107:
39b97ced92 2011-06-05 108: class FReadlineQueue(gevent.queue.Queue):
39b97ced92 2011-06-05 109: # storing file descriptor, leftover
39b97ced92 2011-06-05 110: __slots__ = frozenset(['_fd', '_tail'])
39b97ced92 2011-06-05 111:
39b97ced92 2011-06-05 112: def __init__(self, fd):
39b97ced92 2011-06-05 113: # initialising class
39b97ced92 2011-06-05 114: gevent.queue.Queue.__init__(self)
39b97ced92 2011-06-05 115: # storing file descriptor
39b97ced92 2011-06-05 116: self._fd = fd
39b97ced92 2011-06-05 117: # using empty tail
39b97ced92 2011-06-05 118: self._tail = ''
39b97ced92 2011-06-05 119: # setting up event
39b97ced92 2011-06-05 120: self._install_wait()
39b97ced92 2011-06-05 121:
39b97ced92 2011-06-05 122: def _install_wait(self):
39b97ced92 2011-06-05 123: fileno = self._fd.fileno()
39b97ced92 2011-06-05 124: # putting file to nonblocking mode
39b97ced92 2011-06-05 125: fcntl.fcntl(fileno, fcntl.F_SETFL, fcntl.fcntl(fileno, fcntl.F_GETFL) | os.O_NONBLOCK)
39b97ced92 2011-06-05 126: # installing event handler
39b97ced92 2011-06-05 127: gevent.core.read_event(fileno, self._wait_helper)
39b97ced92 2011-06-05 128:
39b97ced92 2011-06-05 129: def _wait_helper(self, ev, evtype):
39b97ced92 2011-06-05 130: # reading one buffer from stream
39b97ced92 2011-06-05 131: buf = self._fd.read(4096)
39b97ced92 2011-06-05 132: # splitting stream by line ends
39b97ced92 2011-06-05 133: rows = buf.decode('l1').split('\n')
39b97ced92 2011-06-05 134: # adding tail to the first element if there is some tail
39b97ced92 2011-06-05 135: if len(self._tail) > 0:
39b97ced92 2011-06-05 136: rows[0] = self._tail + rows[0]
39b97ced92 2011-06-05 137: # popping out last (incomplete) element
39b97ced92 2011-06-05 138: self._tail = rows.pop(-1)
39b97ced92 2011-06-05 139: # dropping all complete elements to the queue
39b97ced92 2011-06-05 140: for row in rows:
39b97ced92 2011-06-05 141: self.put_nowait(row)
fad48b740c 2012-07-07 142: logger.info(str('< ' + row))
39b97ced92 2011-06-05 143: if len(buf) > 0:
39b97ced92 2011-06-05 144: # no EOF, reinstalling event handler
39b97ced92 2011-06-05 145: gevent.core.read_event(self._fd.fileno(), self._wait_helper)
39b97ced92 2011-06-05 146: else:
39b97ced92 2011-06-05 147: # EOF found, sending EOF to queue
39b97ced92 2011-06-05 148: self.put_nowait(None)
39b97ced92 2011-06-05 149:
39b97ced92 2011-06-05 150: stdin = FReadlineQueue(sys.stdin)
d823fa83dd 2012-07-07 151:
d823fa83dd 2012-07-07 152: class FWritelineQueue(gevent.queue.JoinableQueue):
d823fa83dd 2012-07-07 153: # storing fileno, io interface, leftover
d823fa83dd 2012-07-07 154: __slots__ = frozenset(['_fileno', '_io', '_tail'])
d823fa83dd 2012-07-07 155:
d823fa83dd 2012-07-07 156: def __init__(self, fd, closefd = True):
d823fa83dd 2012-07-07 157: import io
d823fa83dd 2012-07-07 158: # initialising class
d823fa83dd 2012-07-07 159: gevent.queue.JoinableQueue.__init__(self)
d823fa83dd 2012-07-07 160: # storing fileno
d823fa83dd 2012-07-07 161: self._fileno = fd.fileno()
d823fa83dd 2012-07-07 162: # creating interface
d823fa83dd 2012-07-07 163: self._io = io.FileIO(self._fileno, 'w', closefd)
d823fa83dd 2012-07-07 164: # using empty tail
d823fa83dd 2012-07-07 165: self._tail = None
d823fa83dd 2012-07-07 166: # putting file to nonblocking mode
d823fa83dd 2012-07-07 167: fcntl.fcntl(self._fileno, fcntl.F_SETFL, fcntl.fcntl(self._fileno, fcntl.F_GETFL) | os.O_NONBLOCK)
d823fa83dd 2012-07-07 168:
d823fa83dd 2012-07-07 169: def __del__(self):
d823fa83dd 2012-07-07 170: # purge queue before deleting
d823fa83dd 2012-07-07 171: if not self.empty():
d823fa83dd 2012-07-07 172: self.join()
d823fa83dd 2012-07-07 173:
d823fa83dd 2012-07-07 174: def put(self, item, block=True, timeout=None):
d823fa83dd 2012-07-07 175: # calling real put
d823fa83dd 2012-07-07 176: gevent.queue.JoinableQueue.put(self, item, block, timeout)
d823fa83dd 2012-07-07 177: # installing event handler
d823fa83dd 2012-07-07 178: gevent.core.write_event(self._fileno, self._wait_helper)
d823fa83dd 2012-07-07 179:
d823fa83dd 2012-07-07 180: def _wait_helper(self, ev, evtype):
d823fa83dd 2012-07-07 181: # XXX ev, evtype checking?
d823fa83dd 2012-07-07 182: # checking leftover
d823fa83dd 2012-07-07 183: while True:
d823fa83dd 2012-07-07 184: if self._tail == None:
d823fa83dd 2012-07-07 185: try:
d823fa83dd 2012-07-07 186: self._tail = str(self.get_nowait()).encode('utf-8') + '\n'
d823fa83dd 2012-07-07 187: except gevent.queue.Empty:
d823fa83dd 2012-07-07 188: self._tail = None
d823fa83dd 2012-07-07 189: return
d823fa83dd 2012-07-07 190: # writing tail
d823fa83dd 2012-07-07 191: written = self._io.write(self._tail)
d823fa83dd 2012-07-07 192: length = len(self._tail)
d823fa83dd 2012-07-07 193: if written == length:
d823fa83dd 2012-07-07 194: self._tail = None
d823fa83dd 2012-07-07 195: elif written < length:
d823fa83dd 2012-07-07 196: self._tail = self._tail[written:]
d823fa83dd 2012-07-07 197: break
d823fa83dd 2012-07-07 198: else:
d823fa83dd 2012-07-07 199: break
d823fa83dd 2012-07-07 200: # reinstalling event handler
d823fa83dd 2012-07-07 201: gevent.core.write_event(self._fileno, self._wait_helper)
d2c7ba18a4 2011-09-14 202:
39b97ced92 2011-06-05 203: # wrapper around database
39b97ced92 2011-06-05 204: class tagDB(object):
39b97ced92 2011-06-05 205: __slots__ = frozenset(['_cursor', '_db'])
39b97ced92 2011-06-05 206:
39b97ced92 2011-06-05 207: def __init__(self):
39b97ced92 2011-06-05 208: config.section('database')
d2c7ba18a4 2011-09-14 209: if config['host'] == None:
d2c7ba18a4 2011-09-14 210: self._db = psycopg2.connect(
d2c7ba18a4 2011-09-14 211: database = config['database'],
d2c7ba18a4 2011-09-14 212: user = config['user'],
d2c7ba18a4 2011-09-14 213: password = config['password']
d2c7ba18a4 2011-09-14 214: )
d2c7ba18a4 2011-09-14 215: else:
d2c7ba18a4 2011-09-14 216: self._db = psycopg2.connect(
d2c7ba18a4 2011-09-14 217: database = config['database'],
d2c7ba18a4 2011-09-14 218: host = config['host'],
d2c7ba18a4 2011-09-14 219: user = config['user'],
d2c7ba18a4 2011-09-14 220: password = config['password']
d2c7ba18a4 2011-09-14 221: )
39b97ced92 2011-06-05 222: self._cursor = self._db.cursor()
39b97ced92 2011-06-05 223:
39b97ced92 2011-06-05 224: def _field_names(self):
39b97ced92 2011-06-05 225: names = []
39b97ced92 2011-06-05 226: for record in self._cursor.description:
39b97ced92 2011-06-05 227: names.append(record.name)
39b97ced92 2011-06-05 228: return(names)
39b97ced92 2011-06-05 229:
39b97ced92 2011-06-05 230: def check(self, site, ip_address):
39b97ced92 2011-06-05 231: self._cursor.execute("select * from (select redirect_url, regexp from site_rule where site <@ tripdomain(%s) and netmask >>= %s order by array_length(site, 1) desc) a group by redirect_url, regexp", [site, ip_address])
39b97ced92 2011-06-05 232: return(self._cursor.fetchall())
39b97ced92 2011-06-05 233:
39b97ced92 2011-06-05 234: def dump(self):
39b97ced92 2011-06-05 235: self._cursor.execute("select untrip(site) as site, tag::text, regexp from urls order by site, tag")
39b97ced92 2011-06-05 236: return(self._field_names(), self._cursor.fetchall())
39b97ced92 2011-06-05 237:
39b97ced92 2011-06-05 238: def load(self, data):
39b97ced92 2011-06-05 239: if config.options.flush_db:
39b97ced92 2011-06-05 240: self._cursor.execute('delete from urls;')
39b97ced92 2011-06-05 241: bundle = []
39b97ced92 2011-06-05 242: for row in data:
39b97ced92 2011-06-05 243: if len(row) == 2:
39b97ced92 2011-06-05 244: bundle.append([row[0], row[1], None])
39b97ced92 2011-06-05 245: else:
39b97ced92 2011-06-05 246: bundle.append([row[0], row[1], row[2]])
39b97ced92 2011-06-05 247: self._cursor.executemany("insert into urls (site, tag, regexp) values (tripdomain(%s), %s, %s)", bundle)
39b97ced92 2011-06-05 248: self._cursor.execute("update urls set regexp = NULL where regexp = ''")
39b97ced92 2011-06-05 249: self._db.commit()
39b97ced92 2011-06-05 250:
39b97ced92 2011-06-05 251: def load_conf(self, csv_data):
39b97ced92 2011-06-05 252: self._cursor.execute('delete from rules;')
39b97ced92 2011-06-05 253: bundle = []
39b97ced92 2011-06-05 254: for row in csv_data:
39b97ced92 2011-06-05 255: bundle.append([row[0], row[1], int(row[2]), int(row[3]), row[4], row[5], row[6]])
39b97ced92 2011-06-05 256: self._cursor.executemany("insert into rules (netmask, redirect_url, from_weekday, to_weekday, from_time, to_time, tag) values (%s::text::cidr, %s, %s, %s, %s::text::time, %s::text::time, %s::text::text[])", bundle)
39b97ced92 2011-06-05 257: self._db.commit()
39b97ced92 2011-06-05 258:
39b97ced92 2011-06-05 259: def dump_conf(self):
39b97ced92 2011-06-05 260: self._cursor.execute("select netmask, redirect_url, from_weekday, to_weekday, from_time, to_time, tag::text from rules")
39b97ced92 2011-06-05 261: return(self._field_names(), self._cursor.fetchall())
39b97ced92 2011-06-05 262:
39b97ced92 2011-06-05 263: # abstract class with basic checking functionality
39b97ced92 2011-06-05 264: class Checker(object):
d823fa83dd 2012-07-07 265: __slots__ = frozenset(['_db', '_log', '_queue', '_request', '_stdout'])
39b97ced92 2011-06-05 266:
39b97ced92 2011-06-05 267: def __init__(self, queue, logger):
39b97ced92 2011-06-05 268: self._db = tagDB()
39b97ced92 2011-06-05 269: self._log = logger
fad48b740c 2012-07-07 270: self._log.info(str('started'))
39b97ced92 2011-06-05 271: self._request = re.compile('^([0-9]+)\ (http|ftp):\/\/([-\w.:]+)\/([^ ]*)\ ([0-9.]+)\/(-|[\w\.]+)\ (-|\w+)\ (-|GET|HEAD|POST).*$')
39b97ced92 2011-06-05 272: self._queue = queue
d823fa83dd 2012-07-07 273: self._stdout = FWritelineQueue(sys.stdout, False)
39b97ced92 2011-06-05 274:
39b97ced92 2011-06-05 275: def process(self, id, site, ip_address, url_path, line = None):
fad48b740c 2012-07-07 276: #self._log.info(str('trying {}'.format(site)))
39b97ced92 2011-06-05 277: result = self._db.check(site, ip_address)
39b97ced92 2011-06-05 278: reply = None
fad48b740c 2012-07-07 279: #self._log.info(str('got {} lines from database'.format(len(result))))
39b97ced92 2011-06-05 280: for row in result:
39b97ced92 2011-06-05 281: if row != None and row[0] != None:
39b97ced92 2011-06-05 282: if row[1] != None:
fad48b740c 2012-07-07 283: self._log.info(str('trying regexp "{}" versus "{}"'.format(row[1], url_path)))
39b97ced92 2011-06-05 284: try:
39b97ced92 2011-06-05 285: if re.compile(row[1]).match(url_path):
39b97ced92 2011-06-05 286: reply = row[0].format(url_path)
39b97ced92 2011-06-05 287: else:
39b97ced92 2011-06-05 288: continue
39b97ced92 2011-06-05 289: except:
fad48b740c 2012-07-07 290: self._log.info(str("can't compile regexp"))
39b97ced92 2011-06-05 291: else:
39b97ced92 2011-06-05 292: reply = row[0].format(url_path)
39b97ced92 2011-06-05 293: if reply != None:
d823fa83dd 2012-07-07 294: self.writeline('{} {}'.format(id, reply))
39b97ced92 2011-06-05 295: return(True)
d823fa83dd 2012-07-07 296: self.writeline('{}'.format(id))
39b97ced92 2011-06-05 297:
39b97ced92 2011-06-05 298: def check(self):
39b97ced92 2011-06-05 299: while True:
39b97ced92 2011-06-05 300: line = self._queue.get()
39b97ced92 2011-06-05 301: if line == None:
39b97ced92 2011-06-05 302: break
fad48b740c 2012-07-07 303: #self._log.info(str('request: ' + line))
39b97ced92 2011-06-05 304: request = self._request.match(line)
39b97ced92 2011-06-05 305: if request:
39b97ced92 2011-06-05 306: id = request.group(1)
39b97ced92 2011-06-05 307: #proto = request.group(2)
39b97ced92 2011-06-05 308: site = request.group(3)
39b97ced92 2011-06-05 309: url_path = request.group(4)
39b97ced92 2011-06-05 310: ip_address = request.group(5)
39b97ced92 2011-06-05 311: self.process(id, site, ip_address, url_path, line)
39b97ced92 2011-06-05 312: else:
fad48b740c 2012-07-07 313: self._log.info(str('bad request'))
d823fa83dd 2012-07-07 314: self.writeline(line)
39b97ced92 2011-06-05 315:
39b97ced92 2011-06-05 316: def writeline(self, string):
fad48b740c 2012-07-07 317: self._log.info(str('> ' + string))
d823fa83dd 2012-07-07 318: self._stdout.put(string)
39b97ced92 2011-06-05 319:
39b97ced92 2011-06-05 320: def loop(self):
39b97ced92 2011-06-05 321: pool = gevent.pool.Pool()
39b97ced92 2011-06-05 322: pool.spawn(self.check)
39b97ced92 2011-06-05 323: pool.join()
39b97ced92 2011-06-05 324:
d301d9adc6 2010-08-13 325: if config.options.dump or config.options.load or config.options.dump_conf or config.options.load_conf:
d301d9adc6 2010-08-13 326: import csv
d301d9adc6 2010-08-13 327:
d301d9adc6 2010-08-13 328: tagdb = tagDB()
bde51dc0c7 2010-08-26 329: data_fields = ['site', 'tag', 'regexp']
d301d9adc6 2010-08-13 330: conf_fields = ['netmask', 'redirect_url', 'from_weekday', 'to_weekday', 'from_time', 'to_time', 'tag']
d301d9adc6 2010-08-13 331:
d301d9adc6 2010-08-13 332: if config.options.dump or config.options.dump_conf:
0ef24b1937 2011-04-06 333: csv_writer = csv.writer(sys.stdout)
d301d9adc6 2010-08-13 334: if config.options.dump:
bde51dc0c7 2010-08-26 335: dump = tagdb.dump()
bde51dc0c7 2010-08-26 336: elif config.options.dump_conf:
bde51dc0c7 2010-08-26 337: dump = tagdb.dump_conf()
bde51dc0c7 2010-08-26 338:
0ef24b1937 2011-04-06 339: csv_writer.writerow(dump[0])
0ef24b1937 2011-04-06 340: for line in dump[1]:
0ef24b1937 2011-04-06 341: csv_writer.writerow(line)
d301d9adc6 2010-08-13 342:
d301d9adc6 2010-08-13 343: elif config.options.load or config.options.load_conf:
d301d9adc6 2010-08-13 344: csv_reader = csv.reader(sys.stdin)
d301d9adc6 2010-08-13 345: first_row = next(csv_reader)
d301d9adc6 2010-08-13 346:
d301d9adc6 2010-08-13 347: if config.options.load:
bde51dc0c7 2010-08-26 348: fields = data_fields
bde51dc0c7 2010-08-26 349: load = tagdb.load
bde51dc0c7 2010-08-26 350: elif config.options.load_conf:
bde51dc0c7 2010-08-26 351: fields = conf_fields
bde51dc0c7 2010-08-26 352: load = tagdb.load_conf
bde51dc0c7 2010-08-26 353:
bde51dc0c7 2010-08-26 354: assert first_row == fields, 'File must contain csv data with theese columns: ' + repr(fields)
bde51dc0c7 2010-08-26 355: load(csv_reader)
d301d9adc6 2010-08-13 356:
d301d9adc6 2010-08-13 357: else:
d301d9adc6 2010-08-13 358: # main loop
39b97ced92 2011-06-05 359: Checker(stdin, logger).loop()