commit 5c25a91b2094e5c870ac5121e780561e679d5d64 Author: Jan Doubravský Date: Mon May 19 18:39:59 2025 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Vault.code-workspace b/Vault.code-workspace new file mode 100644 index 0000000..876a149 --- /dev/null +++ b/Vault.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/Vault.py b/Vault.py new file mode 100644 index 0000000..d30a0db --- /dev/null +++ b/Vault.py @@ -0,0 +1,37 @@ +import zipfile +import os + +def vytvor_zip(zip_path, soubory): + with zipfile.ZipFile(zip_path, 'w') as zipf: + for soubor in soubory: + zipf.write(soubor) + +def extrahuj_zip(zip_path, cilovy_adresar): + with zipfile.ZipFile(zip_path, 'r') as zipf: + zipf.extractall(cilovy_adresar) + +def vypis_obsah_zip(zip_path): + with zipfile.ZipFile(zip_path, 'r') as zipf: + for nazev in zipf.namelist(): + print(nazev) + +def pridej_do_zip(zip_path, soubor): + with zipfile.ZipFile(zip_path, 'a') as zipf: + zipf.write(soubor) + +def prepis_soubor_v_zipu(zip_path, novy_soubor, jmeno_v_zipu=None): + jmeno_v_zipu = jmeno_v_zipu or os.path.basename(novy_soubor) + temp_zip = zip_path + '.tmp' + + with zipfile.ZipFile(zip_path, 'r') as zip_read, \ + zipfile.ZipFile(temp_zip, 'w') as zip_write: + for item in zip_read.infolist(): + if item.filename != jmeno_v_zipu: + data = zip_read.read(item.filename) + zip_write.writestr(item, data) + zip_write.write(novy_soubor, arcname=jmeno_v_zipu) + + os.replace(temp_zip, zip_path) + +#vytvor_zip("test.vf", ["material_hardness.xlsx", "material_denominations.xlsx"]) +vypis_obsah_zip("test.vf") \ No newline at end of file