From 729bfcc52c1db17d70b3643489464fda2aaee7f9 Mon Sep 17 00:00:00 2001 From: Leo Ju Date: Mon, 9 Sep 2013 01:39:03 +0900 Subject: [PATCH] Add a script to add Dash docset with feed URL --- bin/dash-add-docset.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/dash-add-docset.py diff --git a/bin/dash-add-docset.py b/bin/dash-add-docset.py new file mode 100755 index 0000000..c86085a --- /dev/null +++ b/bin/dash-add-docset.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import re +import sys +import urllib + +regex = re.compile( + r'^(?:http|ftp)s?://' # http:// or https:// + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)' + '+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain + r'localhost|' # localhost... + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip + r'(?::\d+)?' # optional port + r'(?:/?|[/?]\S+)$', re.IGNORECASE) + +if len(sys.argv) != 2 or not regex.match(sys.argv[1]): + print "%s requires a valid URL parameter." % sys.argv[0] + sys.exit(1) +else: + os.system('open dash-feed://%s' % urllib.quote(sys.argv[1], '')) + sys.exit(0)