~brianlbaird/charms/trusty/pcrf/trunk

« back to all changes in this revision

Viewing changes to lib/charms/docker/workspace.py

  • Committer: brianlbaird at gmail
  • Date: 2016-02-05 22:23:46 UTC
  • Revision ID: brianlbaird@gmail.com-20160205222346-4mv1208rduhngpbu
update pcrf relation in metadata

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
class Workspace:
 
4
    '''
 
5
    Docker workspaces are unique in our world, as they can be one of two context
 
6
    dependent things: A Docker build directory, containing only a single
 
7
    Dockerfile, or they can be part of a formation using docker-compose in which
 
8
    they warehouse a docker-compose.yml file.
 
9
 
 
10
    Under most situations we only care about the context the charm author wishes
 
11
    to be in, and what implications that has on the workspace to be valid.
 
12
 
 
13
    This method simply exposes an overrideable object to determine these
 
14
    characteristics.
 
15
    '''
 
16
    def __init__(self, path, context="compose"):
 
17
        self.path = path
 
18
        self.context = context
 
19
 
 
20
    def __str__(self):
 
21
        return self.path
 
22
 
 
23
    def __repr__(self):
 
24
        return self.path
 
25
 
 
26
    def validate(self):
 
27
        dcyml = os.path.isfile("{}/docker-compose.yml".format(self.path))
 
28
        dcyaml = os.path.isfile("{}/docker-compose.yaml".format(self.path))
 
29
        dfile = os.path.isfile("{}/Dockerfile".format(self.path))
 
30
 
 
31
        if self.context == "compose":
 
32
            if not dcyml and not dcyaml:
 
33
                msg = "Missing yaml definition: docker-compose.yml"
 
34
                raise OSError(msg)
 
35
        else:
 
36
            if not dfile:
 
37
                msg = "Missing Dockerfile"
 
38
                raise OSError(msg)
 
39
        return True