-
Notifications
You must be signed in to change notification settings - Fork 187
/
setup.py
executable file
·167 lines (149 loc) · 5.51 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
#!/usr/bin/env python
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import os
import sys
import codecs
try:
import py2exe
except ImportError:
pass
import re
here = os.path.abspath(os.path.dirname(__file__))
def get_global_str_from_file(rel_filepath, var):
prog = re.compile(r'^{0} = ("|\')(.*?)("|\')'.format(var))
with open(os.path.join(here, rel_filepath), 'r') as f:
for line in f.readlines():
res = prog.match(line)
if res is not None:
return str(res.group(2))
initFile = 'cherrymusicserver/__init__.py'
VERSION = get_global_str_from_file(initFile, 'VERSION')
DESCRIPTION = get_global_str_from_file(initFile, 'DESCRIPTION')
import gzip
def gzipManPages():
localManPagePath = 'doc/man'
for manpage in os.listdir(localManPagePath):
#man pages end in numbers
if manpage.endswith(tuple(map(str,range(10)))):
manpagefn = os.path.join(localManPagePath, manpage)
with open(manpagefn, 'rb') as manfile:
manfilegz = gzip.open(manpagefn+'.gz', 'wb')
manfilegz.writelines(manfile)
manfilegz.close()
def list_files_in_dir(crawlpath, installpath, filterfunc=None, excluded_paths=None):
all_files = []
for dirpath, dirnames, filenames in os.walk(crawlpath):
if excluded_paths and any(dirpath.startswith(path) for path in excluded_paths):
continue
files = []
for filename in filenames:
if filterfunc:
if not filterfunc(filename):
continue
files += [os.path.join(dirpath, filename)]
all_files += [(os.path.join(installpath, dirpath), files)]
return all_files
def module(foldername):
ret = [foldername]
for i in os.listdir(foldername):
if i == '__pycache__':
continue
subfolder = os.path.join(foldername, i)
if os.path.isdir(subfolder) and _ispackage(subfolder):
ret += module(subfolder)
ret += [subfolder.replace(os.sep,'.')]
return ret
def _ispackage(foldername):
return '__init__.py' in os.listdir(foldername)
def read(*parts):
return codecs.open(os.path.join(here, *parts), 'r').read()
def packagedata(pkgfolder, childpath=''):
ret = []
for n in os.listdir(os.path.join(pkgfolder, childpath)):
if n == '__pycache__':
continue
child = os.path.join(childpath, n)
fullchild = os.path.join(pkgfolder, child)
if os.path.isdir(fullchild):
if not _ispackage(fullchild):
ret += packagedata(pkgfolder, child)
elif os.path.isfile(fullchild):
if not os.path.splitext(n)[1].startswith('.py'):
ret += [child]
return ret
#setup preparations:
gzipManPages()
pathproviderFile = os.path.join('cherrymusicserver/pathprovider.py')
shareFolder = os.path.join(
'share', get_global_str_from_file(pathproviderFile, 'sharedFolderName')
)
# files to put in /usr/share
data_files = list_files_in_dir(
'res',
shareFolder,
excluded_paths=['res/react-client/node_modules']
)
long_description = None
if 'upload' in sys.argv or 'register' in sys.argv:
readmemd = "\n" + "\n".join([read('README.md')])
print("converting markdown to reStucturedText for upload to pypi.")
from urllib.request import urlopen
from urllib.parse import quote
import json
url = 'http://pandoc.org/cgi-bin/trypandoc?from=markdown&to=rst&text=%s'
urlhandler = urlopen(url % quote(readmemd))
result = json.loads(codecs.decode(urlhandler.read(), 'utf-8'))
long_description = result['html']
else:
long_description = "\n" + "\n".join([read('README.md')])
setup_options = {
'name': 'CherryMusic',
'version': VERSION,
'description': DESCRIPTION,
'long_description': long_description,
'author': 'Tom Wallroth & Tilman Boerner',
'author_email': '[email protected], [email protected]',
'url': 'http://www.fomori.org/cherrymusic/',
'license': 'GPLv3',
'install_requires': ['CherryPy >= 3.2.2'],
'packages': module('cherrymusicserver')+module('tinytag')+module('audiotranscode')+module('cmbootstrap')+module('backport'),
'package_data': {
'cherrymusicserver.database.defs': packagedata('cherrymusicserver/database/defs'),
},
#startup script
'scripts': ['cherrymusic','cherrymusicd','cherrymusic-tray'],
'classifiers': [
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Web Environment',
'Framework :: CherryPy',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
'Natural Language :: English',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Multimedia',
'Topic :: Multimedia :: Sound/Audio :: Players',
],
'data_files': data_files
}
if os.name == 'nt':
#py2exe specific
setup_options['console'] = [
{
'icon_resources': [(1, 'res/favicon.ico')],
'script':'cherrymusic'
}
]
setup(**setup_options)