-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.py
74 lines (60 loc) · 2.41 KB
/
make.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
import os
import zipfile
import xml.etree.ElementTree as ET
import json
import hashlib
import shutil
suffix = ""
def getver():
description = ET.parse('install.rdf').getroot()[0]
for child in description:
if child.tag.endswith("}version"):
return child.text
return ""
def sha256sum(filename):
with open(filename, 'rb', buffering=0) as f:
return "sha256:"+hashlib.file_digest(f, 'sha256').hexdigest()
def update(filename):
v = getver()
link = "https://github.com/frianasoa/Ze-Notes/releases/download/v"+v+"/zenotes-v"+v+".xpi"
et = ET.parse('zenote-update'+suffix+'.rdf')
root = et.getroot()
for child in root.iter("{https://www.mozilla.org/2004/em-rdf#}version"):
child.text = v
for child in root.iter("{https://www.mozilla.org/2004/em-rdf#}updateLink"):
child.text=link
et.write("zenote-update"+suffix+".rdf", encoding="utf-8", xml_declaration=True)
update_json(v, link, sha256sum(filename))
def manifest():
v = getver()
with open('manifest.json') as f:
d = json.load(f)
d["version"] = v
with open('manifest.json', "w") as f:
json.dump(d, f, indent=4)
def update_json(version, link, hash):
with open('zenote-update'+suffix+'.json') as f:
d = json.load(f)
d["addons"]["[email protected]"]["updates"][0]["version"] = version
d["addons"]["[email protected]"]["updates"][0]["update_link"] = link
d["addons"]["[email protected]"]["updates"][0]["update_hash"] = hash
with open('zenote-update'+suffix+'.json', "w") as f:
json.dump(d, f, indent=2)
def zipdir(path, ziph):
exclude = ("./.git", "./make.py", "./upload.sh", "./build", "./docs", "./run.cmd", "./run7.cmd", "./zenote-update")
for root, dirs, files in os.walk(path):
for file in files:
fullpath = os.path.join(root, file)
if fullpath.startswith(exclude):
continue
ziph.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(path, '.')))
def install(source):
dest = "C:/ETOOLS/apps/Zotero_win-x64/distribution/extensions/[email protected]"
shutil.copy(source, dest)
manifest()
os.makedirs("build", exist_ok=True)
filename = './build/zenotes-v'+getver()+'.xpi'
with zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipdir('./', zipf)
update(filename)
install(filename)