コード例 #1
0
    def extract(self, filename) -> None:

        with open(filename, 'rb') as f:  # type: ignore
            t = utar.TarFile(f)
            for i in t:
                if i.Type is utar.Type.DIR:
                    self._writeTarItemAsDir(i)
                    continue

                self._writeTarItemToFile(i)
コード例 #2
0
def check_over_ip(node_type):
    """ tcp/ip stage of checking of OTA"""

    try:
        resp = url_open("http://10.11.12.13:1415/%s/version.txt" % node_type)
    except (OSError, CheckTimeoutError):
        blink("no version found")
        return False

    remote_version = resp.read().decode("utf-8").strip()
    blink("remote version = %s" % remote_version)

    try:
        local_version = open(".otaversion").read().strip()
    except OSError:
        blink("no local version found")
        local_version = ""

    blink("local_version = %s remote_version=%s" %
          (local_version, remote_version))

    if local_version == remote_version:
        blink("skipping")
        return False

    blink("doing OTA")

    resp = url_open("http://10.11.12.13:1415/%s/%s.tar" %
                    (node_type, remote_version))

    ftar = utarfile.TarFile(fileobj=resp)
    meta = install_tar(ftar)

    fver = open(".otaversion", "wb")
    fver.write(remote_version)
    fver.close()

    del fver
    del resp
    del ftar
    del meta

    blink("OTA PERFORMED, doing reboot")
    machine.reset()
コード例 #3
0
ファイル: extracttar.py プロジェクト: watrt/linewatch
def run(src,dest_dir):
  t = utarfile.TarFile(src)
  prefix=dest_dir
  for i in t:
    i.name=i.name.rstrip('/')
    print(i,i.name)
    i.name=prefix+i.name
    print(i.name)
    if i.type == utarfile.DIRTYPE:
      try:
        os.mkdir(i.name)
      except OSError as e:
        if e.args[0] != errno.EEXIST and e.args[0] != errno.EISDIR:
          raise e
     
    else:
      f = t.extractfile(i)
      print(i.name)
      shutil.copyfileobj(f, open(i.name, "wb+"))
コード例 #4
0
    def unpack(self, path):
        os.chdir(self._tmp_dir)

        t = utarfile.TarFile(path)
        for i in t:
            print(i)
            if i.type == utarfile.DIRTYPE:
                os.mkdir(i.name)
            else:
                shutil.create_folders_if_needed(self._tmp_dir + os.sep +
                                                i.name)
                src = t.extractfile(i)
                dst = open(i.name, "wb")
                shutil.copyfileobj(src, dst)
                dst.close()
                os.sync()
            gc.collect()
        os.unlink(path)
        os.chdir('/flash')
        print('firmware unpacked to {}'.format(self._tmp_dir))
コード例 #5
0
lan = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power=machine.Pin(12), phy_type = network.PHY_LAN8720, phy_addr=0, clock_mode=network.ETH_CLOCK_GPIO17_OUT)
lan.active(True)
timer = 0
while not lan.isconnected():
    timer += 1
    if timer > 300000:                                   # Well, this is sketchy AF
        raise Exception ("Network took too long")
sleep_ms(5000)
upip.install("micropython-uasyncio")
upip.install("micropython-uasyncio.queues")
upip.install("micropython-utarfile")

if "tmp" not in os.listdir():
    os.mkdir("tmp")

if "firmware" not in os.listdir():
    os.mkdir("firmware")

import utarfile
for fn in os.listdir():
    if fn.endswith(".tar"):
        t = utarfile.TarFile(fn)
        for i in t:
            print(i)
            if i.type == utarfile.DIRTYPE:
                os.mkdir(i.name)
            else:
                tf = t.extractfile(i)
                with open(i.name, "wr") as f:
                    f.write(tf.read())
コード例 #6
0
ファイル: example-extract.py プロジェクト: pmp-p/wapy-lib
import sys
import os
import shutil
import utarfile

t = utarfile.TarFile(sys.argv[1])
for i in t:
    print(i)
    if i.type == utarfile.DIRTYPE:
        os.makedirs(i.name)
    else:
        f = t.extractfile(i)
        shutil.copyfileobj(f, open(i.name, "wb"))