2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # pick some current environment infos
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright (C) 2013 AIT Austrian Institute of Technology
12 # AIT Austrian Institute of Technology GmbH
13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
14 # http://www.ait.ac.at
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation version 2.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 # Boston, MA 02110-1301, USA.
29 # ------------------------------------------------------------
32 # ------------------------------------------------------------
40 # ------------------------------------------------------------
44 class Environment(object):
46 """Hold some nifty environment stuff in a dedicated class."""
48 def __init__(self, application = None):
50 # if we ain't got a path to start from, all is valid/lost
51 if len(sys.path[0]) == 0:
59 # - on Linux: this is ../../ to the current executable
60 # e.g. "/usr/bin/myprogram" --> "/usr"
62 # - on Windows: this is the installation folder
63 # e.g. "C:/Program Files/MyProgram/bin/myprogam" --> "C:/Program Files/MyProgram"
65 if sys.platform == 'linux2':
66 self.prefix_path = os.path.split(sys.path[0])[0]
67 elif sys.platform == 'win32':
68 self.prefix_path = os.path.split(sys.path[0])[0]
70 # the data path where all data files are stored
71 if sys.platform == 'linux2':
72 if not application is None:
73 self.data_path = os.path.join(self.prefix_path, os.path.join('share', application))
75 self.data_path = os.path.join(self.prefix_path, 'share')
76 elif sys.platform == 'win32':
77 self.data_path = self.prefix_path
80 if sys.platform == 'linux2':
81 self.image_path = os.path.join(self.data_path, 'gfx')
82 elif sys.platform == 'win32':
83 self.image_path = os.path.join(self.data_path, 'gfx')
88 """Module test call."""
90 e = Environment("opensecurity")
91 print("prefix_path: {0}".format(e.prefix_path))
92 print(" data_path: {0}".format(e.data_path))
93 print(" image_path: {0}".format(e.image_path))
95 # standalone calls are module tests
96 if __name__ == '__main__':