-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
195 lines (157 loc) · 5.74 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/python3
#
# maggy 2.5.1 - GTK+ based utility to create booklets and other layouts
# from PDF documents.
# Copyright (C) 2008-2012 GAF Software
# <https://sourceforge.net/projects/maggy>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# =====> Version number must be changed in setup.py (in the comment, line 4, and in the code) and build.py (in the code)
import os
import io
import re
import glob
import ftplib
from ftplib import FTP
# import pysftp
import zipfile
import tarfile
def fix_bin_file(file1):
data1 = b"#!/usr/bin/python3\n"
data1b = file1.readline()
data2 = file1.read()
data3 = data1 + data2
x = len(data3)
out = io.BytesIO()
out.write(data3)
return (out, x)
pyinstaller_file = ""
version = "2.3.0"
print ("\n\n ================ start bdist =============================\n\n")
# creates maggy-3.x.x.linux-[system].tar.gz
os.system('python3 setup.py bdist')
print ("\n\n ================ end bdist - start sdist =================\n\n")
# creates maggy-3.x.x.tar.gz
os.system('python3 setup.py sdist')
print ("\n\n ================ end sdist - start bdist_rpm =============\n\n")
os.system('python3 setup.py bdist_rpm')
# dependencies are set in the setup.cfg file
print ("\n\n ================ end bdist_rpm ===========================\n\n")
print ("\n\n ================ Generate pyinstaller file =======================\n\n" )
os.chdir('./maggy')
os.system('pyinstaller maggy3.py -y > /dev/null')
pyinstaller_file = "pyinstaller-" + version + ".zip"
zipfile1 = zipfile.ZipFile("../dist/" + pyinstaller_file, "w")
os.system('ls -l /home/')
for mydir in os.walk("./dist/") :
for myfile in mydir[2] :
path = os.path.join(mydir[0], myfile)
if os.path.isfile(path) :
zipfile1.write(path)
zipfile1.close()
os.chdir("..")
#os.system("tree -d") # option -d will print directories only
#os.chdir("dist")
rpm_file = "maggy-" + version + "-1.noarch.rpm"
tar_file = "maggy-" + version + ".tar.gz"
tar64_file = "./maggy-" + version + ".linux-x86_64.tar.gz"
corr_tar64_file = "./maggy-" + version + "-all_64_corr.tar.gz"
deb_file = "./maggy_" + version + "-2_all.deb"
# ###### to restore normalement ############################
"""
input1 = tarfile.open(tar64_file, "r")
output = tarfile.open(corr_tar64_file, "w")
names = input1.getnames()
for name in names:
x = re.search(r"\./usr/lib/python.*?packages", name)
if x:
original_package = x.group(0)
break
for name in names:
member = input1.getmember(name)
member.name = member.name.replace(original_package,"./usr/lib/python3/dist-packages")
file1 = input1.extractfile(member)
if name == "./usr/bin/maggy" :
(file2, size) = fix_bin_file(file1)
file2.seek(0)
member.size = size
output.addfile(member, file2)
continue
if file1:
output.addfile(member, file1)
input1.close()
output.close()
""""""
# generate Debian package
print ("\n\n ================ Creating debian package =======================\n\n")
#os.system('alien --generate --scripts ' + rpm_file)
os.system('sudo alien --generate ' + corr_tar64_file)
new_dir = "./maggy-" + version + "/"
os.chdir(new_dir)
control_file = "./debian/control"
if os.path.isfile(control_file) :
print ("control found")
f1 = open(control_file, "r")
data1 = f1.read()
data1 = data1.replace("${shlibs:Depends}", "python (>= 2.7), python-gi, python-gi-cairo, python3-gi, python3-gi-cairo, python3-cairo, gir1.2-gtk-3.0, gir1.2-poppler-0.18")
# above dependencies are for Debian. Unsure if python3-cairo is necessary.
# for rpm, something like that will be necessary, but unsufficient : python-gobject, python-gobject-2, pypoppler|python-poppler\n")
f1.close()
f1 = open(control_file, "w")
f1.write(data1)
f1.close()
else :
print ("============> ERROR : control NOT found.")
# post installation commands
# correct maggy.cfg
"""
"""
pb_dir = "./usr/share/maggy/"
text = "chmod 777 " + pb_dir
# I am unsure of the right place of this file, so let us put it in both places
os.system(" echo " + text + "> ./postinst")
os.system(" echo " + text + "> ./debian/postinst")
# Build debian package
os.system("dpkg-buildpackage")
os.chdir("..")
"""
if os.path.isfile("dist/" + rpm_file) :
print ("found rpm", rpm_file)
else :
print ("NOT found rpm", rpm_file)
if os.path.isfile("dist/" + tar_file) :
print ("found tar", tar_file)
else :
print ("NOT found tar", tar_file)
if os.path.isfile("dist/" + tar64_file) :
print ("found tar", tar64_file)
else :
print ("NOT found tar", tar64_file)
if os.path.isfile("dist/" + deb_file) :
print ("found deb", deb_file)
else :
print ("NOT found deb", deb_file)
if os.path.isfile("dist/" + pyinstaller_file) :
print ("found pyinstaller", pyinstaller_file)
else :
print ("NOT found pyinstaller", pyinstaller_file)
os.system('ls')
# install package
"""
print ("\n\n ================ Installing debian package =============================\n\n")
os.system("sudo dpkg -i " + deb_file)
os.system("sudo apt-get -f -y install")
"""
print("\n\n ================ End of build.py =======================\n\n")