Revision 023e1217 image_creator/dialog_wizard.py

b/image_creator/dialog_wizard.py
40 40
from image_creator.kamaki_wrapper import Kamaki, ClientError
41 41
from image_creator.util import MD5, FatalError
42 42
from image_creator.output.cli import OutputWthProgress
43
from image_creator.dialog_util import extract_image, update_background_title
43 44

  
44 45
PAGE_WIDTH = 70
45 46

  
......
100 101
            choices.append((self.choices[i][0], self.choices[i][1], default))
101 102

  
102 103
        while True:
103
            (code, answer) = d.radiolist(self.message, width=PAGE_WIDTH,
104
                ok_label="Next", cancel="Back", choices=choices,
105
                title="(%d/%d) %s" % (index + 1, total, self.title))
104
            (code, answer) = \
105
                d.radiolist(self.message, width=PAGE_WIDTH,
106
                            ok_label="Next", cancel="Back", choices=choices,
107
                            title="(%d/%d) %s" % (index + 1, total, self.title)
108
                            )
106 109

  
107 110
            if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
108 111
                return self.PREV
......
131 134

  
132 135
        init = w[self.name] if self.name in w else self.init_value
133 136
        while True:
134
            (code, answer) = d.inputbox(self.message, init=init,
135
                width=PAGE_WIDTH, ok_label="Next", cancel="Back",
136
                title="(%d/%d) %s" % (index + 1, total, self.title))
137
            (code, answer) = \
138
                d.inputbox(self.message, init=init,
139
                           width=PAGE_WIDTH, ok_label="Next", cancel="Back",
140
                           title="(%d/%d) %s" % (index + 1, total, self.title))
137 141

  
138 142
            if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
139 143
                return self.PREV
......
159 163

  
160 164
        while True:
161 165
            ret = d.yesno(self.message, width=PAGE_WIDTH, ok_label="Yes",
162
                    cancel="Back", extra_button=1, extra_label="Quit",
163
                    title="(%d/%d) %s" % (index + 1, total, self.title))
166
                          cancel="Back", extra_button=1, extra_label="Quit",
167
                          title="(%d/%d) %s" % (index + 1, total, self.title))
164 168

  
165 169
            if ret == d.DIALOG_CANCEL:
166 170
                return self.PREV
......
173 177
def wizard(session):
174 178

  
175 179
    name = WizardInputPage("ImageName", "Please provide a name for the image:",
176
                      title="Image Name", init=session['device'].distro)
180
                           title="Image Name", init=session['device'].distro)
177 181
    descr = WizardInputPage("ImageDescription",
178
        "Please provide a description for the image:",
179
        title="Image Description", empty=True,
180
        init=session['metadata']['DESCRIPTION'] if 'DESCRIPTION' in
181
        session['metadata'] else '')
182
                            "Please provide a description for the image:",
183
                            title="Image Description", empty=True,
184
                            init=session['metadata']['DESCRIPTION'] if
185
                            'DESCRIPTION' in session['metadata'] else '')
182 186
    account = WizardInputPage("account",
183
        "Please provide your ~okeanos account e-mail:",
184
        title="~okeanos account information", init=Kamaki.get_account())
187
                              "Please provide your ~okeanos account e-mail:",
188
                              title="~okeanos account information",
189
                              init=Kamaki.get_account())
185 190
    token = WizardInputPage("token",
186
        "Please provide your ~okeanos account token:",
187
        title="~okeanos account token", init=Kamaki.get_token())
191
                            "Please provide your ~okeanos account token:",
192
                            title="~okeanos account token",
193
                            init=Kamaki.get_token())
188 194

  
189 195
    msg = "All necessary information has been gathered. Confirm and Proceed."
190 196
    proceed = WizardYesNoPage(msg, title="Confirmation")
......
198 204
    w.add_page(proceed)
199 205

  
200 206
    if w.run():
201
        extract_image(session)
207
        create_image(session)
202 208
    else:
203 209
        return False
204 210

  
205 211
    return True
206 212

  
207 213

  
208
def extract_image(session):
214
def create_image(session):
209 215
    d = session['dialog']
210 216
    disk = session['disk']
211 217
    device = session['device']
......
228 234
        #Shrink
229 235
        size = device.shrink()
230 236
        session['shrinked'] = True
231
        getattr(__import__("image_creator.dialog_main",
232
                fromlist=['image_creator']),
233
                "update_background_title")(session)
237
        update_background_title(session)
234 238

  
235 239
        metadata.update(device.meta)
236 240
        metadata['DESCRIPTION'] = wizard['ImageDescription']
......
254 258
            pithos_file = ""
255 259
            with open(snapshot, 'rb') as f:
256 260
                pithos_file = kamaki.upload(f, size, name,
257
                                             "(1/4)  Calculating block hashes",
258
                                             "(2/4)  Uploading missing blocks")
261
                                            "(1/4)  Calculating block hashes",
262
                                            "(2/4)  Uploading missing blocks")
259 263

  
260 264
            out.output("(3/4)  Uploading metadata file...", False)
261 265
            kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
......
281 285
    msg = "The image was successfully uploaded and registered with " \
282 286
          "~okeanos. Would you like to keep a local copy of the image?"
283 287
    if not d.yesno(msg, width=PAGE_WIDTH):
284
        getattr(__import__("image_creator.dialog_main",
285
                fromlist=['image_creator']), "extract_image")(session)
286

  
288
        extract_image(session)
287 289

  
288 290
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :

Also available in: Unified diff