Esempio n. 1
0
def getVirtualApplianceByCode():
    code = dialogbox.inputbox.TextInputBox(gui.res.string_virtual_appliance_code, "", 5, 32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").execute()
    if code == None: return None
    json_url = "http://goo.gl/" + code # e.g. DoIX3

    try:
        with dialogbox.messagebox.open(gui.res.string_code_check):
            rst = http_client.nonblockHttpGet(json_url)
            va = json.loads(rst)
            for key in ["id", "title"]: 
                if not key in va: raise ValueError("Invalid data")
    except ValueError:
        dialogbox.messagebox.execute(gui.res.string_code_not_correct, None, gui.res.caution_sign)
        return None
    except http_client.Cancelled:
        dialogbox.messagebox.execute(string_cancelled)
        return None
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return None

    # architecture check
    required_arch = va["arch"] if "arch" in va else "i686"
    supported_arch = {"i686":["i686"], "x86_64":["i686", "x86_64"]}
    s = system.getSystem()
    arch = s.getArchitectureString()
    if arch not in supported_arch:
        dialogbox.messagebox.execute(gui.res.string_domain_sys_error % arch, None, gui.res.caution_sign)
        return None
    if required_arch not in supported_arch[arch]:
        dialogbox.messagebox.execute(gui.res.string_domain_support_error % (required_arch, arch), None, gui.res.caution_sign)
        return None

    return va
Esempio n. 2
0
def showVirtualApplianceDialog(title, images, description, tarball, minimum_hd, minimum_ram):
    try:
        with dialogbox.messagebox.open(gui.res.string_get_detail):
            image_url = images[0]["url"] if images != None and len(images) > 0 and "url" in images[0] else None

            if image_url != None: 
                rst = http_client.nonblockHttpGet(image_url)
                image = pygame.image.load(io.BytesIO(rst)).convert_alpha()
            else:
                image = None

            contentLength = None
            if tarball != None:
                headers = http_client.nonblockingHttpHead(tarball)
                if "content-length" in headers:
                    contentLength = headers["content-length"]
    except http_client.Cancelled:
        dialogbox.messagebox.execute(string_cancelled)
        return False
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return False

    buttons = []
    if tarball != None: buttons.append({ "id":"download", "icon":gui.res.icon_ok, "text":gui.res.string_domain_download })
    buttons.append({ "id":"cancel", "icon":gui.res.icon_cancel, "text":string_cancel})
    specs = []
    if contentLength != None: specs.append(gui.res.string_download_capacity % (float(contentLength) / 1024 / 1024))
    if minimum_hd != None: specs.append(gui.res.string_capacity_atleast % minimum_hd)
    if minimum_ram != None: specs.append(gui.res.string_minimum_ram % minimum_ram)

    vad = VirtualApplianceDescription(title, image, description, " ".join(specs))

    return dialogbox.DialogBox(vad, buttons).execute() == "download"
Esempio n. 3
0
def main(stackPanel):
    try:
        with dialogbox.messagebox.open(gui.res.string_catalog):
            rst = http_client.nonblockHttpGet(catalog.getURL())
    except http_client.Cancelled:
        dialogbox.messagebox.execute(string_cancelled)
        return False
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(
            gui.res.string_comm_error % (e.getError(), e.getURL()), None,
            gui.res.caution_sign)
        return False

    try:
        items = catalog.parse(io.BytesIO(rst))
    except xml.etree.ElementTree.ParseError:
        dialogbox.messagebox.execute(gui.res.string_incorrect_format, None,
                                     gui.res.caution_sign)
        return False

    valist = gui.list.List(stackPanel.getSize())
    font = gui.res.font_system.getFont(20)
    valist.addItem(gui.list.TextListItem(gui.res.string_enter_code, font))
    for item in items:
        valist.addItem(
            gui.list.TextListItem(item["title"], font, None, None, item))
    stackPanel.push(valist)
    try:
        while True:
            rst = gui.eventLoop(valist)
            if rst == 0:
                va = getVirtualApplianceByCode()
            elif rst != None:
                va = valist.getSelected().getData()
                if "image" in va: va["images"] = [{"url": va["image"]}]
                if "minimum_hd" in va: va["minimum_hd"] = int(va["minimum_hd"])
                if "minimum_ram" in va:
                    va["minimum_ram"] = int(va["minimum_ram"])
            else:
                break
            if va == None: continue

            title = va["title"]
            images = va["images"] if "images" in va else None
            description = va["description"] if "description" in va else None
            tarball = va["tarball"] if "tarball" in va else None
            minimum_hd = va["minimum_hd"] if "minimum_hd" in va else None
            minimum_ram = va["minimum_ram"] if "minimum_ram" in va else None
            if showVirtualApplianceDialog(title, images, description, tarball,
                                          minimum_hd, minimum_ram):
                if download_va(va["id"], tarball, minimum_hd, minimum_ram):
                    return True
    finally:
        stackPanel.pop()
    return False
Esempio n. 4
0
def showVirtualApplianceDialog(title, images, description, tarball, minimum_hd,
                               minimum_ram):
    try:
        with dialogbox.messagebox.open(gui.res.string_get_detail):
            image_url = images[0]["url"] if images != None and len(
                images) > 0 and "url" in images[0] else None

            if image_url != None:
                rst = http_client.nonblockHttpGet(image_url)
                image = pygame.image.load(io.BytesIO(rst)).convert_alpha()
            else:
                image = None

            contentLength = None
            if tarball != None:
                headers = http_client.nonblockingHttpHead(tarball)
                if "content-length" in headers:
                    contentLength = headers["content-length"]
    except http_client.Cancelled:
        dialogbox.messagebox.execute(string_cancelled)
        return False
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(
            gui.res.string_comm_error % (e.getError(), e.getURL()), None,
            gui.res.caution_sign)
        return False

    buttons = []
    if tarball != None:
        buttons.append({
            "id": "download",
            "icon": gui.res.icon_ok,
            "text": gui.res.string_domain_download
        })
    buttons.append({
        "id": "cancel",
        "icon": gui.res.icon_cancel,
        "text": string_cancel
    })
    specs = []
    if contentLength != None:
        specs.append(gui.res.string_download_capacity %
                     (float(contentLength) / 1024 / 1024))
    if minimum_hd != None:
        specs.append(gui.res.string_capacity_atleast % minimum_hd)
    if minimum_ram != None:
        specs.append(gui.res.string_minimum_ram % minimum_ram)

    vad = VirtualApplianceDescription(title, image, description,
                                      " ".join(specs))

    return dialogbox.DialogBox(vad, buttons).execute() == "download"
Esempio n. 5
0
def main(stackPanel):
    try:
        with dialogbox.messagebox.open(gui.res.string_catalog):
            rst = http_client.nonblockHttpGet(catalog.getURL())
    except http_client.Cancelled:
        dialogbox.messagebox.execute(string_cancelled)
        return False
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return False

    try:
        items = catalog.parse(io.BytesIO(rst))
    except xml.etree.ElementTree.ParseError:
        dialogbox.messagebox.execute(gui.res.string_incorrect_format, None, gui.res.caution_sign)
        return False

    valist = gui.list.List(stackPanel.getSize())
    font = gui.res.font_system.getFont(20)
    valist.addItem(gui.list.TextListItem(gui.res.string_enter_code, font))
    for item in items:
        valist.addItem(gui.list.TextListItem(item["title"], font, None, None, item))
    stackPanel.push(valist)
    try:
        while True:
            rst =  gui.eventLoop(valist)
            if rst == 0:
                va = getVirtualApplianceByCode()
            elif rst != None:
                va = valist.getSelected().getData()
                if "image" in va: va["images"] = [{"url":va["image"]}]
                if "minimum_hd" in va: va["minimum_hd"] = int(va["minimum_hd"])
                if "minimum_ram" in va: va["minimum_ram"] = int(va["minimum_ram"])
            else: break
            if va == None: continue

            title = va["title"]
            images = va["images"] if "images" in va else None
            description = va["description"] if "description" in va else None
            tarball = va["tarball"] if "tarball" in va else None
            minimum_hd = va["minimum_hd"] if "minimum_hd" in va else None
            minimum_ram = va["minimum_ram"] if "minimum_ram" in va else None
            if showVirtualApplianceDialog(title, images, description, tarball, minimum_hd, minimum_ram):
                if download_va(va["id"], tarball, minimum_hd, minimum_ram):
                    return True
    finally:
        stackPanel.pop()
    return False
Esempio n. 6
0
def getVirtualApplianceByCode():
    code = dialogbox.inputbox.TextInputBox(
        gui.res.string_virtual_appliance_code, "", 5, 32,
        "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    ).execute()
    if code == None: return None
    json_url = "http://goo.gl/" + code  # e.g. DoIX3

    try:
        with dialogbox.messagebox.open(gui.res.string_code_check):
            rst = http_client.nonblockHttpGet(json_url)
            va = json.loads(rst)
            for key in ["id", "title"]:
                if not key in va: raise ValueError("Invalid data")
    except ValueError:
        dialogbox.messagebox.execute(gui.res.string_code_not_correct, None,
                                     gui.res.caution_sign)
        return None
    except http_client.Cancelled:
        dialogbox.messagebox.execute(string_cancelled)
        return None
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(
            gui.res.string_comm_error % (e.getError(), e.getURL()), None,
            gui.res.caution_sign)
        return None

    # architecture check
    required_arch = va["arch"] if "arch" in va else "i686"
    supported_arch = {"i686": ["i686"], "x86_64": ["i686", "x86_64"]}
    s = system.getSystem()
    arch = s.getArchitectureString()
    if arch not in supported_arch:
        dialogbox.messagebox.execute(gui.res.string_domain_sys_error % arch,
                                     None, gui.res.caution_sign)
        return None
    if required_arch not in supported_arch[arch]:
        dialogbox.messagebox.execute(
            gui.res.string_domain_support_error % (required_arch, arch), None,
            gui.res.caution_sign)
        return None

    return va
Esempio n. 7
0
def create():
    code = dialogbox.inputbox.TextInputBox(gui.res.string_app_code, "", 5, 32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").execute()
    if code == None: return None
    json_url = "http://goo.gl/" + code # e.g. lLj8Q

    try:
        with dialogbox.messagebox.open(gui.res.string_app_code_check):
            rst = http_client.nonblockHttpGet(json_url)
            app = json.loads(rst)
            for key in ["id", "title","type"]: 
                if not key in app: raise ValueError("Invalid data")
            if app["type"] != "app":
                raise ValueError("type must be app")
    except ValueError:
        dialogbox.messagebox.execute(gui.res.string_code_invalid, None, gui.res.caution_sign)
        return None
    except http_client.Cancelled:
        dialogbox.messagebox.execute(gui.res.string_app_canceled)
        return None
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_app_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return None

    images = app["images"] if "images" in app else None
    tarball = app["tarball"] if "tarball" in app else None
    minimum_hd = app["minimum_hd"] if "minimum_hd" in app else None
    title = app["title"] if "title" in app else None
    description = app["description"] if "description" in app else None

    s = system.getSystem()
    if not s.checkIfArchitectureIsSupported(app["arch"] if "arch" in app else "i686"):
         dialogbox.messagebox.execute(gui.res.string_app_not_supported % s.getArchitectureString(), None, gui.res.caution_sign)
         return False

    try:
        with dialogbox.messagebox.open(gui.res.string_apps_details):
            image_url = images[0]["url"] if images != None and len(images) > 0 and "url" in images[0] else None

            if image_url != None: 
                rst = http_client.nonblockHttpGet(image_url)
                image = pygame.image.load(io.BytesIO(rst)).convert_alpha()
            else:
                image = None

            contentLength = None
            if tarball != None:
                headers = http_client.nonblockingHttpHead(tarball)
                if "content-length" in headers:
                    contentLength = headers["content-length"]
    except http_client.Cancelled:
        dialogbox.messagebox.execute(gui.res.string_app_canceled)
        return False
    except http_client.CurlException as e:
        dialogbox.messagebox.execute(gui.res.string_app_comm_error % (e.getError(), e.getURL()), None, gui.res.caution_sign)
        return False

    buttons = []
    if tarball != None: buttons.append({ "id":"download", "icon":gui.res.icon_ok, "text":gui.res.string_app_download })
    buttons.append({ "id":"cancel", "icon":gui.res.icon_cancel, "text":gui.res.string_app_can})
    specs = []
    if contentLength != None: specs.append(gui.res.string_downl_capacity % (float(contentLength) / 1024 / 1024))
    if minimum_hd != None: specs.append(gui.res.string_app_minimum_hd % minimum_hd)

    apd = domain.create.VirtualApplianceDescription(title, image, description, " ".join(specs))

    if dialogbox.DialogBox(apd, buttons).execute() != "download": return False

    if exists(app["id"]):
        dialogbox.messagebox.execute(gui.res.string_app_exists % app["id"], None, gui.res.caution_sign)
        return False

    
    vgname = None

    while vgname == None:
        options = []
        for vg in volume.list_vgs():
            options.append({"id":vg["name"], "label":vg["name"]})
        vgname = gui.selectbox.execute(gui.res.string_app__select_area, options)
        if vgname == None: return False

        lvname = app["id"]
        try:
            device_name = s.createLogicalVolumeInMB(vgname, lvname, int(minimum_hd), "@wbapp")
        except Exception, e:
            traceback.print_exc(file=sys.stderr)
            dialogbox.messagebox.execute(gui.res.string_app_area_creation_failed_desc, None, gui.res.caution_sign)
            vgname = None