-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.py
85 lines (76 loc) · 2.54 KB
/
build.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
# Imports
import os
import re
import sys
from glob import glob
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
# XPI package files, Note must update when adding or removing files.
resources = [
"install.rdf",
"chrome.manifest",
"defaults/preferences/prefs.js",
"chrome/content/core/css/uikit.gradient.min.css",
"chrome/content/core/fonts/FontAwesome.otf",
"chrome/content/core/fonts/fontawesome-webfont.ttf",
"chrome/content/core/fonts/fontawesome-webfont.woff",
"chrome/content/core/fonts/fontawesome-webfont.woff2",
"chrome/content/core/images/show_on_customize.jpg",
"chrome/content/core/images/show_on_panel.jpg",
"chrome/content/core/images/show_on_toolbar.jpg",
"chrome/content/core/js/jquery-2.2.4.min.js",
"chrome/content/core/js/lightbox.min.js",
"chrome/content/core/js/uikit.min.js",
"chrome/content/firstrun.html",
"chrome/content/firstrun.js",
"chrome/content/language_Manager.xul",
"chrome/content/language_Manager_Overlay.xul",
"chrome/content/LanguageList.json",
"chrome/content/options.html",
"chrome/content/options.js",
"chrome/content/overlay.js",
"chrome/locale/*/*",
"chrome/skin/*"
]
# Zip package
class ZipOutFile(ZipFile):
def __init__(self, zfile):
ZipFile.__init__(self, zfile, "w", ZIP_DEFLATED)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
# Enumerate resource files and folders.
def get_files(resources):
for r in resources:
if os.path.isfile(r):
yield r
continue
for g in glob(r):
yield g
# Build XPI package.
def buildXPI( version ):
destination = "xpi/LanguageManager-" + version + ".xpi"
# Check if the package already exists in our destination and remove it.
if os.path.exists(destination):
print("Found & removing: " + destination)
os.remove(destination)
print('Creating package please wait!')
with ZipOutFile(destination) as zp:
for f in sorted(get_files(resources), key=str.lower):
compress_type = ZIP_STORED if f.endswith(".png") else ZIP_DEFLATED
zp.write(f, compress_type=compress_type)
print("Compressing: " + f)
return;
# Since we use command line arguments we require two in total "build" & "0.0.0" (Version) for XPI package.
if sys.argv[1] == "build":
# Make XPI directory if not exists.
if not os.path.exists("xpi"):
os.makedirs("xpi")
# Send version to build XPI package.
buildXPI(sys.argv[2])
sys.exit()
else:
# If the above command line arguments were not set say goodbye.
print('Invalid commands or failed build!')
sys.exit()