~juju/ubuntu/quantal/juju/0.6

« back to all changes in this revision

Viewing changes to juju/charm/base.py

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-10-09 09:50:34 UTC
  • mto: (10.1.1 precise)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20111009095034-wqzww7z4tx2n0x43
Tags: upstream-0.5+bzr398
ImportĀ upstreamĀ versionĀ 0.5+bzr398

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from juju.errors import CharmError
 
2
 
 
3
 
 
4
def get_revision(file_content, metadata, path):
 
5
    if file_content is None:
 
6
        return metadata.obsolete_revision
 
7
    try:
 
8
        result = int(file_content.strip())
 
9
        if result >= 0:
 
10
            return result
 
11
    except (ValueError, TypeError):
 
12
        pass
 
13
    raise CharmError(path, "invalid charm revision %r" % file_content)
1
14
 
2
15
 
3
16
class CharmBase(object):
10
23
        raise NotImplementedError("%s.%s not supported" %
11
24
                                  (self.__class__.__name__, attr))
12
25
 
 
26
    def get_revision(self):
 
27
        """Get the revision, preferably from the revision file.
 
28
 
 
29
        Will fall back to metadata if not available.
 
30
        """
 
31
        self._unsupported("get_revision()")
 
32
 
 
33
    def set_revision(self, revision):
 
34
        """Update the revision file, if possible.
 
35
 
 
36
        Some subclasses may not be able to do this.
 
37
        """
 
38
        self._unsupported("set_revision()")
 
39
 
13
40
    def as_bundle(self):
14
41
        """Transform this charm into a charm bundle, if possible.
15
42