forked from Mte90/GlotDict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack-ext.py
executable file
·43 lines (37 loc) · 1.64 KB
/
pack-ext.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
#!/usr/bin/python3
print("Browser Extension packager by Mte90")
print("The only parameter required is the folder path!")
import sys, os, json, zipfile
def zipdir(path,name):
zipf = zipfile.ZipFile(name, 'w', zipfile.ZIP_DEFLATED)
exclude_prefixes = ['__', '.', 'jshintrc','tests'] # list of exclusion prefixes
exclude_suffixes = ['.xpi', '.zip', '.md', '.py'] # list of exclusion suffix
for dirpath, dirnames, filenames in os.walk(path):
# exclude all dirs/files starting/endings
dirnames[:] = [dirname
for dirname in dirnames
if all([dirname.startswith(string) is False
for string in exclude_prefixes])
is True]
filenames[:] = [filename
for filename in filenames
if (all([filename.startswith(string) is False for string in exclude_prefixes]))
and (all([filename.endswith(string) is False for string in exclude_suffixes]))
is True]
for file_found in filenames:
zipf.write(os.path.join(dirpath, file_found))
zipf.close()
if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
manifest = sys.argv[1] + '/manifest.json'
if os.path.isfile(manifest):
with open(manifest) as content:
data = json.load(content)
name = data['name'].replace(' ', '-') + '_v' + data['version']
zipdir(sys.argv[1], name + '.zip')
print("-Package done!")
else:
print("The file" + manifest + " not exist")
sys.exit()
else:
print("Path not found")
sys.exit()