linkchecker/linkcheck/gui/urlsave.py

60 lines
1.9 KiB
Python
Raw Normal View History

2010-11-26 20:23:27 +00:00
# -*- coding: iso-8859-1 -*-
2011-02-11 13:00:31 +00:00
# Copyright (C) 2010-2011 Bastian Kleineidam
2010-11-26 20:23:27 +00:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
from PyQt4 import QtGui
LoggerFilters = ";;".join((
_("HTML output (*.html)"),
_("Text output (*.txt)"),
_("XML output (*.xml)"),
_("CSV output (*.csv)"),
2010-11-26 20:23:27 +00:00
))
FileExt2LogType = {
".html": "html",
".txt": "text",
".xml": "xml",
".csv": "csv",
2010-11-26 20:23:27 +00:00
}
def urlsave (parent, config, urls):
"""Save URL results in file."""
2011-12-29 05:52:48 +00:00
filename = get_save_filename(parent)
2011-12-20 19:53:49 +00:00
if not filename:
2011-02-09 06:42:36 +00:00
# user canceled
2010-11-26 20:23:27 +00:00
return
2011-12-29 05:52:48 +00:00
filename = unicode(filename)
2010-11-26 20:23:27 +00:00
logtype = FileExt2LogType.get(os.path.splitext(filename)[1])
if not logtype:
return
kwargs = dict(fileoutput=1, filename=filename, encoding="utf_8_sig")
logger = config.logger_new(logtype, **kwargs)
logger.start_output()
for urlitem in urls:
do_print = True
logger.log_filter_url(urlitem.url_data, do_print)
2010-11-26 20:23:27 +00:00
logger.end_output()
2011-02-09 06:42:36 +00:00
2011-03-19 16:02:15 +00:00
def get_save_filename (parent):
2011-02-17 18:59:02 +00:00
"""Open file save dialog for given parent window and base directory.
Return dialog result."""
2011-02-09 06:42:36 +00:00
filename = "linkchecker-out.html"
title = _("Save check results")
func = QtGui.QFileDialog.getSaveFileName
return func(parent, title, filename, LoggerFilters)