don't generate empty output files

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3332 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2006-06-01 13:58:13 +00:00
parent b0b3f2263d
commit c3fa9d7965
3 changed files with 25 additions and 9 deletions

View file

@ -4,6 +4,11 @@
new option --allow-root to prevent this.
Type: feature
Changed: linkchecker, doc/{en,de}/linkchecker.1
* Don't generate empty output files, open them only when they are
written to.
Type: bugfix
Changed: linkcheck/logger/{__init__,text}.py
4.1 "Totsi" (released 29.5.2006)

View file

@ -77,19 +77,23 @@ class Logger (object):
"""
Initialize self.fd file descriptor from args.
"""
self.filename = None
self.close_fd = False
self.fd = None
if args.get('fileoutput'):
filename = args['filename']
path = os.path.dirname(filename)
if path and not os.path.isdir(path):
os.makedirs(path)
self.fd = file(filename, "wb")
self.close_fd = True
self.filename = args['filename']
elif args.has_key('fd'):
self.fd = args['fd']
self.close_fd = False
else:
self.fd = sys.stdout
self.close_fd = False
def start_fileoutput (self):
path = os.path.dirname(self.filename)
if path and not os.path.isdir(path):
os.makedirs(path)
self.fd = file(self.filename, "wb")
self.close_fd = True
self.filename = None
def close_fileoutput (self):
"""
@ -144,6 +148,8 @@ class Logger (object):
"""
Write string to output descriptor.
"""
if self.filename is not None:
self.start_fileoutput()
if self.fd is None:
raise ValueError("write to non-file")
self.fd.write(self.encode(s), **args)

View file

@ -70,7 +70,8 @@ class TextLogger (linkcheck.logger.Logger):
"""
super(TextLogger, self).__init__(**args)
self.init_fileoutput(args)
self.fd = linkcheck.ansicolor.Colorizer(self.fd)
if self.fd is not None:
self.fd = linkcheck.ansicolor.Colorizer(self.fd)
self.colorparent = args['colorparent']
self.colorurl = args['colorurl']
self.colorname = args['colorname']
@ -84,6 +85,10 @@ class TextLogger (linkcheck.logger.Logger):
self.colordlsize = args['colordlsize']
self.colorreset = args['colorreset']
def start_fileoutput (self):
super(TextLogger, self).start_fileoutput()
self.fd = linkcheck.ansicolor.Colorizer(self.fd)
def start_output (self):
"""
Write generic start checking info.