-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_ext.py
More file actions
139 lines (113 loc) · 3.81 KB
/
make_ext.py
File metadata and controls
139 lines (113 loc) · 3.81 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import argparse
import os
import sys
from subprocess import call
import zipfile
from conf import *
def exists(path):
return os.path.exists(path)
def join(*paths):
return os.path.join(*paths)
def validate():
path = join(DIR_SOURCE, FILE_PY)
if not exists(path):
LOG.error('No se encontro el archivo PY')
return False
path = join(DIR_SOURCE, FILE_IDL)
if not exists(path):
LOG.error('No se encontro el archivo IDL')
return False
if not exists(PATH_IDLC):
LOG.error('No se encontro el archivo IDLC necesario para compilar')
return False
if not exists(PATH_REGMERGE):
LOG.error('No se encontro el archivo REGMERGE necesario para compilar')
return False
return True
def compilate_idl():
LOG.info('Compilate IDL...')
path_rdb = join(DIR_SOURCE, FILE_RDB)
path_urd = join(DIR_SOURCE, FILE_URD)
if exists(path_rdb):
os.remove(path_rdb)
if exists(path_urd):
os.remove(path_urd)
path = join(DIR_SOURCE, FILE_IDL)
call([PATH_IDLC, '-I', PATH_IDLC_INCLUDE, path])
#~ call([PATH_IDLC, path])
call([PATH_REGMERGE, path_rdb, '/UCR', path_urd])
os.remove(path_urd)
LOG.info('Compilate IDL sucesfully...')
return True
def compress_zip():
LOG.info('Compress zip extension...')
if not exists(DIR_FILES):
os.mkdir(DIR_FILES)
path_oxt = join(DIR_FILES, FILE_OXT)
z = zipfile.ZipFile(path_oxt, 'w', compression=zipfile.ZIP_DEFLATED)
root_len = len(os.path.abspath(DIR_SOURCE))
for root, dirs, files in os.walk(DIR_SOURCE):
relative = os.path.abspath(root)[root_len:]
for f in files:
fullpath = join(root, f)
file_name = join(relative, f)
if file_name == FILE_IDL:
continue
z.write(fullpath, file_name, zipfile.ZIP_DEFLATED)
z.close()
LOG.info('Extension zip sucesfully...')
return
def install(in_aoo):
path_oxt = join(DIR_FILES, FILE_OXT)
if in_aoo:
LOG.info('Install extension in OpenOffice...')
call(['/opt/openoffice4/program/unopkg', 'add', '-v', '-f', '-s', path_oxt])
call(['openoffice4', '-calc'])
else:
LOG.info('Install extension in LibreOffice...')
call(['unopkg', 'add', '-v', '-f', '-s', path_oxt])
call(['soffice', '--calc'])
LOG.info('Install extension sucesfully...')
return
def make_xml():
LOG.info('Update files XML...')
path = join(DIR_SOURCE, DIR_META)
if not exists(path):
os.mkdir(path)
path = join(path, FILE_MANIFEST)
with open(path, 'w') as f:
f.write(XML_MANIFEST)
path = join(DIR_SOURCE, FILE_DESCRIPTION)
with open(path, 'w') as f:
f.write(XML_DESCRIPTION)
path = join(DIR_FILES, FILE_UPDATE)
with open(path, 'w') as f:
f.write(XML_UPDATE)
LOG.info('Files XML update sucesfully...')
return
def process_command_line_arguments():
parser = argparse.ArgumentParser(
description='Make AddIn extension OXT')
parser.add_argument('-i', '--install', dest='install', action='store_true',
default=False, required=False)
parser.add_argument('-o', '--only_compress', dest='only_compress',
action='store_true', default=False, required=False)
parser.add_argument('-a', '--install_aoo', dest='install_aoo',
action='store_true', default=False, required=False)
return parser.parse_args()
if __name__ == '__main__':
args = process_command_line_arguments()
if not validate():
sys.exit(0)
if args.only_compress:
compress_zip()
if args.install:
install()
sys.exit(0)
if not compilate_idl():
sys.exit(0)
make_xml()
compress_zip()
if args.install:
install(args.install_aoo)
LOG.info('Extension make sucesfully...')