summaryrefslogtreecommitdiffstats
path: root/cobbler/config.py
blob: 470b57cc4b13a5a7502ddb57a83ae7526db8d6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Config.py is a repository of the Cobbler object model

Michael DeHaan <mdehaan@redhat.com>
"""

import os
import weakref

import item_distro as distro
import item_profile as profile
import item_system as system

import collection_distros as distros
import collection_profiles as profiles
import collection_systems as systems

import settings
import serializer

class Config:

   def __init__(self):
       # manage a definitive copy of all data collections with weakrefs
       # back here so they can understand each other
       self._distros      = distros.Distros(weakref.proxy(self))
       self._profiles     = profiles.Profiles(weakref.proxy(self))
       self._systems      = systems.Systems(weakref.proxy(self))
       self._settings     = settings.Settings() # not a true collection
       self._classes = [
          self._distros,
          self._profiles,
          self._systems,
          self._settings,
       ]
       self.file_check()

   def distros(self):
       return self._distros

   def profiles(self):
       return self._profiles

   def systems(self):
       return self._systems

   def settings(self):
       return self._settings

   def new_distro(self):
       return distro.Distro(weakref.proxy(self))

   def new_system(self):
       return system.System(weakref.proxy(self))

   def new_profile(self):
       return profile.Profile(weakref.proxy(self))

   def clear(self):
       for x in self._classes:
          x.clear()

   def file_check(self):
       for x in self._classes:
          if not os.path.exists(x.filename()):
              serializer.serialize(x)

   def serialize(self):
       for x in self._classes:
          serializer.serialize(x)

   def deserialize(self):
       for x in self._classes:
          serializer.deserialize(x)