示例#1
0
def test_archive_append(tmp_path):
    py7zr.unpack_7zarchive(os.path.join(testdata_path, 'test_2.7z'), path=tmp_path.joinpath('src'))
    target = tmp_path / "target.7z"
    shutil.copy(os.path.join(testdata_path, "test_1.7z"), target)
    source = str(tmp_path / 'src')
    cli = py7zr.cli.Cli()
    cli.run(['a', str(target), source])
示例#2
0
def test_archive_without_extension(tmp_path, capsys):
    py7zr.unpack_7zarchive(os.path.join(testdata_path, "test_1.7z"), path=tmp_path.joinpath("src"))
    target = str(tmp_path / "target")
    source = str(tmp_path / "src")
    cli = py7zr.cli.Cli()
    cli.run(["c", target, source])
    expected_target = tmp_path / "target.7z"
    assert expected_target.exists()
示例#3
0
def test_volume_creation(tmp_path, capsys):
    tmp_path.joinpath('src').mkdir()
    py7zr.unpack_7zarchive(os.path.join(testdata_path, 'lzma2bcj.7z'), path=tmp_path.joinpath('src'))
    target = str(tmp_path / "target.7z")
    source = str(tmp_path / 'src')
    cli = py7zr.cli.Cli()
    cli.run(['c', target, source, '-v', '2m'])
    out, err = capsys.readouterr()
示例#4
0
def test_archive_creation(tmp_path, capsys):
    tmp_path.joinpath('src').mkdir()
    py7zr.unpack_7zarchive(os.path.join(testdata_path, 'test_1.7z'), path=tmp_path.joinpath('src'))
    os.chdir(str(tmp_path))
    target = "target.7z"
    source = 'src'
    cli = py7zr.cli.Cli()
    cli.run(['c', target, source])
    out, err = capsys.readouterr()
示例#5
0
def test_compress_to_multi_volume(tmp_path):
    tmp_path.joinpath('src').mkdir()
    py7zr.unpack_7zarchive(os.path.join(testdata_path, 'lzma2bcj.7z'),
                           path=tmp_path.joinpath('src'))
    with MVF.open(tmp_path.joinpath('target.7z'), mode='wb',
                  volume=10240) as tgt:
        with py7zr.SevenZipFile(tgt, 'w') as arc:
            arc.writeall(tmp_path.joinpath('src'), 'src')
    target = tmp_path.joinpath('target.7z.0001')
    assert target.exists()
    assert target.stat().st_size == 10240
示例#6
0
def test_volume_creation(tmp_path, capsys):
    expected = ""
    tmp_path.joinpath("src").mkdir()
    py7zr.unpack_7zarchive(os.path.join(testdata_path, "lzma2bcj.7z"), path=tmp_path.joinpath("src"))
    target = str(tmp_path / "target.7z")
    source = str(tmp_path / "src")
    cli = py7zr.cli.Cli()
    cli.run(["c", target, source, "-v", "2m"])
    out, err = capsys.readouterr()
    assert out == expected
    assert err == expected
示例#7
0
def test_archive_already_exist(tmp_path, capsys):
    expected = 'Archive file exists!\n'
    py7zr.unpack_7zarchive(os.path.join(testdata_path, 'test_1.7z'), path=tmp_path.joinpath('src'))
    target = tmp_path / "target.7z"
    with target.open('w') as f:
        f.write('Already exist!')
    source = str(tmp_path / 'src')
    cli = py7zr.cli.Cli()
    with pytest.raises(SystemExit):
        cli.run(['c', str(target), source])
    out, err = capsys.readouterr()
    assert err == expected
示例#8
0
def test_archive_already_exist(tmp_path, capsys):
    expected = "Archive file exists!\n"
    py7zr.unpack_7zarchive(os.path.join(testdata_path, "test_1.7z"), path=tmp_path.joinpath("src"))
    target = tmp_path / "target.7z"
    with target.open("w") as f:
        f.write("Already exist!")
    source = str(tmp_path / "src")
    cli = py7zr.cli.Cli()
    with pytest.raises(SystemExit):
        cli.run(["c", str(target), source])
    out, err = capsys.readouterr()
    assert err == expected
示例#9
0
 def download_sounds(self):
     if self.settings["soundbackup"] is True:
         import py7zr
         name = self.settings["name"]
         if not os.path.isfile(self.file_system.path + "/nonesounds.7z"):
             self.log.info("downloading soundbackup")
             wget.download(
                 'http://downloads.tuxfamily.org/pdsounds/pdsounds_march2009.7z',
                 self.file_system.path + "/nonesounds.7z")
         if not os.path.isdir(self.settings["file_path"] + "/" + name +
                              "/not-wake-word/noises"):
             if not os.path.isdir(self.file_system.path + "/noises"):
                 os.makedirs(self.file_system.path + "/noises")
             if not os.path.isdir(self.file_system.path + "/noises/mp3"):
                 self.log.info("unzip soundbackup")
                 py7zr.unpack_7zarchive(
                     self.file_system.path + "/nonesounds.7z",
                     self.file_system.path + "/noises")
                 self.log.info("download sucess, start convert")
             if not os.path.isdir(self.file_system.path + "/noises/noises"):
                 for root, dirs, files in os.walk(self.file_system.path +
                                                  "/noises/mp3/"):
                     for f in files:
                         filename = os.path.join(root, f)
                         if filename.endswith('.mp3'):
                             self.log.info("Filename: " + filename)
                             if not os.path.isdir(self.file_system.path +
                                                  "/noises/noises"):
                                 os.makedirs(self.file_system.path +
                                             "/noises/noises")
                             self.soundbackup_convert = subprocess.Popen(
                                 [
                                     "ffmpeg -i " + filename +
                                     " -acodec pcm_s16le -ar 16000 -ac 1 -f wav "
                                     + self.file_system.path +
                                     "/noises/noises/noises-" +
                                     str(uuid.uuid1()) + ".wav"
                                 ],
                                 preexec_fn=os.setsid,
                                 shell=True)
                             self.log.info("extratct: " + filename)
                 self.log.info("Make Filelink")
             if not os.path.isdir(self.settings["file_path"] + "/" + name +
                                  "/not-wake-word"):
                 os.makedirs(self.settings["file_path"] + "/" + name +
                             "/not-wake-word")
             os.symlink(
                 self.file_system.path + "/noises/noises/",
                 self.settings["file_path"] + "/" + name +
                 "/not-wake-word/noises")
     else:
         return True
示例#10
0
def test_archive_append(tmp_path, capsys):
    expected = ""
    py7zr.unpack_7zarchive(os.path.join(testdata_path, "test_2.7z"), path=tmp_path.joinpath("src"))
    target = tmp_path / "target.7z"
    shutil.copy(os.path.join(testdata_path, "test_1.7z"), target)
    source = str(tmp_path / "src")
    cli = py7zr.cli.Cli()
    cli.run(["a", str(target), source])
    out, err = capsys.readouterr()
    assert err == expected
    #
    p7zip_test(tmp_path / "target.7z")
    libarchive_extract(tmp_path / "target.7z", tmp_path.joinpath("tgt2"))
示例#11
0
def test_archive_creation(tmp_path, capsys):
    expected = ""
    tmp_path.joinpath("src").mkdir()
    py7zr.unpack_7zarchive(os.path.join(testdata_path, "test_1.7z"), path=tmp_path.joinpath("src"))
    os.chdir(str(tmp_path))
    target = "target.7z"
    source = "src"
    cli = py7zr.cli.Cli()
    cli.run(["c", target, source])
    out, err = capsys.readouterr()
    assert out == expected
    #
    p7zip_test(tmp_path / "target.7z")
    libarchive_extract(tmp_path / "target.7z", tmp_path.joinpath("tgt2"))
示例#12
0
 def download_sounds(self):
     if self.settings["soundbackup"] is True:
         import py7zr
         name = self.settings["Name"]
         if not os.path.isfile(self.file_system.path+"/nonesounds.7z"):
             free_mb = psutil.disk_usage('/')[2] / 1024 / 1024
             if free_mb <= 1500:
                 self.settings["soundbackup"] = False
                 self.log.info("no space: Sound Download not possible")
                 return
             else:
                 self.log.info("downloading soundbackup")
                 wget.download('http://downloads.tuxfamily.org/pdsounds/pdsounds_march2009.7z', self.file_system.path+"/nonesounds.7z")
         #onlyfiles = next(os.walk(self.settings["file_path"]+name+"/not-wake-word/noises"))[2]
         #if len(onlyfiles) <= 30:
             if not os.path.isdir(self.file_system.path+"/noises"):
                 os.makedirs(self.file_system.path+"/noises")
             if not os.path.isdir(self.file_system.path+"/noises/mp3"):
                 self.log.info("unzip soundbackup")
                 py7zr.unpack_7zarchive(self.file_system.path+"/nonesounds.7z", self.file_system.path+"/noises")
                 self.log.info("download sucess, start convert")
             onlyfiles = next(os.walk(self.file_system.path+"/noises/noises"))[2]
             if len(onlyfiles) <= 30:
                 folder = self.file_system.path+"/noises/mp3/"
                 fileformat = '.mp3'
                 i = 1
                 while i <= 2:
                     for root, dirs, files in os.walk(folder):
                         for f in files:
                             filename = os.path.join(root, f)
                             if filename.endswith(fileformat):
                                 self.log.info("Filename: "+filename)
                                 soundfile = filename.replace(fileformat, '').replace(folder, '')
                                 if not os.path.isdir(self.file_system.path+"/noises/noises"):
                                     os.makedirs(self.file_system.path+"/noises/noises")
                                 subprocess.call(["ffmpeg -i "+filename+" -acodec pcm_s16le -ar 16000 -ac 1 -f wav "+
                                                 self.file_system.path+"/noises/noises/"+soundfile+".wav"],
                                                 preexec_fn=os.setsid, shell=True)
                                 self.log.info("extratct: "+filename)
                     folder = self.file_system.path+"/noises/otherformats/"
                     fileformat = '.flac'
                     i = i + 1
                 self.speak_dialog("download.success")
             if not os.path.isdir(self.settings["file_path"]+name+"/not-wake-word"):
                 os.makedirs(self.settings["file_path"]+"/"+name+"/not-wake-word")
         if not os.path.isdir(self.settings["file_path"]+name+"/not-wake-word/noises"):
             self.log.info("Make Filelink")
             os.symlink(self.file_system.path+"/noises/noises/", self.settings["file_path"]+name+"/not-wake-word/noises")
     else:
         return True
示例#13
0
 def install(self):
     downloadUrl: str = None
     for tag in get(self.app.repoApiUrl).json():
         if tag['name'] == self.app.version:
             for asset in tag['assets']:
                 if '.exe' in asset['name']:
                     downloadUrl = asset['browser_download_url']
                     break
             break
     if not downloadUrl:
         wx.GenericMessageDialog(
             parent=self.app.root,
             message="Can't find the version specified",
             caption='Error',
             style=None,
         ).ShowModal()
         wx.CallAfter(self.app.root.Destroy)
         return
     request = get(downloadUrl, stream=True)  # download BEE
     # working variables
     zipdata = io.BytesIO()
     dl = 0
     total_length = int(request.headers.get('content-length'))
     total_length_mb: int(total_length / 1024 / 1024)
     wx.CallAfter(self.app.root.progBar.SetRange, total_length)
     # download!
     for data in request.iter_content(chunk_size=1024):
         dl += len(data)
         zipdata.write(data)
         done = int(100 * dl / total_length)
         print(f'total: {total_length}, dl: {dl}, done: {done}')
         wx.CallAfter(self.app.root.progBar.SetValue, done)
         wx.CallAfter(self.app.root.megaText.SetLabel,
                      f'Done: {done / 1024 / 1024 }/{total_length_mb}MB')
         wx.CallAfter(self.app.root.speedText.SetLabel,
                      f'Speed: {len(data)}mbs')
     wx.CallAfter(self.app.root.progBar.Pulse)
     # read the data as bytes and then create the zipfile object from it
     if py7zr.is_7zfile(zipdata):
         wx.GenericMessageDialog(
             parent=self.app.root,
             message="The downloaded file wasn't a 7z file.",
             caption='Error',
             style=None,
         ).ShowModal()
         wx.CallAfter(self.app.root.Destroy)
         return
     tempdir = tempfile.mkdtemp(prefix='bridge-inst')
     py7zr.unpack_7zarchive(zipdata, tempdir)
     shutil.move(tempdir, self.app.installPath)
示例#14
0
def extract_via_py7zr(file_path, directory) -> bool:
    """
    Extract the contents of a file to a directory, using py7zr
    WARNING:  This can and will silently overwrite files in the target directory.
    """
    update_logger.debug("Extracting via py7zr.")
    import py7zr
    try:
        py7zr.unpack_7zarchive(file_path, directory)
    except Exception as e:
        update_logger.error(
            'Error while extracting from {0}'.format(file_path))
        update_logger.debug('Exception {0}'.format(str(e)))
        return False
    return True
示例#15
0
def test_compress_to_multi_volume(tmp_path):
    tmp_path.joinpath("src").mkdir()
    py7zr.unpack_7zarchive(os.path.join(testdata_path, "lzma2bcj.7z"),
                           path=tmp_path.joinpath("src"))
    with multivolumefile.open(tmp_path.joinpath("target.7z"),
                              mode="wb",
                              volume=10240) as tgt:
        with py7zr.SevenZipFile(tgt, "w") as arc:
            arc.writeall(tmp_path.joinpath("src"), "src")
    assert tmp_path.joinpath("target.7z.0001").stat().st_size == 10240
    assert tmp_path.joinpath("target.7z.0002").stat().st_size == 10240
    assert tmp_path.joinpath("target.7z.0003").stat().st_size == 10240
    assert 6000 < tmp_path.joinpath("target.7z.0004").stat().st_size < 6100
    #
    p7zip_test(tmp_path.joinpath("target.7z.0001"))
 def un_py7zr(filename, extract_dir):
     list = []
     try:
         is7z = py7zr.is_7zfile(filename)
         if is7z:
             ret = py7zr.unpack_7zarchive(filename, extract_dir)
             arc = py7zr.SevenZipFile(filename)
             list = arc.getnames()
             # print(list)
         else:
             print('un_py7zr: unknow file type')
     except Exception as e:
         print(e)
     return list
示例#17
0
    def un_py7zr(filename):
        extract_dir = os.getcwd() + "\\firmware"
        if os.path.isdir(extract_dir):
            pass
        else:
            os.mkdir(extract_dir)

        is7z = py7zr.is_7zfile(filename)
        py7zr.SevenZipFile
        if is7z:
            ret = py7zr.unpack_7zarchive(filename, extract_dir)
            print(ret)
        else:
            print('unknow file type')
        return extract_dir