~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to platform/windows-xul/plat/resources.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Miro - an RSS based video player application
2
 
# Copyright (C) 2005-2010 Participatory Culture Foundation
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17
 
#
18
 
# In addition, as a special exception, the copyright holders give
19
 
# permission to link the code of portions of this program with the OpenSSL
20
 
# library.
21
 
#
22
 
# You must obey the GNU General Public License in all respects for all of
23
 
# the code used other than OpenSSL. If you modify file(s) with this
24
 
# exception, you may extend this exception to your version of the file(s),
25
 
# but you are not obligated to do so. If you do not wish to do so, delete
26
 
# this exception statement from your version. If you delete this exception
27
 
# statement from all source files in the program, then also delete it here.
28
 
 
29
 
import os
30
 
import re
31
 
import sys
32
 
import urllib
33
 
import platform
34
 
 
35
 
from miro.plat import specialfolders
36
 
 
37
 
def appRoot():
38
 
    """Determine the directory the .exe file is located in.  Taken from the
39
 
    WhereAmI recipe on the py2exe website.
40
 
    """
41
 
    exe_path = unicode(sys.executable, sys.getfilesystemencoding())
42
 
    return os.path.dirname(exe_path)
43
 
 
44
 
def root():
45
 
    return os.path.join(appRoot(), 'resources')
46
 
 
47
 
def share_path(path):
48
 
    return os.path.join(root(), path)
49
 
 
50
 
# Note: some of these functions are probably not absolutely correct in
51
 
# the face of funny characters in the input paths. In particular,
52
 
# url() doesn't DTRT when the path contains spaces. But they should be
53
 
# sufficient for resolving resources, since we have control over the
54
 
# filenames.
55
 
 
56
 
# Find the full path to a resource data file. 'relative_path' is
57
 
# expected to be supplied in Unix format, with forward-slashes as
58
 
# separators. The output, though, uses the native platform separator.
59
 
def path(relative_path):
60
 
    abspath = os.path.abspath(os.path.join(root(), relative_path))
61
 
    return abspath.replace("/", "\\")
62
 
 
63
 
def url(relative_path):
64
 
    return absoluteUrl(path(relative_path))
65
 
 
66
 
def absoluteUrl(absolute_path):
67
 
    """Like url, but without adding the resource directory.
68
 
    """
69
 
    absolute_path = absolute_path.encode('utf_8')
70
 
    return u"file:///" + urllib.quote(absolute_path, safe=":~\\")
71
 
 
72
 
def _getThemeDirectory():
73
 
    # We don't get the publisher and long app name from the config so
74
 
    # changing the app name doesn't change the support directory
75
 
    path = os.path.join(specialfolders.commonAppDataDirectory,
76
 
                        u'Participatory Culture Foundation',
77
 
                        u'Miro',
78
 
                        u'Themes')
79
 
    try:
80
 
        os.makedirs(path)
81
 
    except:
82
 
        pass
83
 
    return path
84
 
 
85
 
def theme_path(theme, relative_path):
86
 
    return os.path.join(_getThemeDirectory(), theme, relative_path)
87
 
 
88
 
def get_osname():
89
 
    osname = '%s %s %s' % (platform.system(), platform.release(),
90
 
            platform.machine())
91
 
    return osname
92
 
 
93
 
def get_default_search_dir():
94
 
    return specialfolders.get_special_folder("My Videos")