Skip to content

Commit

Permalink
Merge 493844e into 21c162e
Browse files Browse the repository at this point in the history
  • Loading branch information
p0358 committed Dec 2, 2017
2 parents 21c162e + 493844e commit 0de46df
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,8 @@ Changelog
-------------------

- Support Python 3.6.
- Fix for duplicated lines with the same time where the resulting HTML ``id`` anchors would evolve into long form like "t22:24:49-2-3-4-5-6-7-8-9-10" instead of "t22:24:49-10" resulting in significant output file sizes grow in some cases
- Add --output-dir (-o) parameter to logs2html allowing to place resulting files in a directory different from input catalogue


2.15.3 (2016-12-08)
Expand Down
3 changes: 2 additions & 1 deletion src/irclog2html/irclog2html.py
Expand Up @@ -416,8 +416,9 @@ def nicktext(self, time, nick, text, htmlcolour):
def timestamp_anchor(self, time):
anchor = 't%s' % time
if anchor in self._anchors:
org_anchor = anchor
for n in itertools.count(2):
anchor = '%s-%d' % (anchor, n)
anchor = '%s-%d' % (org_anchor, n)
if anchor not in self._anchors:
break
self._anchors.add(anchor)
Expand Down
25 changes: 21 additions & 4 deletions src/irclog2html/logs2html.py
Expand Up @@ -74,7 +74,7 @@ def __ne__(self, other):
def newfile(self):
"""Check whether the log file is new.
The log file is new iff the corresponding html file does not exist
The log file is new if the corresponding html file does not exist
or was just generated by self.generate. This implies that navigation
links for the previous/next file need to be updated.
"""
Expand Down Expand Up @@ -211,6 +211,9 @@ def main(argv=sys.argv):
parser.add_option('-g', '--glob-pattern', dest="pattern", default="*.log",
help="glob pattern that finds log files to be processed"
" (default: *.log)")
parser.add_option('-o', '--output-dir', dest="output_dir", default=None,
help="destination output directory"
" (default: same as input directory)")
options, args = parser.parse_args(argv[1:])
if len(args) < 1:
parser.error("missing directory name")
Expand All @@ -231,6 +234,20 @@ def process(dir, options):
extra_args += ['-S']
if options.dircproxy:
extra_args += ['--dircproxy']
if options.output_dir:
if os.path.isdir(options.output_dir):
extra_args += ['--output-file', options.output_dir]
out_dir = options.output_dir
else:
if os.path.isfile(options.output_dir):
raise Error("%s is a file" % options.output_dir)
else:
try:
os.makedirs(options.output_dir)
except Error as e:
sys.exit("Failed to recursively create directory %s: %s" % (options.output_dir, e))
else:
out_dir = dir
logfiles = find_log_files(dir, options.pattern)
logfiles.reverse() # newest first
for n, logfile in enumerate(logfiles):
Expand All @@ -249,8 +266,8 @@ def process(dir, options):
latest_log_link = None
if logfiles and hasattr(os, "symlink"):
latest_log_link = 'latest.log.html'
move_symlink(logfiles[0].link, os.path.join(dir, latest_log_link))
outfilename = os.path.join(dir, 'index.html')
move_symlink(logfiles[0].link, os.path.join(out_dir, latest_log_link))
outfilename = os.path.join(out_dir, 'index.html')
try:
outfile = open(outfilename, 'w')
except IOError as e:
Expand All @@ -260,7 +277,7 @@ def process(dir, options):
latest_log_link)
finally:
outfile.close()
css_file = os.path.join(dir, 'irclog.css')
css_file = os.path.join(out_dir, 'irclog.css')
if not os.path.exists(css_file) and os.path.exists(CSS_FILE):
shutil.copy(CSS_FILE, css_file)

Expand Down
6 changes: 3 additions & 3 deletions src/irclog2html/tests/test_logs2html.py
Expand Up @@ -150,7 +150,7 @@ def test_process(self):
self.create('somechannel-20130318.log')
options = optparse.Values(dict(searchbox=True, dircproxy=True,
pattern='*.log', force=False,
prefix='IRC logs for ',
prefix='IRC logs for ', output_dir=None,
style='xhtmltable', title='IRC logs'))
process(self.tmpdir, options)
self.assertTrue(os.path.exists(self.filename('index.html')))
Expand All @@ -169,7 +169,7 @@ def test_process_copies_css_even_when_all_logs_up_to_date(self):
self.create('somechannel-20130316.log.html')
options = optparse.Values(dict(searchbox=True, dircproxy=True,
pattern='*.log', force=False,
prefix='IRC logs for ',
prefix='IRC logs for ', output_dir=None,
style='xhtmltable', title='IRC logs'))
process(self.tmpdir, options)
self.assertTrue(os.path.exists(self.filename('index.html')))
Expand All @@ -183,7 +183,7 @@ def test_process_handles_write_errors(self):
self.create('index.html')
options = optparse.Values(dict(searchbox=True, dircproxy=True,
pattern='*.log', force=False,
prefix='IRC logs for ',
prefix='IRC logs for ', output_dir=None,
style='xhtmltable', title='IRC logs'))
os.chmod(self.filename('index.html'), 0o444)
self.assertRaises(Error, process, self.tmpdir, options)
Expand Down

0 comments on commit 0de46df

Please sign in to comment.