forked from FranklinDM/TGS
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
executable file
·75 lines (62 loc) · 2.34 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
#!/usr/bin/env python3
# pylint: disable=C0103
import os
import shutil
import xml.etree.ElementTree as ET
pj = os.path.join
pn = os.path.normpath
script_path = os.path.dirname(os.path.realpath(__file__))
main_path = script_path
temp_path = pj(main_path, "src_temp")
if os.path.exists(temp_path):
shutil.rmtree(temp_path)
os.chdir(main_path)
shutil.copytree(pn("./src"), temp_path)
shutil.copy(pn("license.txt"), temp_path)
os.chdir(temp_path)
unused_locales = []
with open(pj(temp_path, "locales.manifest"), "r", encoding='utf-8') as l_m:
for line in l_m:
if "#locale" in line:
unused_locales.append(line.split()[2])
if unused_locales:
for ul in unused_locales:
shutil.rmtree(pn("./locale/" + ul))
# Get extension version from install.rdf
rdfRoot = ET.parse(pn("./install.rdf")).getroot()
emRdf = "http://www.mozilla.org/2004/em-rdf#"
xmlnsRdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
namespaces = {'xmlns': xmlnsRdf,
'em': emRdf}
for description in rdfRoot.findall('xmlns:Description', namespaces):
extVersion = description.get("{"+emRdf+"}version")
# Create xpi
artifacts_path = pj(main_path, "artifacts")
f_name = "CS-"+extVersion
UXP_xpi = pj(artifacts_path, f_name + ".xpi")
if os.path.exists(UXP_xpi):
print("Removing old xpi file")
os.remove(UXP_xpi)
if not os.path.exists(artifacts_path):
os.makedirs(artifacts_path)
print("Creating new xpi file in artifacts directory")
shutil.make_archive(pj(artifacts_path, f_name), 'zip', "./")
os.rename(pj(artifacts_path, f_name + ".zip"), UXP_xpi)
# Cleanup
os.chdir(main_path)
shutil.rmtree(temp_path)
# Update update.xml
print("Updating update.xml")
updateXml = pn("./update/update.xml")
updateXmlTree = ET.parse(updateXml)
updateXmlRoot = updateXmlTree.getroot()
ET.register_namespace('em', emRdf)
ET.register_namespace('RDF', xmlnsRdf)
for description in updateXmlRoot.findall('./xmlns:Description/em:updates/xmlns:Seq/xmlns:li/xmlns:Description', namespaces):
description.set("{"+emRdf+"}version", extVersion)
desc = description.find(
"./em:targetApplication/xmlns:Description", namespaces)
desc.set("{"+emRdf+"}updateLink",
"https://github.com/hawkeye116477/CS/releases/download/"+extVersion+"/"+f_name+".xpi")
updateXmlTree.write(updateXml, encoding='UTF-8',
xml_declaration=True, method='xml')