root/trunk/umit/core/Utils.py @ 4376

Revision 4376, 2.2 kB (checked in by gpolo, 4 years ago)

Added utility function to correctly get the desired value of UMIT_DEVELOPMENT env var.

Line 
1# Copyright (C) 2007 Adriano Monteiro Marques
2#
3# Authors: Guilherme Polo <ggpolo@gmail.com>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18# USA
19
20import os
21import sys
22import errno
23import platform
24
25# Check if we are on win32
26WIN32 = bool(platform.win32_ver()[0])
27
28# Check if we are on Maemo
29MAEMO = False
30try:
31    import hildon
32    MAEMO = True
33except ImportError:
34    pass
35
36def development_mode(default=True):
37    """
38    Returns True if the environment var UMIT_DEVELOPMENT is set to true,
39    'true' (case insensitive) or some number different than 0 are considered
40    as true, False otherwise.
41
42    If the env var is not set, then the default value governs the return
43    value. If you want UMIT_DEVELOPMENT to be True by default, call this
44    function with default=True (default).
45    """
46    val = os.environ.get('UMIT_DEVELOPMENT', default)
47    try:
48        val = int(val)
49    except ValueError:
50        if val.lower() == 'true':
51            return True
52    else:
53        if val:
54            return True
55
56    return False
57
58
59def is_maemo():
60    """
61    Returns True in case we are on Maemo, otherwise, False.
62    """
63    return MAEMO
64
65
66def amiroot():
67    """
68    Checks if root is around ;)
69    """
70    root = False
71    try:
72        if WIN32:
73            root = True
74        elif is_maemo():
75            root = True
76        elif os.getuid() == 0:
77            root = True
78    except: # XXX
79        pass
80
81    return root
82
83
84def open_url_as():
85    """
86    If python ver >= 2.5, will open help pages in a new tab.
87    """
88    tab = 0
89    if sys.hexversion >= 0x2050000:
90        tab = 2
91
92    return tab
Note: See TracBrowser for help on using the browser.