19 from builtins
import map
20 from builtins
import str
21 from builtins
import object
25 sys.path.extend(list(map(os.path.abspath, [
'../../'])))
26 from smolt_config
import get_config_attr
27 from request
import Request
33 return '%s__%s' % (hw_uuid, host)
54 self.
_config = configparser.RawConfigParser()
56 if not self.
_config.has_section(_SECTION):
57 self.
_config.add_section(_SECTION)
62 smolt_user_config_dir = os.path.expanduser(
'~/.smolt/')
63 if not os.path.exists(smolt_user_config_dir):
64 os.mkdir(smolt_user_config_dir, 0o700)
69 logging.error(
'Flushing UUID database failed')
74 logging.info(
'Public UUID "%s" read from database' % pub_uuid)
76 except configparser.NoOptionError:
79 pudict = json.loads(req.open().
read())
81 return pudict[
'pub_uuid']
82 except Exception
as e:
83 error(
_(
'Error determining public UUID: %s') % e)
84 sys.stderr.write(
_(
"Unable to determine Public UUID! This could be a network error or you've\n"))
85 sys.stderr.write(
_(
"not submitted your profile yet.\n"))
89 for i
in (hw_uuid, host, pub_uuid):
91 raise Exception(
'No parameter is allowed to be None')
93 logging.info(
'Public UUID "%s" written to database' % pub_uuid)
98 with open(
'/proc/sys/kernel/random/uuid')
as rand_uuid:
99 rand_uuid_string = rand_uuid.read().strip()
100 return rand_uuid_string
106 raise UUIDError(
'Could not generate new UUID!')
114 self.
hw_uuid = hwuuidfile.read().strip()
119 raise UUIDError(
'Unable to determine UUID of system!')
124 except Exception
as e:
129 _uuid_db_instance =
None
131 """Simple singleton wrapper with lazy initialization"""
132 global _uuid_db_instance
133 if _uuid_db_instance
is None:
135 from smolt
import get_config_attr
137 return _uuid_db_instance