This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.py
373 lines (327 loc) · 17 KB
/
setup.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
from setuptools import setup, Command
import os
import platform
import shutil
import site
from concurrent.futures import ProcessPoolExecutor
from datetime import datetime
from multiprocessing import cpu_count
class Doxygen(Command):
description = "Create/update doxygen documentation in doc/html"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("Creating Doxygen Documentation")
os.system("""sed -i -e "41d" doc/Doxyfile""")#Delete line 41
os.system("""sed -i -e "41iPROJECT_NUMBER = {}" doc/Doxyfile""".format(__version__))#Insert line 41
os.system("rm -Rf build")
os.chdir("doc")
os.system("doxygen Doxyfile")
os.system("rsync -avzP -e 'ssh -l turulomio' html/ frs.sourceforge.net:/home/users/t/tu/turulomio/userweb/htdocs/doxygen/caloriestracker/ --delete-after")
os.chdir("..")
class PyInstaller(Command):
description = "We run pyinstaller in build to avoid doing a ./caloriestracker module imort. I had problems with i18n. Before running this command I must have done a install, removing old installations"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
## TODOS LOS ERRORES VINIERON POR TENER MAL EL __init__ LE PUSE _ALL__
## TAMBIEN VINIERON PORQUE EL NOMBRE DEL SCRIPT AUXILIAR ERA EL MISMO QUE EL DEL PAQUETE
## PKG_RESOURCES IS NOT SUPPORTED BY PYINSTALLER. I COPY QM to .
## --log-level DEBUG ALLOWS YOU TOO DEBUG PROBLEMS
def run(self):
os.system("python setup.py uninstall")
os.system("python setup.py install")
self.entry_point("caloriestracker.caloriestracker","caloriestracker")
## Makes a entry_point for this module, fuction should be main. It also executes pyinstaller
## @param module strings with the module to import
## @param name string with the name of the name of the file
def entry_point(self,module,name):
filename=module.replace(".","_")+".py"
f=open(filename,"w")
f.write("""import {0}
import sys
import os
# NO funciona con PyQt5-2.13 tuve que bajar a PyQt5-2.12.1, PyQtWebengine y Pyqtchart, con la version 3.5. Bug de Pyinstaller. Probar mas adelante. Comprobado el 20190720
if hasattr(sys,'frozen'): #CREO QUE CON ESTO SI FUNCIONARIA EN 2.13
sys.path.append( sys._MEIPASS)
print(sys.path)
{0}.main()
""".format(module))
f.close()
##Para depurar poner --debug bootloader y quitar --onefile y --windowed
os.system("""pyinstaller -n {}-{} --icon caloriestracker/images/caloriestracker.ico --onefile --windowed \
--noconfirm --distpath ./dist --clean {} \
--add-data caloriestracker/i18n/caloriestracker_en.qm;i18n \
--add-data caloriestracker/i18n/caloriestracker_es.qm;i18n \
--add-data caloriestracker/i18n/caloriestracker_fr.qm;i18n \
--add-data caloriestracker/i18n/caloriestracker_ro.qm;i18n \
--add-data caloriestracker/i18n/caloriestracker_ru.qm;i18n \
--add-data caloriestracker/sql/*.sql;sql
""".format(name,__version__,filename))
class Reusing(Command):
description = "Use code from https://github.com/turulomio/reusingcode"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from sys import path
path.append("caloriestracker")
from github import download_from_github
download_from_github('turulomio','reusingcode','python/admin_pg.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/call_by_name.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/casts.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/database_update.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/libmanagers.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/connection_pg.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/connection_pg_qt.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/ui/frmAccess.ui', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/frmAccess.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/frmSelector.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/myqcharts.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/myqdialog.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/myqwidgets.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/myqtablewidget.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/wdgDatetime.ui', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/wdgDatetime.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/wdgYearMonth.ui', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/ui/wdgYearMonth.py', 'caloriestracker/ui')
download_from_github('turulomio','reusingcode','python/package_resources.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/translationlanguages.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/datetime_functions.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/text_inputs.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/decorators.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/sqlparser.py', 'caloriestracker')
download_from_github('turulomio','reusingcode','python/objects/percentage.py', 'caloriestracker/objects')
download_from_github('turulomio','reusingcode','python/objects/currency.py', 'caloriestracker/objects')
download_from_github('turulomio','reusingcode','python/ui/wdgDistributeAmount.py', 'caloriestracker/ui')
class Compile(Command):
description = "Compile ui and images"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
futures=[]
with ProcessPoolExecutor(max_workers=cpu_count()+1) as executor:
for filename in os.listdir("caloriestracker/ui/"):
if filename.endswith(".ui"):
without_extension=filename[:-3]
futures.append(executor.submit(os.system, "pyuic5 caloriestracker/ui/{0}.ui -o caloriestracker/ui/Ui_{0}.py".format(without_extension)))
futures.append(executor.submit(os.system, "pyrcc5 caloriestracker/images/caloriestracker.qrc -o caloriestracker/images/caloriestracker_rc.py"))
# Overwriting caloriestracker_rc
for filename in os.listdir("caloriestracker/ui/"):
if filename.startswith("Ui_"):
os.system("sed -i -e 's/caloriestracker_rc/caloriestracker.images.caloriestracker_rc/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from myqcharts/from caloriestracker.ui.myqcharts/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from myqlineedit/from caloriestracker.ui.myqlineedit/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from myqtablewidget/from caloriestracker.ui.myqtablewidget/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from myqdoublespinbox/from caloriestracker.ui.myqdoublespinbox/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from caloriestracker.ui.myqlineedit/from caloriestracker.ui.myqlineedit/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from wdgDatetime/from caloriestracker.ui.wdgDatetime/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from wdgBiometrics/from caloriestracker.ui.wdgBiometrics/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from wdgYear/from caloriestracker.ui.wdgYear/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from wdgDistributeAmount/from caloriestracker.ui.wdgDistributeAmount/' caloriestracker/ui/{}".format(filename))
os.system("sed -i -e 's/from frmSelector/from caloriestracker.ui.frmSelector/' caloriestracker/ui/{}".format(filename))
class Uninstall(Command):
description = "Uninstall installed files with install"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if platform.system()=="Linux":
os.system("rm -Rf build") #sql were not erased
os.system("rm -Rf {}/caloriestracker*".format(site.getsitepackages()[0]))
os.system("rm /usr/bin/caloriestracker*")
os.system("rm /usr/share/pixmaps/caloriestracker.png")
os.system("rm /usr/share/applications/caloriestracker.desktop")
else:
print(site.getsitepackages())
for file in os.listdir(site.getsitepackages()[1]):#site packages
path=site.getsitepackages()[1]+"\\"+ file
if file.find("caloriestracker")!=-1:
shutil.rmtree(path)
print(path, "Erased")
for file in os.listdir(site.getsitepackages()[0]+"\\Scripts\\"):#Scripts
path=site.getsitepackages()[0]+"\\scripts\\"+ file
if file.find("caloriestracker")!=-1:
os.remove(path)
print(path, "Erased")
class Procedure(Command):
description = "Uninstall installed files with install"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("""
Nueva versión:
* Cambiar la versión y la fecha en version.py
* Modificar el Changelog en README
* python setup.py doc
* linguist
* python setup.py doc
* python setup.py install
* python setup.py doxygen
* git commit -a -m 'caloriestracker-{}'
* git push
* Hacer un nuevo tag en GitHub
* python setup.py sdist upload -r pypi
* python setup.py uninstall
* Crea un nuevo ebuild de Gentoo con la nueva versión
* Subelo al repositorio del portage
* Change to windows. Enter in an Administrator console.
* Change to caloriestracker source directory and make git pull
* python setup.py pyinstaller
* Add file to github release
""".format(__version__))
class Dump(Command):
description = "Creates a database dump. Must be used before changing schema"
user_options = [
# The format is (long option, short option, description).
( 'user=', None, 'Database user'),
( 'db=', None, 'Database name'),
( 'port=', None, 'Database port'),
( 'server=', None, 'Database server'),
]
def initialize_options(self):
self.user="postgres"
self.db="caloriestracker"
self.port="5432"
self.server="127.0.0.1"
def finalize_options(self):
pass
def run(self):
dt=datetime.now()
dts="{}{}{}{}{}".format(dt.year, str(dt.month).zfill(2), str(dt.day).zfill(2), str(dt.hour).zfill(2), str(dt.minute).zfill(2))
os.system("pg_dump -U {} -h {} --port {} {} > caloriestracker-{}.sql".format(self.user,self.server,self.port,self.db, dts))
class Doc(Command):
description = "Update translation librarys and hardcoded strings"
user_options = [
# The format is (long option, short option, description).
( 'user=', None, 'Database user'),
( 'db=', None, 'Database name'),
( 'port=', None, 'Database port'),
( 'server=', None, 'Database server'),
]
def initialize_options(self):
self.user="postgres"
self.db="caloriestracker"
self.port="5432"
self.server="127.0.0.1"
def finalize_options(self):
pass
def run(self):
from caloriestracker.connection_pg import Connection
con=Connection()
con.user=self.user
con.server=self.server
con.port=self.port
con.db=self.db
con.get_password("", "")
con.connect()
print("Is connection active?", con.is_active())
f=open("caloriestracker/hardcoded_strings.py", "w", encoding='utf-8')
f.write("from PyQt5.QtWidgets import QApplication\n")
rows=con.cursor_rows("select distinct(name) from products where companies_id is Null and elaboratedproducts_id is null order by name")
for row in rows:
f.write("QApplication.translate('HardcodedStrings','{}')\n".format(row["name"]))
f.write("\n#Formats\n")
rows=con.cursor_rows("select distinct(name) from formats order by name")
for row in rows:
f.write("QApplication.translate('HardcodedStrings','{}')\n".format(row["name"]))
f.write("\n#Foodtypes\n")
rows=con.cursor_rows("select * from foodtypes order by name")
for row in rows:
f.write("QApplication.translate('HardcodedStrings','{}')\n".format(row["name"]))
f.close()
con.disconnect()
os.system("pylupdate5 -noobsolete -verbose caloriestracker.pro")
os.system("lrelease -qt5 caloriestracker.pro")
print("Updating Entity Relationship Schema")
os.chdir("doc/html")
os.system("/usr/bin/postgresql_autodoc -d {} -h {} -u {} -p {} --password={} -t html".format(self.db,self.server,self.user, self.port,con.password))
os.system("/usr/bin/postgresql_autodoc -d {} -h {} -u {} -p {} --password={} -t dot_shortfk".format(self.db,self.server,self.user, self.port,con.password))
os.system("dot -Tpng {0}.dot_shortfk -o {0}_er.png".format(self.db))
########################################################################
#Description
#with open('README.md', encoding='utf-8') as f:
# long_description = f.read()
long_description="Home page is https://github.com/turulomio/caloriestracker" #Just for pypi upload
#entry_points
entry_points={
'console_scripts': [
'caloriestracker_console=caloriestracker.caloriestracker_console:main',
'caloriestracker_maintenance_products_system2personal=caloriestracker.caloriestracker_maintenance:products_system2personal',
],
'gui_scripts': [
'caloriestracker=caloriestracker.caloriestracker:main',
],
}
if platform.system()=="Windows":
entry_points['console_scripts'].append( 'caloriestracker_shortcuts=caloriestracker.shortcuts:create',)
#data_files
if platform.system()=="Linux":
data_files=[
('/usr/share/pixmaps/', ['caloriestracker/images/caloriestracker.png']),
('/usr/share/applications/', ['caloriestracker.desktop']),
]
else:
data_files=[]
#__version__
__version__= None
with open('caloriestracker/version.py', encoding='utf-8') as f:
for line in f.readlines():
if line.find("__version__ =")!=-1:
__version__=line.split("'")[1]
setup(name='caloriestracker',
version=__version__,
description='Calories tracker system',
long_description=long_description,
long_description_content_type='text/markdown',
classifiers=['Development Status :: 4 - Beta',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 3',
],
keywords='calories tracker',
url='https://github.com/turulomio/caloriestracker',
author='Turulomio',
author_email='[email protected]',
license='GPL-3',
packages=['caloriestracker'],
entry_points = entry_points,
install_requires= [ 'setuptools',
'psycopg2',
'pytz',
'colorama',
'officegenerator',
'PyQtChart;platform_system=="Windows"',
'PyQtWebEngine;platform_system=="Windows"',
'PyQt5;platform_system=="Windows"',
'pywin32;platform_system=="Windows"',
], #PyQt5 and PyQtChart doesn't have egg-info in Gentoo, so I remove it to install it with ebuild without making 2 installations. Should be added manually when using pip to install
data_files=data_files,
cmdclass={
'compile': Compile,
'doc': Doc,
'doxygen': Doxygen,
'dump': Dump,
'procedure': Procedure,
'pyinstaller': PyInstaller,
'reusing': Reusing,
'uninstall':Uninstall,
},
zip_safe=False,
include_package_data=True
)