Revision f6d137ea kamaki/cli.py

b/kamaki/cli.py
70 70

  
71 71
import inspect
72 72
import logging
73
import os
74 73
import sys
75 74

  
76 75
from argparse import ArgumentParser
77 76
from base64 import b64encode
78
from grp import getgrgid
79 77
from os.path import abspath, basename, exists
80
from pwd import getpwuid
81 78
from sys import exit, stdout, stderr
82 79

  
83 80
from colors import magenta, red, yellow
......
222 219
                          action='append', default=[],
223 220
                          metavar='PATH[,SERVER PATH[,OWNER[,GROUP,[MODE]]]]',
224 221
                          help='add a personality file')
225
        parser.epilog = ("If missing, optional personality values will be "
226
                        "filled based on the file at PATH.")
227 222

  
228 223
    def main(self, name, flavor_id, image_id):
229 224
        personalities = []
......
242 237
            
243 238
            with open(path) as f:
244 239
                contents = b64encode(f.read())
245
            
246
            st = os.stat(path)
247
            personalities.append({
248
                'path': p[1] or abspath(path),
249
                'owner': p[2] or getpwuid(st.st_uid).pw_name,
250
                'group': p[3] or getgrgid(st.st_gid).gr_name,
251
                'mode': int(p[4]) if p[4] else 0x7777 & st.st_mode,
252
                'contents': contents})
253
        
240

  
241
            d = {'path': p[1] or abspath(path), 'contents': contents}
242
            if p[2]:
243
                d['owner'] = p[2]
244
            if p[3]:
245
                d['group'] = p[3]
246
            if p[4]:
247
                d['mode'] = int(p[4])
248
            personalities.append(d)
249

  
254 250
        reply = self.client.create_server(name, int(flavor_id), image_id,
255 251
                personalities)
256 252
        print_dict(reply)

Also available in: Unified diff