~free.ekanayaka/landscape-client/jaunty-updates-1.4.4-0ubuntu0.9.04

« back to all changes in this revision

Viewing changes to landscape/lib/persist.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2009-09-21 17:59:31 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090921175931-4ucv40j9ro26i3lm
Tags: 1.3.2.3-0ubuntu0.9.04.0
* New upstream release (LP: #347983):
  - Don't clear the hash_id_requests table upon resynchronize (LP #417122)
  - Include the README file in landscape-client (LP: #396260)
  - Fix client capturing stderr from run_command when constructing
    hash-id-databases url (LP: #397480)
  - Use substvars to conditionally depend on update-motd or
    libpam-modules (LP: #393454)
  - Fix reporting wrong version to the server (LP: #391225)
  - The init script does not wait for the network to be available
    before checking for EC2 user data (LP: #383336)
  - When the broker is restarted by the watchdog, the state of the client
    is inconsistent (LP: #380633)
  - Package stays unknown forever in the client with hash-id-databases
    support (LP: #381356)
  - Standard error not captured when calling smart-update (LP: #387441)
  - Changer calls reporter without switching groups, just user (LP: #388092)
  - Run smart update in the package-reporter instead of having a cronjob (LP: #362355)
  - Package changer does not inherit proxy settings (LP: #381241)
  - The ./test script doesn't work in landscape-client (LP: #381613)
  - The source package should build on all supported releases (LP: #385098)
  - Strip smart update's output (LP: #387331)
  - The fetch() timeout isn't based on activity (#389224)
  - Client can use a UUID of "None" when fetching the hash-id-database (LP: #381291)
  - Registration should use the fqdn rather than just the hostname (LP: #385730)

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
 
42
42
class Persist(object):
43
 
    """Persistence handler.
 
43
 
 
44
    """Persist a hierarchical database of key=>value pairs.
44
45
 
45
46
    There are three different kinds of opition maps, regarding the
46
47
    persistence and priority that maps are queried.
47
48
 
48
 
    hard - Options are persistent.
49
 
    soft - Options are not persistent, and have a higher priority
 
49
      - hard - Options are persistent.
 
50
      - soft - Options are not persistent, and have a higher priority
50
51
           than persistent options.
51
 
    weak - Options are not persistent, and have a lower priority
 
52
      - weak - Options are not persistent, and have a lower priority
52
53
           than persistent options.
53
54
 
54
55
    @ivar filename: The name of the file where persist data is saved
55
 
        or None if not filename is available.
 
56
        or None if no filename is available.
 
57
 
56
58
    """
57
59
 
58
 
 
59
60
    def __init__(self, backend=None, filename=None):
60
61
        """
61
62
        @param backend: The backend to use. If none is specified,
91
92
    modified = property(_get_modified)
92
93
 
93
94
    def reset_modified(self):
 
95
        """Set the database status as non-modified."""
94
96
        self._modified = False
95
97
 
96
98
    def assert_writable(self):
 
99
        """Assert if the object is writable
 
100
 
 
101
        @raise: L{PersistReadOnlyError}
 
102
        """
97
103
        if self._readonly:
98
104
            raise PersistReadOnlyError("Configuration is in readonly mode.")
99
105
 
100
106
    def load(self, filepath):
 
107
        """Load a persisted database."""
101
108
        filepath = os.path.expanduser(filepath)
102
109
        if not os.path.isfile(filepath):
103
110
            raise PersistError("File not found: %s" % filepath)
313
320
        return result
314
321
 
315
322
    def root_at(self, path):
 
323
        """
 
324
        Rebase the database hierarchy.
 
325
 
 
326
        @return: A L{RootedPersist} using this L{Persist} as parent.
 
327
        """
316
328
        return RootedPersist(self, path)
317
329
 
318
330
 
319
331
class RootedPersist(object):
 
332
    """Root a L{Persist}'s tree at a particular branch.
 
333
 
 
334
    This class shares the same interface of L{Persist} and provides a shortcut
 
335
    to access the nodes of a particular branch in a L{Persist}'s tree.
 
336
 
 
337
    The chosen branch will be viewed as the root of the tree of the
 
338
    L{RootedPersist} and all operations will be forwarded to the parent
 
339
    L{Persist} as appropriate.
 
340
    """
320
341
 
321
342
    def __init__(self, parent, root):
 
343
        """
 
344
        @param parent: the parent L{Persist}.
 
345
        @param root: a branch of the parent L{Persist}'s tree, that
 
346
            will be used as root of this L{RootedPersist}.
 
347
        """
322
348
        self.parent = parent
323
349
        if type(root) is str:
324
350
            self.root = path_string_to_tuple(root)