forked from mysql/mysql-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.py
184 lines (160 loc) · 6.52 KB
/
info.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
#
# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
"""This module containts the Metadata for Python Software Packages"""
import glob
import os
import mysql.utilities
def find_packages(*args, **kwrds):
"""Find all packages and sub-packages and return a list of them.
The function accept any number of directory names that will be
searched to find packages. Packages are identified as
sub-directories containing an __init__.py file. All duplicates
will be removed from the list and it will be sorted
alphabetically.
Packages can be excluded by pattern using the 'exclude' keyword,
which accepts a list of patterns. All packages with names that
match the beginning of an exclude pattern will be excluded.
Root base path can be attached to each package by using 'inc_base'
keyword.
"""
from fnmatch import fnmatch
excludes = kwrds.get('exclude', [])
inc_base = kwrds.get('inc_base', False)
pkgs = {}
for base_path in args:
for root, _, files in os.walk(base_path):
if '__init__.py' in files:
assert root.startswith(base_path)
pkg = root[len(base_path)+1:].replace(os.sep, '.')
if inc_base and pkg:
pkg = os.path.join(base_path, pkg).replace(os.sep, '.')
elif inc_base:
pkg = base_path.replace(os.sep, '.')
pkgs[pkg] = root
result = pkgs.keys()
for excl in excludes:
# We exclude packages that *begin* with an exclude pattern.
result = [pkg for pkg in result if not fnmatch(pkg, excl + "*")]
result.sort()
return result
def add_optional_resources(*args, **kwrds):
"""Adds additional resources, as source packages, scripts and data files.
The function will try to find all resources in the directory names given,
that will be searched to find packages, data files and scripts.
Packages are identified as sub-directories containing an __init__.py file.
All duplicates will be removed from the list and it will be sorted
alphabetically. This function uses the find_packages function; see his
help to know more how packages are found.
Scripts must be set on 'scripts', and a list of the desired scripts to add
must be given by 'scripts' keyword.
Data files can be set in a dictionary with the keyword
'data_files', where destination is used as key and a list of source files,
are the item for that key.
"""
excludes = kwrds.get('exclude', [])
inc_base = kwrds.get('inc_base', True)
data_files = kwrds.get('data_files', {})
packages_found = []
pkg_base = args[0]
print('checking {0} for packages to distribute'.format(pkg_base))
pkgs = find_packages(pkg_base, exclude=excludes, inc_base=inc_base)
print("packages found: {0}".format(pkgs))
packages_found.extend(pkgs)
scripts_found = []
for _, _, scripts in os.walk('scripts'):
for script in scripts:
script_path = os.path.join('scripts', script)
if not script_path.endswith('.py') and \
not os.path.exists('{0}.py'.format(script_path)):
os.rename(script_path, '{0}.py'.format(script_path))
script_path = '{0}.py'.format(script_path)
if script_path.endswith('.py'):
scripts_found.append(script_path)
print("scripts found: {0}".format(scripts_found))
data_files_found = []
for _, _, data_files in os.walk('data'):
datafiles = []
zipfiles = []
otherfiles = []
for src in data_files:
_, ext = os.path.splitext(src)
if ext == '.zip' and os.name != 'nt':
zipfiles.append(os.path.join('data', src))
else:
datafiles.append(os.path.join('data', src))
if datafiles:
data_files_found.append(('data', datafiles))
if zipfiles:
data_files_found.append(('/etc/mysql', zipfiles))
if otherfiles:
data_files_found.append(('other', otherfiles))
if packages_found:
INSTALL['packages'].extend(packages_found)
print("package set {0}".format(set(INSTALL['packages'])))
INSTALL['packages'] = list(set(INSTALL['packages']))
if scripts_found:
INSTALL['scripts'].extend(scripts_found)
INSTALL['scripts'] = list(set(INSTALL['scripts']))
if data_files_found:
INSTALL['data_files'] = data_files_found
META_INFO = {
'name': 'mysql-utilities',
'description': 'MySQL Utilities',
'maintainer': 'Oracle',
'maintainer_email': '',
'version': mysql.utilities.VERSION_STRING,
'url': 'http://dev.mysql.com',
'license': 'GNU GPLv2 (with FOSS License Exception)',
'keywords': "mysql db",
'classifiers': [
'Development Status :: 3 - Alpha',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Environment :: Console',
'Environment :: Win32 (MS Windows)',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: Database Administrators',
'Operating System :: Microsoft :: Windows',
'Operating System :: OS Independent',
'Operating System :: POSIX',
'Topic :: Utilities',
],
}
INSTALL = {
'packages': [
'mysql',
'mysql.utilities',
'mysql.utilities.command',
'mysql.utilities.common',
],
'scripts': glob.glob('scripts/*.py'),
'requires': [
'distutils',
],
'provides': [
'mysql.utilities',
],
}
# This adds any optional resource
add_optional_resources('mysql', exclude=["tests"])
if __name__ == "__main__":
for key, item in INSTALL.iteritems():
print("--> {0}".format(key))
print(" {0}".format(item))
print