-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3b-opt.py
More file actions
72 lines (62 loc) · 1.67 KB
/
3b-opt.py
File metadata and controls
72 lines (62 loc) · 1.67 KB
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
68
69
70
71
72
#!/usr/bin/python3
#3b-opt.py
#MoulesFrites
#11/11/2018
#Script de sauvegarde avec opt
import signal
import sys
import time
import os
import tarfile
def exitproperly(sig, frame):
sys.stdout.write('\nGood bye misteuuuuuur\n')
sys.exit(0)
signal.signal(signal.SIGINT, exitproperly)
def addFileNewTargz(fileName, tarName):
tz = tarfile.open(tarName, 'w:gz')
tz.add(fileName)
tz.close()
def unAutre():
saisi = input('Un autre ? (yes/no)')
if saisi == 'no' :
sys.exit(0)
elif saisi == 'yes' :
filepath = input("Entrez le dossier/fichier à compresser\n")
existPath = os.path.exists(filepath)
if existPath == True :
main(filepath)
else :
sys.stdout.write('Error filePath/dirPath\n')
else :
sys.stdout.write("Erreur dans la matrice")
def main(filePath):
directory = 'data/'
existPath = os.path.exists('data/')
if existPath == False :
os.mkdir(directory)
tarName = 'save' + filePath + str(time.time())
addFileNewTargz(filePath, str(tarName))
os.rename(str(tarName), directory + tarName)
existPath = os.path.isfile(directory + tarName)
if existPath == True :
sys.stdout.write('C\'est tout bon\n')
else :
sys.stdout.write('Erreur dans la matrice\n')
unAutre()
if len(sys.argv) > 1 :
opt1 = sys.argv[1]
if opt1 == '-h' :
sys.stdout.write('Vous avez demander de l\'aide ?\n')
else :
existPath = os.path.exists(opt1)
if existPath == True :
main(opt1)
else :
sys.stdout.write('Error filePath/dirPath\n')
else :
filepath = input("Entrez le dossier/fichier à compresser\n")
existPath = os.path.exists(filepath)
if existPath == True :
main(filepath)
else :
sys.stdout.write('Error filePath/dirPath\n')