1 | #============================================================================ |
---|
2 | # This library is free software; you can redistribute it and/or |
---|
3 | # modify it under the terms of version 2.1 of the GNU Lesser General Public |
---|
4 | # License as published by the Free Software Foundation. |
---|
5 | # |
---|
6 | # This library is distributed in the hope that it will be useful, |
---|
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
9 | # Lesser General Public License for more details. |
---|
10 | # |
---|
11 | # You should have received a copy of the GNU Lesser General Public |
---|
12 | # License along with this library; if not, write to the Free Software |
---|
13 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
14 | #============================================================================ |
---|
15 | # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com> |
---|
16 | #============================================================================ |
---|
17 | |
---|
18 | import os |
---|
19 | |
---|
20 | def getenv(var, val, conv=None): |
---|
21 | """Get a value from the environment, with optional conversion. |
---|
22 | |
---|
23 | @param var name of environment variable |
---|
24 | @param val default value |
---|
25 | @param conv conversion function to apply to env value |
---|
26 | @return converted value or default |
---|
27 | """ |
---|
28 | try: |
---|
29 | v = os.getenv(var) |
---|
30 | if v is None: |
---|
31 | v = val |
---|
32 | else: |
---|
33 | print var, '=', v |
---|
34 | if conv: |
---|
35 | v = conv(v) |
---|
36 | except: |
---|
37 | v = val |
---|
38 | return v |
---|
39 | |
---|
40 | # The following parameters could be placed in a configuration file. |
---|
41 | XEND_PID_FILE = '/var/run/xend.pid' |
---|
42 | XEND_TRACE_FILE = '/var/log/xen/xend.trace' |
---|
43 | XEND_DEBUG_LOG = '/var/log/xen/xend-debug.log' |
---|
44 | XEND_USER = 'root' |
---|
45 | XEND_DEBUG = getenv("XEND_DEBUG", 0, conv=int) |
---|
46 | XEND_DAEMONIZE = getenv("XEND_DAEMONIZE", not XEND_DEBUG, conv=int) |
---|