| Server IP : 182.53.201.61 / Your IP : 216.73.217.175 Web Server : Apache/2.2.15 (Fedora) System : Linux km10.dyndns.org 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686 User : apache ( 48) PHP Version : 5.3.3 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/smolt/client/ |
Upload File : |
# smolt - Fedora hardware profiler
#
# Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
import ConfigParser
import logging
import os
_SECTION = 'MAIN'
def _get_option_name(hw_uuid, host):
return '%s__%s' % (hw_uuid, host)
class _UuidDb:
def __init__(self, database_filename):
self._database_filename = database_filename
self._config = ConfigParser.RawConfigParser()
self._config.read(self._database_filename)
if not self._config.has_section(_SECTION):
self._config.add_section(_SECTION)
def _flush(self):
try:
smolt_user_config_dir = os.path.expanduser('~/.smolt/')
if not os.path.exists(smolt_user_config_dir):
os.mkdir(smolt_user_config_dir, 0700)
f = open(self._database_filename, 'w')
self._config.write(f)
f.close()
except:
logging.error('Flushing UUID database failed')
def get_pub_uuid(self, hw_uuid, host):
try:
pub_uuid = self._config.get(_SECTION, _get_option_name(hw_uuid, host))
logging.info('Public UUID "%s" read from database' % pub_uuid)
return pub_uuid
except ConfigParser.NoOptionError:
return None
def set_pub_uuid(self, hw_uuid, host, pub_uuid):
for i in (hw_uuid, host, pub_uuid):
if not i:
raise Exception('No paramater allowed to be None.')
self._config.set(_SECTION, _get_option_name(hw_uuid, host), pub_uuid)
logging.info('Public UUID "%s" written to database' % pub_uuid)
self._flush()
_uuid_db_instance = None
def UuidDb():
"""Simple singleton wrapper with lazy initialization"""
global _uuid_db_instance
if _uuid_db_instance == None:
_uuid_db_instance = _UuidDb(os.path.expanduser('~/.smolt/uuiddb.cfg'))
return _uuid_db_instance