-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.py
67 lines (58 loc) · 1.77 KB
/
zip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import queue
import threading
import sys
import pandas as pd
import subprocess
import os
CHEMIN = "chemin_complet"
PREFIXE = "Renommage_prefixe"
DOSSIER = "nom_dossier"
ANNEE = "Année"
MAILLE = "Maille_Vigie_Chiro"
NUMZ = "num_Z"
PASSAGE = "Passage"
dossier_zip = "c:\\zip"
fichier = "C:\\vigie\\renom_echantillon.xlsx"
def main(argv):
if argv:
inputfile = argv[0]
zip_dir = argv[1]
nb_thread = None
if len(argv) == 3:
nb_thread = int(argv[2])
zipper(inputfile, zip_dir, nb_thread)
return 0
else:
print(f"""Utilisation:
zip.py <inputfile> <zip_dir> [nb_thread]
""")
sys.exit(2)
def worker(q):
while True:
item = q.get()
print(f'Working on {item}')
subprocess.run(item)
print(f'Finished {item}')
q.task_done()
def zipper(nom_fichier, nom_rep, nb_thread):
file = pd.read_excel(nom_fichier)
if not os.path.exists(nom_rep):
os.makedirs(nom_rep)
q = queue.Queue()
for ligne in file.itertuples():
dossier = f"{nom_rep}\\{str(getattr(ligne, DOSSIER))}"
if not os.path.exists(dossier):
os.makedirs(dossier)
for rootdir, dirs, files in os.walk(ligne.chemin_complet):
q.put(f"c:\\Program Files\\7-Zip\\7z.exe a {dossier}\\{ligne.nom_dossier}.zip {rootdir}\\*.wav -r -v700M")
nb_dossier = q.qsize()
if nb_thread:
for i in range(nb_thread):
threading.Thread(target=worker, args=(q,), daemon=True).start()
else:
threading.Thread(target=worker, args=(q,), daemon=True).start()
q.join()
nb_dossier_traite = nb_dossier - q.qsize()
print(f"{nb_dossier_traite} dossiers traités sur {nb_dossier}")
if __name__ == '__main__':
main(sys.argv[1:])