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 future import standard_library
20 standard_library.install_aliases()
21 from builtins import object
22 import configparser
23 import logging
24 import os
25 
26 _SECTION = 'MAIN'
27 
28 
29 def _get_option_name(hw_uuid, host):
30  return '%s__%s' % (hw_uuid, host)
31 
32 
33 class _UuidDb(object):
34  def __init__(self, database_filename):
35  self._database_filename = database_filename
36  self._config = configparser.RawConfigParser()
38  if not self._config.has_section(_SECTION):
39  self._config.add_section(_SECTION)
40 
41  def _flush(self):
42  try:
43  smolt_user_config_dir = os.path.expanduser('~/.smolt/')
44  if not os.path.exists(smolt_user_config_dir):
45  os.mkdir(smolt_user_config_dir, 0o700)
46  f = open(self._database_filename, 'w')
47  self._config.write(f)
48  f.close()
49  except:
50  logging.error('Flushing UUID database failed')
51 
52  def get_pub_uuid(self, hw_uuid, host):
53  try:
54  pub_uuid = self._config.get(_SECTION, _get_option_name(hw_uuid, host))
55  logging.info('Public UUID "%s" read from database' % pub_uuid)
56  return pub_uuid
57  except configparser.NoOptionError:
58  return None
59 
60  def set_pub_uuid(self, hw_uuid, host, pub_uuid):
61  for i in (hw_uuid, host, pub_uuid):
62  if not i:
63  raise Exception('No parameter is allowed to be None')
64  self._config.set(_SECTION, _get_option_name(hw_uuid, host), pub_uuid)
65  logging.info('Public UUID "%s" written to database' % pub_uuid)
66  self._flush()
67 
68 
70  from smolt_config import get_config_attr
71  _database_filename = get_config_attr("UUID_DB", os.path.expanduser('~/.smolt/uuiddb.cfg'))
72  return _UuidDb(_database_filename)
hardwareprofile.uuiddb._UuidDb.__init__
def __init__(self, database_filename)
Definition: uuiddb.py:34
hardwareprofile.uuiddb._UuidDb._config
_config
Definition: uuiddb.py:36
hardwareprofile.uuiddb._UuidDb._flush
def _flush(self)
Definition: uuiddb.py:41
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:35
hardwareprofile.uuiddb._UuidDb.get_pub_uuid
def get_pub_uuid(self, hw_uuid, host)
Definition: uuiddb.py:52
hardwareprofile.uuiddb.create_default_uuiddb
def create_default_uuiddb()
Definition: uuiddb.py:69
hardwareprofile.uuiddb._UuidDb
Definition: uuiddb.py:33
hardwareprofile.uuiddb._UuidDb.set_pub_uuid
def set_pub_uuid(self, hw_uuid, host, pub_uuid)
Definition: uuiddb.py:60
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:29