-
Notifications
You must be signed in to change notification settings - Fork 137
/
setup.py
156 lines (124 loc) · 3.89 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
import os
from pathlib import Path
from distutils.core import Command
import setuptools
from gourmet import version
package = 'gourmet'
podir = Path('po')
langs = sorted(f.name[:-3] for f in podir.glob('*.po'))
def modir(lang):
mobase = Path("build")
return mobase / "mo" / lang
def mkmo(lang):
outpath = modir(lang)
os.makedirs(outpath, exist_ok=True)
inpath = podir / (lang + ".po")
cmd = f"msgfmt {inpath} -o {outpath}/{package}.mo"
os.system(cmd)
def merge_i18n():
cmd = "LC_ALL=C intltool-merge -u -c ./po/.intltool-merge-cache ./po"
for infile in Path('.').rglob('*.in'):
outfile = Path(str(infile)[:-3])
extension = outfile.suffix
if 'desktop' in extension:
flag = '-d'
elif 'schema' in extension:
flag = '-s'
elif 'xml' in extension:
flag = '-x'
elif 'gourmet-plugin' in extension:
flag = '-k'
else:
flag = ''
if flag:
print(f"Processing {infile} to {outfile}")
os.system(f"{cmd} {flag} {infile} {outfile}")
def polist():
dst_tmpl = "share/locale/%s/LC_MESSAGES/"
polist = [(dst_tmpl % x, ["%s/%s.mo" % (modir(x), package)])
for x in langs]
return polist
class build_i18n(Command):
description = "Create/update po/pot translation files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("Creating POT file")
cmd = f"cd po; intltool-update --pot --gettext-package={package}"
os.system(cmd)
for lang in langs:
print(f"Updating {lang} PO file")
cmd = ("cd po; intltool-update --dist"
f"--gettext-package={package} {lang} >/dev/null 2>&1")
os.system(cmd)
mkmo(lang)
merge_i18n()
def crawl_plugins(base, basename):
plugins = []
subdirs = filter(lambda x: os.path.isdir(os.path.join(base, x)),
os.listdir(base))
for subd in subdirs:
name = basename + '.' + subd
plugins.append(name)
plugins.extend(crawl_plugins(os.path.join(base, subd), name))
return plugins
plugins = crawl_plugins(os.path.join('gourmet', 'plugins'), 'gourmet.plugins')
package_data = [
'backends/default.db',
'plugins/*.gourmet-plugin',
'plugins/*/*.gourmet-plugin',
'data/recipe.dtd',
'data/WEIGHT.txt',
'data/FOOD_DES.txt',
'data/ABBREV.txt',
'data/nutritional_data_sr_version',
'data/images/no_star.png',
'data/images/reccard_edit.png',
'data/images/AddToShoppingList.png',
'data/images/half_gold_star.png',
'data/images/half_blue_star.png',
'data/images/gold_star.png',
'data/images/blue_star.png',
'data/images/reccard.png',
'data/sound/phone.wav',
'data/sound/warning.wav',
'data/sound/error.wav',
'data/icons/gourmet.ico',
'data/icons/scalable/apps/gourmet.svg',
'data/icons/48x48/apps/gourmet.png',
'data/style/epubdefault.css',
'data/style/default.css',
'plugins/*/*.ui',
'plugins/*/images/*.png',
'plugins/*/*/images/*.png',
'ui/*.ui',
'ui/catalog/*',
'../LICENSE',
'../FAQ',
]
setuptools.setup(
name=version.name,
version=version.version,
description=version.description,
author=version.author,
author_email=version.author_email,
url=version.website,
license=version.license,
packages=['gourmet',
'gourmet.backends',
'gourmet.defaults',
'gourmet.gtk_extras',
'gourmet.importers',
'gourmet.exporters',
'gourmet.plugins',
] + plugins,
package_data={'gourmet': package_data},
cmdclass={'build_i18n': build_i18n},
entry_points={
"console_scripts": [
"gourmet = gourmet.GourmetRecipeManager:launch_app",
]}
)