Added more simple url validation.
This commit is contained in:
parent
c0912367f9
commit
c0a7127247
2 changed files with 17 additions and 12 deletions
14
main.py
14
main.py
|
|
@ -7,6 +7,7 @@ import sys
|
||||||
import codecs
|
import codecs
|
||||||
import platform
|
import platform
|
||||||
import requests
|
import requests
|
||||||
|
import validators
|
||||||
|
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
from PySide.QtGui import QApplication, QHBoxLayout, QVBoxLayout
|
from PySide.QtGui import QApplication, QHBoxLayout, QVBoxLayout
|
||||||
|
|
@ -22,8 +23,9 @@ from utils import get_data_path, get_data_file_path
|
||||||
MAX_RECENT = 10
|
MAX_RECENT = 10
|
||||||
|
|
||||||
def url_exists(path):
|
def url_exists(path):
|
||||||
r = requests.head(path)
|
if validators.url(path):
|
||||||
return r.status_code == requests.codes.ok
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class Validator(QtGui.QRegExpValidator):
|
class Validator(QtGui.QRegExpValidator):
|
||||||
def __init__(self, regex, action, parent=None):
|
def __init__(self, regex, action, parent=None):
|
||||||
|
|
@ -340,14 +342,16 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
||||||
|
|
||||||
if (setting.type == 'file' and
|
if (setting.type == 'file' and
|
||||||
setting.value and
|
setting.value):
|
||||||
(not os.path.exists(setting_path) and not url_exists(setting.value))):
|
setting_path_invalid = not os.path.exists(setting_path)
|
||||||
|
setting_url_invalid = not url_exists(setting.value)
|
||||||
|
if setting_path_invalid and setting_url_invalid:
|
||||||
log(setting.value, "does not exist")
|
log(setting.value, "does not exist")
|
||||||
settings_valid = False
|
settings_valid = False
|
||||||
widget = self.find_child_by_name(setting.name)
|
widget = self.find_child_by_name(setting.name)
|
||||||
if widget is not None:
|
if widget is not None:
|
||||||
widget.setStyleSheet(red_border)
|
widget.setStyleSheet(red_border)
|
||||||
widget.setToolTip(u'The file "{}" does not exist.'.format(os.path.join(self.project_dir(),setting.value)))
|
widget.setToolTip(u'The file or url "{}" does not exist.'.format(setting.value))
|
||||||
tab = self.get_tab_index_for_setting_name(setting.name)
|
tab = self.get_tab_index_for_setting_name(setting.name)
|
||||||
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@ pyside
|
||||||
configobj
|
configobj
|
||||||
semantic_version
|
semantic_version
|
||||||
appdirs
|
appdirs
|
||||||
|
validators
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue