-
Notifications
You must be signed in to change notification settings - Fork 20
/
setup.py
219 lines (177 loc) · 6.44 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
# coding=utf-8
#!/usr/bin/env python
from setuptools import setup, Command, find_packages
#import versioneer
DESCRIPTION = "A multiroom audio server based on Mopidy and Snapcast"
LONG_DESCRIPTION = ""
EXTRAS_FOLDERS = [
("/etc/hydraplay.conf.d", 0o755)
]
EXTRAS_FILES = [
("/etc/init.d/", [("extras/hydraplay.init", "hydraplay", 0o755)]),
("/etc/default/", [("extras/hydraplay.default", "hydraplay", 0o644)]),
("/etc/logrotate.d/", [("extras/hydraplay.logrotate", "hydraplay", 0o644)]),
]
def get_extra_tuple(entry):
import os
if isinstance(entry, (tuple, list)):
if len(entry) == 2:
path, mode = entry
filename = os.path.basename(path)
elif len(entry) == 3:
path, filename, mode = entry
elif len(entry) == 1:
path = entry[0]
filename = os.path.basename(path)
mode = None
else:
return None
else:
path = entry
filename = os.path.basename(path)
mode = None
return path, filename, mode
class InstallExtrasCommand(Command):
description = "install extras like init scripts and config files"
user_options = [("force", "F", "force overwriting files if they already exist")]
def initialize_options(self):
self.force = None
def finalize_options(self):
if self.force is None:
self.force = False
def run(self):
global EXTRAS_FILES, EXTRAS_FOLDERS
import shutil
import os
for folder, mode in EXTRAS_FOLDERS:
try:
if os.path.exists(folder):
os.chmod(folder, mode)
else:
os.mkdir(folder, mode)
except Exception as e:
import sys
print(("Error while creating %s (%s), aborting" % (folder, e.message)))
sys.exit(-1)
for target, files in EXTRAS_FILES:
for entry in files:
extra_tuple = get_extra_tuple(entry)
if extra_tuple is None:
print(
(
"Can't parse entry for target %s, skipping it: %r"
% (target, entry)
)
)
continue
path, filename, mode = extra_tuple
target_path = os.path.join(target, filename)
path_exists = os.path.exists(target_path)
if path_exists and not self.force:
print(
(
"Skipping copying %s to %s as it already exists, use --force to overwrite"
% (path, target_path)
)
)
continue
try:
shutil.copy(path, target_path)
if mode:
os.chmod(target_path, mode)
print(
(
"Copied %s to %s and changed mode to %o"
% (path, target_path, mode)
)
)
else:
print(("Copied %s to %s" % (path, target_path)))
except Exception as e:
if not path_exists and os.path.exists(target_path):
# we'll try to clean up again
try:
os.remove(target_path)
except:
pass
import sys
print(
(
"Error while copying %s to %s (%s), aborting"
% (path, target_path, e.message)
)
)
sys.exit(-1)
class UninstallExtrasCommand(Command):
description = "uninstall extras like init scripts and config files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
global EXTRAS_FILES, EXTRAS_FOLDERS
import os
for target, files in EXTRAS_FILES:
for entry in files:
extra_tuple = get_extra_tuple(entry)
if extra_tuple is None:
print(
(
"Can't parse entry for target %s, skipping it: %r"
% (target, entry)
)
)
path, filename, mode = extra_tuple
target_path = os.path.join(target, filename)
try:
os.remove(target_path)
print(("Removed %s" % target_path))
except Exception as e:
print(
(
"Error while deleting %s from %s (%s), please remove manually"
% (filename, target, e.message)
)
)
for folder, mode in EXTRAS_FOLDERS[::-1]:
try:
os.rmdir(folder)
except Exception as e:
print(
(
"Error while removing %s (%s), please remove manually"
% (folder, e.message)
)
)
def params():
name = "hydraplay"
version = "0.7.3"
description = DESCRIPTION
long_description = LONG_DESCRIPTION
author = "Mario Lukas"
author_email = "info@mariolukas.de"
url = "http://github.com/mariolukas/hydraplay"
license = "GPLV3"
#packages = ["hydraplay"]
zip_safe = False
packages = find_packages(where="src")
package_dir = {
"": "src",
}
cmdclass = {
"install_extras": InstallExtrasCommand,
"uninstall_extras": UninstallExtrasCommand,
}
install_requires = ["tornado", "jinja2"]
package_data = {'hydraplay': ['config/*json', 'config/templates/*.j2', 'server/static/*','server/static/snapweb/*','server/static/snapweb/3rd-party/*','server/static/player/*' 'server/static/player/assets/images/*']}
include_package_data = True
#include_package_data = True
entry_points = {
"console_scripts": {
"hydraplay = hydraplay.main:main"
}
}
scripts = ['src/hydraplay.sh']
return locals()
setup(**params())