-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·130 lines (106 loc) · 4.67 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
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import glob
from distutils.core import setup
from bkchem import config
## A few pre-setup hacks
if os.name != 'posix':
sys.path.insert(0, 'bkchem')
# all the apicdoc directories and files
apidocs = [('share/doc/bkchem/'+path[4:], map(os.path.join, len(filenames)*[path], filenames))
for (path, dirnames, filenames) in os.walk('doc/api')]
# available languages to pack
langs = [l for l in os.listdir('locale')
if (os.path.isdir('locale/' + l) and
os.path.exists('locale/' + l + '/LC_MESSAGES/BKChem.mo'))]
print("found languages:", langs)
localizations = [('share/locale/' + lang + '/LC_MESSAGES', ['locale/' + lang + '/LC_MESSAGES/BKChem.mo'])
for lang in langs]
# should we strip something from in the scripts from the installation path (used in gentoo sandboxing etc.)
strip = ""
for arg in sys.argv:
if arg.startswith("--strip="):
strip = arg.lstrip("--strip=")
sys.argv.remove(arg)
break
def strip_path(path):
if path.startswith(strip):
new = path.replace(strip, "", 1)
return new
else:
return path
# the setup itself
conf = setup(
name = 'bkchem',
version = config.current_BKChem_version,
description = "BKChem is a chemical drawing program written in Python",
author = "Beda Kosata",
author_email = "[email protected]",
maintainer = "Reinis Danne",
maintainer_email = "[email protected]",
url = "http://bkchem.zirael.org",
license = "GNU GPL",
platforms = ["Unix", "Windows", "hopefully other OSes able to run Python"],
long_description = "BKChem is a chemical drawing program written in Python",
packages = ['bkchem',
'bkchem/plugins',
'bkchem/oasa',
'bkchem/oasa/oasa',
'bkchem/oasa/oasa/graph',
'bkchem/plugins/piddle'],
data_files = [('share/bkchem/templates', glob.glob('templates/*.cdml') + glob.glob('templates/*.xml')),
('share/bkchem/images', ['images/logo.ppm','images/icon.ico'] + glob.glob('images/bkchem*.png')),
('share/bkchem/pixmaps', glob.glob('pixmaps/*.gif')),
('share/bkchem/dtd', glob.glob('dtd/*.dtd') + glob.glob('dtd/*.xsd')),
('share/bkchem/plugins', glob.glob('plugins/*.py') + glob.glob('plugins/*.xml')),
('share/doc/bkchem', glob.glob('doc/*.xml') + glob.glob('doc/*.html') + ['README', 'INSTALL', 'progress.log']),
#('share/doc/bkchem/pdf', glob.glob( 'doc/pdf/*')),
('share/doc/bkchem/html', glob.glob('doc/html/*')),
('share/doc/bkchem/scripts', glob.glob('doc/scripts/*')),
('share/doc/bkchem/img', glob.glob('doc/img/*')),
] + localizations + apidocs,
)
if len( sys.argv) > 1 and sys.argv[1] == 'install' and '--help' not in sys.argv:
data_dir = conf.command_obj['install'].install_data
py_dir = conf.command_obj['install'].install_lib
bin_dir = conf.command_obj['install'].install_scripts
# the configuration file
config_name = os.path.join(py_dir, 'bkchem/site_config.py')
try:
f = open(config_name, 'w')
except IOError:
print("ERROR: couldn't open the file %s for write" % config_name)
sys.exit()
f.write("# the bkchem configuration file, do not edit!\n #(unless you are pretty sure that you know what you are doing, which even I am not)\n")
f.write('BKCHEM_MODULE_PATH="%s"\n' % strip_path( os.path.join( py_dir, "bkchem")))
f.write('BKCHEM_TEMPLATE_PATH="%s"\n' % strip_path( os.path.join( data_dir, "share/bkchem/templates")))
f.write('BKCHEM_PIXMAP_PATH="%s"\n' % strip_path( os.path.join( data_dir, "share/bkchem/pixmaps")))
f.write('BKCHEM_IMAGE_PATH="%s"\n' % strip_path( os.path.join( data_dir, "share/bkchem/images")))
f.write('BKCHEM_PLUGIN_PATH="%s"\n' % strip_path( os.path.join( data_dir, "share/bkchem/plugins")))
f.close()
print("file %s created" % config_name)
# the executable
if not os.path.isdir(bin_dir):
try:
os.mkdir(bin_dir)
except IOError:
print("ERROR: could not create directory %s" % bin_dir)
sys.exit( 201)
exec_name = os.path.join(bin_dir, 'bkchem')
try:
f = open(exec_name, 'w')
except IOError:
print("ERROR: couldn't open the file %s for write" % exec_name)
sys.exit(201)
f.write("#!/bin/sh\n")
f.write('python %s "$@"\n' % strip_path(os.path.join(py_dir, "bkchem", "bkchem.py")))
f.close()
print("file %s created" % exec_name)
try:
os.chmod(os.path.join(bin_dir, 'bkchem'), 5+5*8+7*8*8)
except IOError:
print("ERROR: failed to make %s executable" % exec_name)
sys.exit( 201)
print("file %s made executable" % exec_name)