Download this file

utils.py    80 lines (68 with data), 2.2 kB

 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
69
70
71
72
73
74
75
76
77
78
79
##########################################################################
# Copyright 2009 Carlos Ribeiro
#
# This file is part of Radio Tray
#
# Radio Tray 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 1 of the License, or
# (at your option) any later version.
#
# Radio Tray 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 Radio Tray. If not, see <http://www.gnu.org/licenses/>.
#
##########################################################################
from os.path import exists, join
try:
import pygtk
pygtk.require("2.0")
import dbus
import dbus.service
except:
pass
try:
import gtk
except ImportError, e:
print str(e)
raise SystemExit
def load_ui_file(name):
import common
ui = gtk.Builder()
ui.add_from_file(join(common.DEFAULT_CFG_PATH, name))
return ui
paths = ("/usr/local/share/radiotray","/usr/share/radiotray")
def tryopen(filename):
"""Returns a reading file handle for filename, searching through directories in the supplied paths."""
try:
f = open(filename)
return f
except IOError, e:
for p in paths:
try:
f = open(join(p,filename))
return f
except IOError, e:
0
raise IOError, "Unable to find file "+filename
def findfile(filename):
"""Looks for filename, searching a built-in list of directories; returns the path where it finds the file."""
if exists(filename): return filename
for p in paths:
x = join(p,filename)
print x
if exists(x): return x
def html_escape(text):
"""Produce entities within text."""
html_escape_table = {
"&": "&amp;",
'"': "&quot;",
"'": "&apos;",
">": "&gt;",
"<": "&lt;",
}
return "".join(html_escape_table.get(c,c) for c in text)