+#!/usr/bin/python
+# Copyright (c) 2016 Samsung Electronics Co., Ltd
+#
+# Licensed under the Flora License, Version 1.1 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://floralicense.org/license/
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Contributors:
+# - S-Core Co., Ltd
+
import logging
import requests
import re
# e.g., Convert http://a.com/a/ to https://a.com/a/blahblah.ks
# Works for file-indexing html
if ksURL[-3:].lower() != ".ks":
+ error = 0
if ksURL[-1:] != "/":
ksURL += "/"
r = requests.get(ksURL)
- m = re.search('>([^<]*\\.ks)\\s*<', r.text)
- if not m.group(1):
+ if r.status_code == requests.codes.ok:
+ m = re.search('>([^<]*\\.ks)\\s*<', r.text)
+ else:
+ error = 1
+ if error == 0 and not m.group(1):
m = re.search('"([^"]*\\.ks)\\s*"', r.text)
if not m.group(1):
m = re.search("'([^']*\\.ks)\\s*'", r.text)
if not m.group(1):
- node['icon'] = 'glyphicon glyphicon-remove-sign'
- node['tooltip'] = 'Cannot find image base from' + ksURL
- return node
+ error = 1
+ if error == 1:
+ node['icon'] = 'glyphicon glyphicon-remove-sign'
+ node['tooltip'] = 'Cannot find image base from' + ksURL
+ return node
ksURL += m.group(1)
node['tooltip'] = 'Image base from '+ksURL
node['ks'] = ksURL