Avoid calling self.fd.tell() when we're reading from stdin.

That means the options --load-from-stdin and --boundaries are not compatible.
This commit is contained in:
Dimitri Fontaine 2010-04-29 13:20:44 +02:00
parent f154d9bf83
commit a062db184d
2 changed files with 21 additions and 8 deletions

View File

@ -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)

View File

@ -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