3 # This file is part of Panucci.
4 # Copyright (c) 2008-2010 The Panucci Audiobook and Podcast Player Project
6 # Panucci is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # Panucci is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Panucci. If not, see <http://www.gnu.org/licenses/>.
20 from __future__
import absolute_import
29 from panucci
import platform
31 __log
= logging
.getLogger('panucci.util')
33 def convert_ns(time_int
):
34 time_int
= max( 0, int(time_int
) )
35 time_int
= time_int
/ 10**9
38 _hours
= time_int
/ 3600
39 time_int
= time_int
- (_hours
* 3600)
40 time_str
= str(_hours
) + ":"
43 time_int
= time_int
- (_mins
* 60)
44 time_str
= time_str
+ str(_mins
) + ":"
47 time_int
= time_int
- (_mins
* 60)
48 time_str
= time_str
+ "0" + str(_mins
) + ":"
50 time_str
= time_str
+ "00:"
52 time_str
= time_str
+ str(time_int
)
54 time_str
= time_str
+ "0" + str(time_int
)
58 def detect_filetype( filepath
):
59 if len(filepath
.split('.')) > 1:
60 filename
, extension
= filepath
.rsplit( '.', 1 )
61 return extension
.lower()
63 def pretty_filename( filename
):
64 filename
, extension
= os
.path
.basename(filename
).rsplit('.',1)
65 return filename
.replace('_', ' ')
67 def build_full_path( path
):
69 if path
.startswith('/'):
70 return os
.path
.abspath(path
)
72 return os
.path
.abspath( os
.path
.join(os
.getcwdu(), path
) )
74 def find_image(filename
):
75 locations
= ['./icons/', '../icons/', '/usr/share/panucci/',
76 os
.path
.dirname(sys
.argv
[0])+'/../icons/']
78 for location
in locations
:
79 if os
.path
.exists(location
+filename
):
80 return os
.path
.abspath(location
+filename
)
84 pynotify
.init('Panucci')
89 def notify( msg
, title
='Panucci' ):
90 """ Sends a notification using pynotify, returns msg """
91 if platform
.DESKTOP
and have_pynotify
:
92 icon
= find_image('panucci_64x64.png')
93 args
= ( title
, msg
) if icon
is None else ( title
, msg
, icon
)
94 notification
= pynotify
.Notification(*args
)
97 # Note: This won't work if we're not in the gtk main loop
98 markup
= '<b>%s</b>\n<small>%s</small>' % (title
, msg
)
100 hildon
.hildon_banner_show_information_with_markup(
101 gtk
.Label(''), None, markup
)
107 f
= '~/MyDocs/panucci.log'
111 return os
.path
.expanduser( f
)