forked from malimaliao/xbmc-addons-chinese
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
executable file
·52 lines (43 loc) · 1.37 KB
/
release.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" plugin release tool"""
import os, sys, re, zipfile, shutil
def cp(src, dst):
if os.path.exists(src):
shutil.copyfile(src, dst)
def release(plugin, version):
# zip dir
zipdir = 'repo/%s' % (plugin)
if not os.path.exists(zipdir):
os.mkdir(zipdir)
# zip repo
zipname = 'repo/%s/%s-%s.zip' % (plugin, plugin, version)
f = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(plugin):
for filename in filenames:
f.write(os.path.join(dirpath,filename))
f.close()
# copy icon
src = '%s/icon.png' % (plugin)
dst = 'repo/%s/icon.png' % (plugin)
cp(src, dst)
# copy change log
src = '%s/changelog.txt' % plugin
dst = 'repo/%s/changelog-%s.txt' % (plugin, version)
cp(src, dst)
def getVersion(plugin):
name = '%s/addon.xml' % plugin
if sys.version_info[0] >= 3:
cont = open(name,encoding='utf-8').read()
else:
cont = open(name).read()
addon = re.findall('<addon.*?version="(.*?)"', cont, re.DOTALL)
if addon:
return addon[0]
argc = len(sys.argv)
if argc >= 2:
plugin = sys.argv[1].rstrip('/')
version = getVersion(plugin) if argc == 2 else sys.argv[2]
release(plugin, version)
else:
print('usage: %s plugin_dir [plugin_version]' % sys.argv[0])