-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.py
79 lines (63 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
# Simple automatization for building an addon
import sys
import os
import shutil
class Const:
ANKI = 0
ZIP = 1
CLEAR = 3
addonIndex = None
mode = None
target = None
acceptedArgs = ('-source', '-dist', '-dev', '-clear')
print('====================== Building RSS Addon =====================')
for index, value in enumerate(sys.argv):
if value not in acceptedArgs:
continue
if value == acceptedArgs[0]: #source
if (index + 1) > len(sys.argv) - 1:
raise IOError('Incorrect parameters. After "-source" there must be a value ')
addonIndex = int(sys.argv[index + 1])
elif value == acceptedArgs[1]:
mode = Const.ZIP # dist
target = '/dist'
elif value == acceptedArgs[2]:
if mode:
print('Already set to dist mode. Ignoring -dev')
else:
mode = Const.ANKI
target = os.environ['anki_addon']
elif value == acceptedArgs[3]: # clear
mode = Const.CLEAR
target = './dist' #os.environ['anki_addon']
# -----------------------------------------------------------
if not target:
raise IOError('No mode was informed. Choose either -dev or -dist')
# -----------------------------------------------------------
currentDir = os.path.dirname(os.path.realpath(__file__))
if mode == Const.ZIP:
if os.path.exists('dist'):
print('Cleaning dist directory')
shutil.rmtree('dist/')
print('Copying files')
shutil.copytree(currentDir, './dist',
ignore=shutil.ignore_patterns('tests', 'doc', '*_test*', '__pycache__'))
print('Creating binary')
shutil.make_archive('dist/anki-web-browser', format='zip', root_dir='dist/src')
# copies to anki's addon folder - test integrated
elif mode == Const.ANKI:
if os.path.exists(target + '/anki-web-browser'):
print('Removing old files: {}'.format(target + '/anki-web-browser'))
shutil.rmtree(target + '/anki-web-browser')
print('Copying files to anki directory')
addonRoot = currentDir
shutil.copytree(addonRoot + '/src', target + '/anki-web-browser',
ignore=shutil.ignore_patterns('tests', 'doc', '*_test*', '__pycache__'))
# Deletes from anki addons
elif mode == Const.CLEAR:
if os.path.exists(target + '/anki-web-browser'):
print('Removing old files: {}'.format(target + '/anki-web-browser'))
shutil.rmtree(target + '/anki-web-browser')
os.remove(target + '/anki-web-browser.py')
else:
print('Addon was not found on the target path: {}'.format(target + '/anki-web-browser.py'))