Skip to content

Commit c6b4eff

Browse files
author
Ferry Boender
committed
Implemented / fixed up Python package generation
1 parent fb7de99 commit c6b4eff

File tree

5 files changed

+59
-46
lines changed

5 files changed

+59
-46
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ ansible-cmdb*.deb
66
ansible-cmdb*.tar.gz
77
ansible-cmdb*.zip
88
example/gen_*
9+
build/
10+
dist/
11+
src/ansible_cmdb.egg-info/

Makefile

+29-25
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,34 @@ test:
1111
example:
1212
example/generate.sh
1313

14-
release_clean: clean
15-
@if [ "$(shell git status --porcelain)" != "" ]; then echo "Repo not clean. Not building"; exit 1; fi
16-
17-
release: release_src release_deb release_rpm
18-
1914
doc:
2015
markdown_py README.md > README.html
2116

22-
release_src: release_clean doc
23-
@echo "Making release for version $(REL_VERSION)"
17+
clean:
18+
rm -rf rel_deb
19+
rm -f *.rpm
20+
rm -f *.deb
21+
rm -f *.tar.gz
22+
rm -f *.zip
23+
rm -f README.html
24+
find ./ -name "*.pyc" -delete
25+
find ./ -name "__pycache__" -type d -delete
26+
rm -f example/gen_*
27+
rm -rf build/
28+
rm -rf dist/
29+
rm -rf src/ansible_cmdb.egg-info/
2430

31+
release_clean: clean
32+
#@if [ "$(shell git status --porcelain)" != "" ]; then echo "Repo not clean. Not building"; exit 1; fi
33+
34+
release_check:
35+
@echo "Making release for version $(REL_VERSION)"
2536
@if [ -z "$(REL_VERSION)" ]; then echo "REL_VERSION required"; exit 1; fi
2637

27-
# Cleanup
38+
release: release_check release_src release_deb release_rpm release_wheel
39+
40+
release_src: release_check release_clean doc
41+
# Cleanup. Only on release, since REL_VERSION doesn't exist otherwise
2842
rm -rf $(PROG)-$(REL_VERSION)
2943

3044
# Prepare source
@@ -47,12 +61,7 @@ release_src: release_clean doc
4761
zip -q -r $(PROG)-$(REL_VERSION).zip $(PROG)-$(REL_VERSION)
4862
tar -czf $(PROG)-$(REL_VERSION).tar.gz $(PROG)-$(REL_VERSION)
4963

50-
release_deb: release_clean doc
51-
@if [ -z "$(REL_VERSION)" ]; then echo "REL_VERSION required"; exit 1; fi
52-
53-
# Cleanup
54-
rm -rf rel_deb
55-
64+
release_deb: release_check release_clean doc
5665
mkdir -p rel_deb/usr/bin
5766
mkdir -p rel_deb/usr/lib/${PROG}
5867
mkdir -p rel_deb/usr/lib/${PROG}/mako
@@ -91,7 +100,7 @@ release_deb: release_clean doc
91100
# Lint
92101
lintian ansible-cmdb-*.deb
93102

94-
release_rpm: release_clean release_deb
103+
release_rpm: release_check release_clean release_deb
95104
alien -r -g $(PROG)-$(REL_VERSION).deb
96105
sed -i '\:%dir "/":d' $(PROG)-$(REL_VERSION)/$(PROG)-$(REL_VERSION)-2.spec
97106
sed -i '\:%dir "/usr/":d' $(PROG)-$(REL_VERSION)/$(PROG)-$(REL_VERSION)-2.spec
@@ -102,6 +111,11 @@ release_rpm: release_clean release_deb
102111
sed -i '\:%dir "/usr/bin/":d' $(PROG)-$(REL_VERSION)/$(PROG)-$(REL_VERSION)-2.spec
103112
cd $(PROG)-$(REL_VERSION) && rpmbuild --buildroot='$(shell readlink -f $(PROG)-$(REL_VERSION))/' -bb --target noarch '$(PROG)-$(REL_VERSION)-2.spec'
104113

114+
release_wheel: release_check release_clean
115+
echo "$(REL_VERSION)" > src/ansiblecmdb/data/VERSION
116+
python setup.py bdist_wheel --universal
117+
echo `git rev-parse --abbrev-ref HEAD | tr "[:lower:]" "[:upper:]"` > src/ansiblecmdb/data/VERSION
118+
105119
install:
106120
mkdir -p /usr/local/lib/$(PROG)
107121
mkdir -p /usr/local/man/man1
@@ -120,13 +134,3 @@ uninstall:
120134
rm -rf /usr/local/lib/$(PROG)
121135
rm -f /usr/local/man/man/ansible-cmdb.man.1.gz
122136
rm -rf /usr/local/bin/ansible-cmdb
123-
124-
clean:
125-
rm -f *.rpm
126-
rm -f *.deb
127-
rm -f *.tar.gz
128-
rm -f *.zip
129-
rm -f README.html
130-
find ./ -name "*.pyc" -delete
131-
find ./ -name "__pycache__" -type d -delete
132-
rm -f example/gen_*

setup.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ def get_long_description():
1111
with open(path) as f:
1212
return f.read()
1313

14-
1514
def get_version():
16-
setup_py = open('setup.py').read()
17-
return re.search('version=[\'"]([0-9]+\.[0-9]+(|\.[0-9]+))[\'"]', setup_py, re.MULTILINE).group(1)
15+
return open('src/ansiblecmdb/data/VERSION', 'r').read().strip()
1816

1917
def get_data_files(path, strip='', prefix=''):
2018
data_files = []
@@ -34,25 +32,27 @@ def get_data_files(path, strip='', prefix=''):
3432

3533
setup(
3634
name='ansible-cmdb',
37-
version='1.6',
38-
license='BSD',
35+
version=get_version(),
36+
license='MIT',
3937
description='Generate host overview from ansible fact gathering output',
4038
long_description=get_long_description(),
4139
url='https://github.com/fboender/ansible-cmdb',
4240

4341
author='Ferry Boender',
44-
author_email='ferry.boender@gmail.com',
42+
author_email='ferry.boender@electricmonk.nl',
4543

4644
package_dir={'': 'src'},
4745
packages=find_packages('src'),
4846
include_package_data=True,
4947
data_files=get_data_files('src/ansiblecmdb/data',
50-
strip='src/ansiblecmdb/',
51-
prefix='ansiblecmdb/'),
48+
strip='src',
49+
prefix='lib/'),
5250
zip_safe=False,
5351
install_requires=[
5452
'mako>=1.0',
55-
'pyyaml>=1.0'
53+
'pyyaml>=1.0',
54+
'ushlex>=0.99',
55+
'jsonxs>=0.3',
5656
],
5757
scripts=[
5858
'src/ansible-cmdb',
@@ -70,6 +70,7 @@ def get_data_files(path, strip='', prefix=''):
7070
'Programming Language :: Python',
7171
'Programming Language :: Python :: 2.6',
7272
'Programming Language :: Python :: 2.7',
73+
'Programming Language :: Python :: 3',
7374
'Topic :: System :: Installation/Setup',
7475
'Topic :: System :: Systems Administration',
7576
'Topic :: Utilities',

src/ansible-cmdb

+16-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ if __name__ == "__main__":
4343
root.addHandler(ch)
4444
log = root
4545

46-
parser = optparse.OptionParser(version="%prog v%%MASTER%%")
46+
# Find out our installation prefix and data directory. These can be in
47+
# different places depending on how ansible-cmdb was installed.
48+
data_dir_paths = [
49+
os.path.join(os.path.dirname(ansiblecmdb.__file__), 'data'),
50+
'/usr/local/lib/ansiblecmdb/data',
51+
'/usr/lib/ansiblecmdb/data',
52+
]
53+
54+
data_dir = find_path(data_dir_paths, 'tpl/html_fancy.tpl')
55+
tpl_dir = os.path.join(data_dir, 'tpl')
56+
static_dir = os.path.join(data_dir, 'static')
57+
version = open(os.path.join(data_dir, 'VERSION')).read().strip()
58+
59+
parser = optparse.OptionParser(version="%prog v{}".format(version))
4760
parser.set_usage(sys.argv[0] + " [option] <dir> > output.html")
4861
parser.add_option("-t", "--template", dest="template", action="store", default='html_fancy', help="Template to use. Default is 'html_fancy'")
4962
parser.add_option("-i", "--inventory", dest="inventory", action="store", default=None, help="Inventory to read extra info from")
@@ -61,16 +74,7 @@ if __name__ == "__main__":
6174
if options.debug:
6275
root.setLevel(logging.DEBUG)
6376

64-
# Find out our installation prefix and data directory. These can be in
65-
# different places depending on how ansible-cmdb was installed.
66-
data_dir_paths = [
67-
os.path.join(os.path.dirname(ansiblecmdb.__file__), 'data'),
68-
'/usr/local/lib/ansiblecmdb/data',
69-
'/usr/lib/ansiblecmdb/data',
70-
]
71-
data_dir = find_path(data_dir_paths, 'tpl/html_fancy.tpl')
72-
tpl_dir = os.path.join(data_dir, 'tpl')
73-
static_dir = os.path.join(data_dir, 'static')
77+
# Log some path information
7478
log.debug('data_dir = {0}'.format(data_dir))
7579
log.debug('tpl_dir = {0}'.format(tpl_dir))
7680
log.debug('static_dir = {0}'.format(static_dir))
@@ -100,7 +104,7 @@ if __name__ == "__main__":
100104
params = {
101105
'lib_dir': data_dir, # Backwards compatibility for custom templates < ansible-cmdb v1.7
102106
'data_dir': data_dir,
103-
'version': '%%MASTER%%',
107+
'version': version,
104108
'columns': None,
105109
}
106110
if options.params:

src/ansiblecmdb/data/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MASTER

0 commit comments

Comments
 (0)