Пример #1
0
def deploy(url):
    import sys
    import os
    import lib.shutil as shutil
    import upip_utarfile as utarfile
    import urequests

    res = urequests.get(url)

    if not res.status_code == 200:
        return

    def dir_exists(path):
        try:
            os.stat(path)
            return True
        except:
            return False

    t = utarfile.TarFile(fileobj = res.raw)

    for f in t:
        print("Extracting {}: {}".format(f.type, f.name))
        if f.type == utarfile.DIRTYPE:
            if f.name[-1:] == '/':
                name = f.name[:-1]
            else:
                name = f.name

            if not dir_exists(name):
                os.mkdir(name)
        else:
            extracted = t.extractfile(f)
            shutil.copyfileobj(extracted, open(f.name, "wb"))
Пример #2
0
def install_pkg(pkg_spec, install_path):
    package = pkg_spec.split("==")
    data = get_pkg_metadata(package[0])

    if len(package) == 1:
        latest_ver = data["info"]["version"]
    else:
        latest_ver = package[1]
    packages = data["releases"][latest_ver]
    del data
    gc.collect()
    assert len(packages) == 1
    package_url = packages[0]["url"]
    print("Installing %s %s from %s" % (pkg_spec, latest_ver, package_url))
    package_fname = op_basename(package_url)
    f1 = url_open(package_url)
    try:
        f2 = uzlib.DecompIO(f1, gzdict_sz)
        f3 = tarfile.TarFile(fileobj=f2)
        meta = install_tar(f3, install_path)
    finally:
        f1.close()
    del f3
    del f2
    gc.collect()
    return meta
Пример #3
0
def install_pkg(pkg_spec, install_path, force_reinstall):
    data = get_pkg_metadata(pkg_spec)
    already_installed = False
    try:
        os.stat("%s%s/" % (install_path, pkg_spec))
    except OSError as e:
        if e.args[0] == errno.EINVAL:
            print("Package %s already installed" % (pkg_spec))
            already_installed = True
        else:
            print("Package %s not yet installed" % (pkg_spec))
    else:
        # fallback for unix version
        print("Package %s already installed" % (pkg_spec))
        already_installed = True
    latest_ver = data["info"]["version"]
    verf = "%s%s/version" % (install_path, pkg_spec)
    if already_installed:
        try:
            fver = open(verf, "r")
        except:
            print("No version file found")
        else:
            old_ver = fver.read()
            if old_ver == latest_ver:
                if not force_reinstall:
                    raise LatestInstalledError("Latest version installed")
            else:
                print("Removing previous rev. %s" % old_ver)
                for rm_file in os.listdir("%s%s" % (install_path, pkg_spec)):
                    os.remove("%s%s/%s" % (install_path, pkg_spec, rm_file))
            fver.close()
    packages = data["releases"][latest_ver]
    del data
    gc.collect()
    assert len(packages) == 1
    package_url = packages[0]["url"]
    print("Installing %s rev. %s from %s" %
          (pkg_spec, latest_ver, package_url))
    package_fname = op_basename(package_url)
    f1 = url_open(package_url)
    try:
        f2 = uzlib.DecompIO(f1, gzdict_sz)
        f3 = tarfile.TarFile(fileobj=f2)
        meta = install_tar(f3, "%s%s/" % (install_path, pkg_spec))
    finally:
        f1.close()
    del f3
    del f2
    fver = open(verf, "w")
    fver.write(latest_ver)
    fver.close()
    del fver
    gc.collect()
    return meta
Пример #4
0
def install_pkg(pkg_spec, install_path):
    data = get_pkg_metadata(pkg_spec)

    latest_ver = data["info"]["version"]
    packages = data["releases"][latest_ver]
    assert len(packages) == 1
    package_url = packages[0]["url"]
    print("Installing %s %s from %s" % (pkg_spec, latest_ver, package_url))
    package_fname = op_basename(package_url)
    f1 = url_open(package_url)
    f2 = uzlib.DecompIO(f1, 16 + 15)
    f3 = tarfile.TarFile(fileobj=f2)
    meta = install_tar(f3, install_path)
    f1.close()
    return meta
Пример #5
0
def install_pkg(pkg_spec, install_path):
    # package_url = get_latest_url_json(pkg_spec)
    package_url = get_latest_url_simple(pkg_spec)

    print("Installing %s from %s" % (pkg_spec, package_url))
    package_fname = op_basename(package_url)
    f1 = url_open(package_url)
    try:
        f2 = uzlib.DecompIO(f1, gzdict_sz, gzdict_buf)
        f3 = tarfile.TarFile(fileobj=f2)
        meta = install_tar(f3, install_path)
    finally:
        f1.close()
    del f3
    del f2
    gc.collect()
    return meta
Пример #6
0
def install_pkg(pkg_spec, install_path, force_reinstall):
    data = get_pkg_metadata(pkg_spec)
    if data is None:
        return None
    already_installed = is_installed(pkg_spec, install_path)
    latest_ver = data["info"]["version"]
    verf = "%s%s/version" % (install_path, pkg_spec)
    if already_installed:
        try:
            with open(verf, "r") as fver:
                old_ver = fver.read()
        except:
            print("No version file found")
        else:
            if old_ver == latest_ver:
                if not force_reinstall:
                    raise LatestInstalledError("Latest version installed")
            else:
                print("Removing previous rev. %s" % old_ver)
                for rm_file in os.listdir("%s%s" % (install_path, pkg_spec)):
                    os.remove("%s%s/%s" % (install_path, pkg_spec, rm_file))
    packages = data["releases"][latest_ver]
    del data
    gc.collect()
    assert len(packages) == 1
    package_url = packages[0]["url"].replace('https', 'http')
    print("Installing %s rev. %s from %s" % (pkg_spec, latest_ver, package_url))
    package_fname = op_basename(package_url)
    f1 = urequests.get(package_url).raw
    try:
        gc.collect()
        print('mem_free:', gc.mem_free())
        f2 = uzlib.DecompIO(f1, gzdict_sz)
        f3 = tarfile.TarFile(fileobj=f2)
        meta = _install_tar(f3, "%s%s/" % (install_path, pkg_spec))
    finally:
        f1.close()
        del f1
    del f3
    del f2
    with open(verf, "w") as fver:
        fver.write(latest_ver)
    del fver
    gc.collect()
    return meta
Пример #7
0
def install_pkg(pkg, install_path, data):
    ver = pkg.get('version', data["info"]["version"])  # defaults to latest

    packages = data["releases"][ver]
    del data
    gc.collect()
    assert len(packages) == 1
    package_url = packages[0]["url"]
    print("Installing %s %s from %s" % (pkg['name'], ver, package_url))
    package_fname = op_basename(package_url)
    f1 = url_open(package_url)
    try:
        f2 = uzlib.DecompIO(f1, gzdict_sz)
        f3 = tarfile.TarFile(fileobj=f2)
        meta = install_tar(f3, install_path)
    finally:
        f1.close()
    del f3
    del f2
    gc.collect()
    return meta
Пример #8
0
def install_pkg(package_url, install_path):
    gzdict_sz = 16 + 15
    f1 = url_open(package_url)
    if (isinstance(f1, (str, bytes, bytearray)) == True):
        print(f1)
        return f1
    try:
        f2 = uzlib.DecompIO(f1, gzdict_sz)
        f3 = tarfile.TarFile(fileobj=f2)
        install_tar(f3, install_path)
    except Exception as e:
        print(e)
        return ("UNTAR_FILE_FAIL")
    finally:
        f1.close()
    del f3
    del f2
    gc.collect()

    print('install_pkg success')
    return 'SUCCESS'
Пример #9
0
def installApp(REPO_URL, manifest, APP_ROOT='/apps'):
    import upip_utarfile as tarfile
    import uzlib, os, gc
    from upip import url_open
    gc.collect()
    oled.fill(0)
    oled.text('Installing...', 0, 0, 1)
    oled.text(manifest['name'], 0, 8, 1)
    oled.text(manifest['version'], 0, 16, 1)
    oled.show()
    count = 0
    try:
        s1 = url_open(REPO_URL + manifest['url'])
        f2 = uzlib.DecompIO(s1, 30)
        t3 = tarfile.TarFile(fileobj=f2)
        for x in t3:
            print(x)
            count += 1
            oled.fill_rect(0, 32, 128, 16, 0)
            oled.hctext('File #%d' % count, 32, 1)
            oled.hctext(x.name[-16:], 40, 1)
            oled.show()
            if x.type == tarfile.DIRTYPE:  # a dir
                FOLDER_PATH = APP_ROOT + '/' + x.name[:-1]
                print(FOLDER_PATH)
                if x.name[:-1] in os.listdir(APP_ROOT):
                    deleteFolder(FOLDER_PATH)  # delete if exists
                os.mkdir(FOLDER_PATH)
            else:  # a file
                f4 = open(APP_ROOT + '/' + x.name, 'wb')
                f4.write(t3.extractfile(x).read())
                f4.close()
    finally:
        s1.close()
    rebuildAppsIndex(APP_ROOT)
    oled.text('Done :)  Reboot!', 0, 56, 1)
    oled.show()
    sleep_ms(500)
    import machine
    machine.reset()
Пример #10
0
    def unpack_tar(self):
        t = utar.TarFile(self.TAR_PATH)
        updatebasepath = "/{}/".format(self.next_boot_partition)
        log.info("Update Base Path: {}".format(updatebasepath))
        for i in t:
            # log.info("info {}".format(i))
            gc.collect()

            if i.type == utar.DIRTYPE:
                i_name = i.name[:-1]
                # log.debug("{} -> {}".format(i.name, i_name))
                try:
                    os.mkdir(updatebasepath + i_name)
                except Exception as e:
                    log.debug("mkdir: {}".format(e))
                    return False
            else:
                # log.info("file: {}".format(updatebasepath+i.name))
                with open(updatebasepath + i.name, 'wb') as ef:
                    pf = t.extractfile(i)
                    copy_file_obj(pf, ef)

        return True