From a062db184d6a77ef67424b45220ef075e3598185 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Thu, 29 Apr 2010 13:20:44 +0200 Subject: [PATCH] Avoid calling self.fd.tell() when we're reading from stdin. That means the options --load-from-stdin and --boundaries are not compatible. --- pgloader.py | 5 +++++ pgloader/reader.py | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pgloader.py b/pgloader.py index a424412..494e57d 100755 --- a/pgloader.py +++ b/pgloader.py @@ -296,6 +296,11 @@ def parse_options(): pgloader.options.PSYCOPG_VERSION = opts.psycopg_version if opts.boundaries: + if opts.stdin: + print >>sys.stderr, \ + "Error: You can't set the boundaries of stdin." + sys.exit(1) + try: start, end = [int(x) for x in opts.boundaries.split("..")] pgloader.options.FILE_BOUNDARIES = (start, end) diff --git a/pgloader/reader.py b/pgloader/reader.py index 0c7a8b0..ebe4c65 100644 --- a/pgloader/reader.py +++ b/pgloader/reader.py @@ -247,12 +247,13 @@ class UnbufferedFileReader: while line != '': line = self.fd.readline() self.line_nb += 1 - try: - self.position = self.fd.tell() - except IOError, error: - #IOError: [Errno 29] Illegal seek --- when stdin reaches EOF - self.log.info(error) - return + + ## try: + ## self.position = self.fd.tell() + ## except IOError, error: + ## #IOError: [Errno 29] Illegal seek --- when stdin reaches EOF + ## self.log.info(error) + ## return ## # if -F is used, count lines to skip, and skip them @@ -275,8 +276,15 @@ class UnbufferedFileReader: # check EOF (real or multi-readers) if line == '' or last_line_read: - self.log.debug("FileReader stoping, offset %d >= %s" \ - % (self.position, self.end)) + try: + self.log.debug("FileReader stoping, offset %d >= %s" \ + % (self.fd.tell(), self.end)) + except IOError, error: + #IOError: [Errno 29] Illegal seek --- when stdin reaches + # EOF should not happen as --load-from-stdin and + # --boundaries are not accepted at the same time + self.log.info(error) + self.fd.close() return