~frankban/juju-quickstart/envs-backup

« back to all changes in this revision

Viewing changes to quickstart/models/envs.py

  • Committer: Francesco Banconi
  • Date: 2014-01-08 21:25:36 UTC
  • Revision ID: francesco.banconi@canonical.com-20140108212536-ylihhb7su8a41rcl
Checkpoint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
        return match.groups()[0]
130
130
 
131
131
 
 
132
def create(env_file):
 
133
    utils.mkdir(os.path.dirname(env_file))
 
134
    with open(env_file, 'w') as stream:
 
135
        serializers.yaml_dump({'environments': {}}, stream)
 
136
 
 
137
 
132
138
def load(env_file):
133
139
    """Load and parse the provided Juju environments.yaml file.
134
140
 
164
170
    except Exception as err:
165
171
        msg = b'unable to parse environments file {}: {}'
166
172
        raise ValueError(msg.format(env_file.encode('utf-8'), err))
 
173
    if contents is None:
 
174
        return {'environments': {}}
167
175
    # Retrieve the environment list.
168
176
    try:
169
177
        env_contents = contents.get('environments', {}).items()
245
253
    try:
246
254
        info = env_db['environments'][env_name]
247
255
    except KeyError:
248
 
        raise ValueError(b'environment {!r} not found'.format(env_name))
 
256
        msg = 'environment {} not found'.format(env_name)
 
257
        raise ValueError(msg.encode('utf-8'))
249
258
    # Why not just use env_data.copy()? Because this way internal mutable data
250
259
    # structures are preserved, even if they are unlikely to be found.
251
260
    env_data = copy.deepcopy(info)