-
Notifications
You must be signed in to change notification settings - Fork 0
/
noplugin.py
executable file
·68 lines (55 loc) · 1.57 KB
/
noplugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# File name: noscript.py
# Author: Viator (viator@via-net.org)
# License: GPL (see http://www.gnu.org/licenses/gpl.txt)
# Created: 2010-09-27
# Description:
# TODO:
import sys
import os
from urlparse import urlparse
def xdghome(key, default):
'''Attempts to use the environ XDG_*_HOME paths if they exist otherwise
use $HOME and the default path.'''
xdgkey = "XDG_%s_HOME" % key
if xdgkey in os.environ.keys() and os.environ[xdgkey]:
return os.environ[xdgkey]
return os.path.join(os.environ['HOME'], default)
def get_domain(url):
'''Return domain segment of url.'''
if not url.startswith('http'):
url = "http://%s" % url
loc = urlparse(url).netloc
if loc.startswith('www.'):
loc = loc[4:]
return loc
def parse_config():
DATA_DIR = os.path.join(xdghome('DATA', '.local/share/'), 'uzbl/')
VALIDDOMAIN = os.path.join(DATA_DIR, 'pluginon')
try:
domains = open(VALIDDOMAIN, 'r').read().split('\n')
except:
domains = []
return domains
def main(url, fifo):
domains = parse_config()
domain = get_domain(url)
try:
fh = open(fifo, "w")
except:
sys.stdout.write(fifo+' can\' be write')
return
if domain in domains:
fh.write('set disable_plugins = 0\n')
else:
fh.write('set disable_plugins = 1\n')
fh.close()
if __name__ == "__main__":
url = sys.argv[6]
fifo = sys.argv[4]
#url = 'http://www.ya.ru/'
#fifo = '/tmp/test'
main(url, fifo)
# vi: ts=4