-
Notifications
You must be signed in to change notification settings - Fork 54
/
setup.py
executable file
·181 lines (150 loc) · 6.63 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
#!/usr/bin/env python3
import sys
from configparser import ConfigParser
import xml.etree.cElementTree as ET
def get_files(path):
files = []
for name in os.listdir(path):
files.append(os.path.join(path, name))
return files
def generate_appdata(prefix, bundle_id):
info = ConfigParser()
info.read(os.path.join('activity', 'activity.info'))
required_fields = ['metadata_license', 'license', 'name', 'icon',
'description']
for name in required_fields:
if not info.has_option('Activity', name):
print('[WARNING] Activity needs more metadata for AppStream '
'file')
print(' Without an AppStream file, the activity will NOT '
'show in software stores!')
print(' Please `pydoc sugar3.activity.bundlebuilder` for'
'more info')
return
# See https://www.freedesktop.org/software/appstream/docs/
root = ET.Element('component', type='desktop-application')
ET.SubElement(root, 'translation', type='gettext').text = \
bundle_id
ET.SubElement(root, 'id').text = bundle_id
ET.SubElement(root, 'launchable', type='desktop-id').text = \
bundle_id + ".desktop"
desc = ET.fromstring('<description><p>{}</p></description>'.format(
info.get('Activity', 'description')))
root.append(desc)
ET.SubElement(root, 'content_rating', type='oars-1.1')
release_pairs = [('220', '2019-09-28'),
('218', '2018-05-22'),
('216', '2017-06-24'),
('215', '2017-04-19')]
releases_root = ET.SubElement(root, 'releases')
for version, date in release_pairs:
ET.SubElement(releases_root, 'release', date=date, version=version)
license_map = {
'GPLv2+': 'GPL-2.0-or-later',
'GPLv3+': 'GPL-3.0-or-later',
'LGPLv2+': 'LGPL-2.0-or-later',
'LGPLv2.1+': 'LGPL-2.1-or-later',
}
licenses = info.get('Activity', 'license').split(';')
spdx_licenses = [license_map.get(x, x) for x in licenses]
ET.SubElement(root, 'project_license').text = " AND ".join(spdx_licenses)
copy_pairs = [('metadata_license', 'metadata_license'),
('summary', 'summary'),
('name', 'name')]
for key, ename in copy_pairs:
ET.SubElement(root, ename).text = info.get('Activity', key)
if info.has_option('Activity', 'screenshots'):
screenshots = info.get('Activity', 'screenshots').split(',')
ss_root = ET.SubElement(root, 'screenshots')
for i, screenshot in enumerate(screenshots):
e = ET.SubElement(ss_root, 'screenshot')
if i == 0:
e.set('type', 'default')
ET.SubElement(e, 'image').text = screenshot.strip()
if info.has_option('Activity', 'url'):
ET.SubElement(root, 'url', type='homepage').text = \
info.get('Activity', 'url')
if info.has_option('Activity', 'repository_url'):
ET.SubElement(root, 'url', type='bugtracker').text = \
info.get('Activity', 'repository_url')
elif info.has_option('Activity', 'repository'):
ET.SubElement(root, 'url', type='bugtracker').text = \
info.get('Activity', 'repository')
path = os.path.join(prefix, 'share', 'metainfo',
bundle_id + '.appdata.xml')
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
tree = ET.ElementTree(root)
tree.write(path, encoding='UTF-8')
if len(sys.argv) > 1 and '--no-sugar' == sys.argv[1]:
# Remove the argument from the stack so we don't cause problems
# for distutils
sys.argv.pop(1)
import os
import shutil
import subprocess
from setuptools import setup
from setuptools.command.install import install
class post_install(install):
def run(self):
install.run(self)
print("Running post_install")
generate_appdata(self.prefix,
'org.laptop.TurtleArtActivity')
# Create a simple module that allows the app where to discover
# its lib and share content.
dst = os.path.join(self.install_purelib, "TurtleArt")
fd = open(os.path.join(dst, "installinfo.py"), "w")
fd.write("INSTALL_PREFIX='%s'\n" % self.prefix)
fd.close()
root = self.root or ''
# distutils doesn't offer a nice way to do recursive install of
# a directory tree, so we install the remaining parts here.
libdir = os.path.join(root + self.install_base, "lib",
"TurtleBlocks")
if not os.path.isdir(libdir):
os.makedirs(libdir)
sharedir = os.path.join(root + self.install_base, "share",
"TurtleBlocks")
if not os.path.isdir(sharedir):
os.makedirs(sharedir)
shutil.copytree("plugins", os.path.join(libdir, "plugins"))
shutil.copytree("samples", os.path.join(sharedir, "samples"))
localedir = os.path.join(root + self.install_base, "share",
"locale")
for f in os.listdir('po'):
if not f.endswith('.po') or f == 'pseudo.po':
continue
file_name = os.path.join('po', f)
lang = f[:-3]
mo_path = os.path.join(localedir, lang, 'LC_MESSAGES')
if not os.path.isdir(mo_path):
os.makedirs(mo_path)
mo_file = os.path.join(
mo_path, 'org.laptop.TurtleArtActivity.mo')
retcode = subprocess.call(
['msgfmt', '--output-file=%s' % mo_file, file_name])
if retcode:
print('ERROR - msgfmt failed with return code %i.'
% retcode)
DATA_FILES = [
('activity', get_files('activity/')),
('icons', get_files('icons/')),
('images', get_files('images/')),
('/usr/share/applications', ['turtleblocks.desktop']),
('org.laptop.TurtleArtActivity.gschema.xml')
]
setup(name='Turtle Art',
description="A LOGO-like tool for teaching programming",
author="Walter Bender",
author_email="walter.bender@gmail.com",
version='0.9.4',
packages=['TurtleArt', 'TurtleArt.util'],
scripts=['turtleblocks'],
data_files=DATA_FILES,
cmdclass={"install": post_install}
)
else:
from sugar3.activity import bundlebuilder
if __name__ == "__main__":
bundlebuilder.start()