MythTV  master
uuiddb.py
Go to the documentation of this file.
1 # smolt - Fedora hardware profiler
2 #
3 # Copyright (C) 2009 Sebastian Pipping <sebastian@pipping.org>
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19 from builtins import object
20 import configparser
21 import logging
22 import os
23 
24 _SECTION = 'MAIN'
25 
26 
27 def _get_option_name(hw_uuid, host):
28  return '%s__%s' % (hw_uuid, host)
29 
30 
31 class _UuidDb(object):
32  def __init__(self, database_filename):
33  self._database_filename = database_filename
34  self._config = configparser.RawConfigParser()
36  if not self._config.has_section(_SECTION):
37  self._config.add_section(_SECTION)
38 
39  def _flush(self):
40  try:
41  smolt_user_config_dir = os.path.expanduser('~/.smolt/')
42  if not os.path.exists(smolt_user_config_dir):
43  os.mkdir(smolt_user_config_dir, 0o700)
44  f = open(self._database_filename, 'w')
45  self._config.write(f)
46  f.close()
47  except:
48  logging.error('Flushing UUID database failed')
49 
50  def get_pub_uuid(self, hw_uuid, host):
51  try:
52  pub_uuid = self._config.get(_SECTION, _get_option_name(hw_uuid, host))
53  logging.info('Public UUID "%s" read from database' % pub_uuid)
54  return pub_uuid
55  except configparser.NoOptionError:
56  return None
57 
58  def set_pub_uuid(self, hw_uuid, host, pub_uuid):
59  for i in (hw_uuid, host, pub_uuid):
60  if not i:
61  raise Exception('No parameter is allowed to be None')
62  self._config.set(_SECTION, _get_option_name(hw_uuid, host), pub_uuid)
63  logging.info('Public UUID "%s" written to database' % pub_uuid)
64  self._flush()
65 
66 
68  from smolt_config import get_config_attr
69  _database_filename = get_config_attr("UUID_DB", os.path.expanduser('~/.smolt/uuiddb.cfg'))
70  return _UuidDb(_database_filename)
hardwareprofile.uuiddb._UuidDb.__init__
def __init__(self, database_filename)
Definition: uuiddb.py:32
hardwareprofile.uuiddb._UuidDb._config
_config
Definition: uuiddb.py:34
hardwareprofile.uuiddb._UuidDb._flush
def _flush(self)
Definition: uuiddb.py:39
discid.disc.read
def read(device=None, features=[])
Definition: disc.py:35
mythburn.write
def write(text, progress=True)
Definition: mythburn.py:308
hardwareprofile.uuiddb._UuidDb._database_filename
_database_filename
Definition: uuiddb.py:33
hardwareprofile.uuiddb._UuidDb.get_pub_uuid
def get_pub_uuid(self, hw_uuid, host)
Definition: uuiddb.py:50
hardwareprofile.uuiddb.create_default_uuiddb
def create_default_uuiddb()
Definition: uuiddb.py:67
hardwareprofile.uuiddb._UuidDb
Definition: uuiddb.py:31
hardwareprofile.uuiddb._UuidDb.set_pub_uuid
def set_pub_uuid(self, hw_uuid, host, pub_uuid)
Definition: uuiddb.py:58
hardwareprofile.smolt_config.get_config_attr
def get_config_attr(attr, default="")
Definition: smolt_config.py:22
hardwareprofile.distros.all.get
def get()
Definition: all.py:22
hardwareprofile.uuiddb._get_option_name
def _get_option_name(hw_uuid, host)
Definition: uuiddb.py:27