-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipYourself.py
68 lines (56 loc) · 1.85 KB
/
zipYourself.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
68
# import required modules
import os
import zipfile
# Declare the function to return all file paths of the particular directory
def retrieve_file_paths(dirName):
# setup file paths variable
filePaths = []
directories_2_exclude = {
'.git',
'tests',
'__pycache__',
'.idea',
'resources',
'screenshots',
'ankiweb',
}
files_2_exlude = {
'.gitignore',
'CHANGELOG.md',
'content.xml',
'license.txt',
'README.md',
'requirements.txt',
'requirements2.txt',
'zipYourself.py',
}
# Read all directory, subdirectories and file lists
for root, directories, files in os.walk(dirName):
directories[:] = [d for d in directories if d not in directories_2_exclude]
for filename in files:
if not (filename in files_2_exlude):
# Create the full filepath by using os module.
filePath = os.path.join(root, filename)
filePaths.append(filePath)
# return all paths
return filePaths
# Declare the main function
def main():
# Assign the name of the directory to zip
dir_name = os.getcwd()
# Call the function to retrieve all files and folders of the assigned directory
filePaths = retrieve_file_paths(dir_name)
# printing the list of all files to be zipped
print('The following list of files will be zipped:')
for fileName in filePaths:
print(fileName)
# writing files to a zipfile
zip_file = zipfile.ZipFile(file=dir_name + '.ankiaddon', mode='w')
with zip_file:
# writing each file one by one
for file in filePaths:
zip_file.write(filename=file, arcname=file[len(dir_name):])
print(dir_name + '.zip file is created successfully!')
# Call the main function
if __name__ == "__main__":
main()