python3 - 2to3 + miscell obvious tweaks
[sfa.git] / Makefile
1 #
2 ## (Re)builds Python metafile (__init__.py)
3 #
4 # overwritten by the specfile
5 DESTDIR="/"
6 PREFIX=/usr
7 ##########
8 all: python wsdl
9
10 install: python-install wsdl-install tests-install
11
12 clean: python-clean wsdl-clean
13
14 uninstall: python-uninstall tests-uninstall
15
16 .PHONY: all install clean uninstall
17
18 ##########
19 rpmversion:=$(shell rpm -q --specfile sfa.spec --queryformat="%{version}\n" | head -1)
20 # somehow %{taglevel} is empty, turns out %{release} has what we want
21 rpmtaglevel:=$(shell rpm -q --specfile sfa.spec --queryformat="%{release}\n" 2> /dev/null | head -1)
22 VERSIONTAG=$(rpmversion)-$(rpmtaglevel)
23 # this used to be 'should-be-redefined-by-specfile' and it indeed should be
24 SCMURL=git://git.onelab.eu/sfa.git
25
26 python: version
27
28 version: sfa/util/version.py
29 sfa/util/version.py: sfa/util/version.py.in force
30         sed -e "s,@VERSIONTAG@,$(VERSIONTAG),g" -e "s,@SCMURL@,$(SCMURL),g" sfa/util/version.py.in > $@
31
32 # postinstall steps - various cleanups and tweaks for a nicer rpm
33 python-install:
34         python setup.py install --prefix=$(PREFIX) --root=$(DESTDIR)
35         chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
36         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/*egg-info
37         rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/sfa/storage/migrations
38         (cd $(DESTDIR)/usr/bin ; ln -s sfi.py sfi; ln -s sfascan.py sfascan; ln -s sfaadmin.py sfaadmin)
39
40 python-clean: version-clean
41         python setup.py clean
42 #       rm $(init)
43
44 version-clean:
45         rm -f sfa/util/version.py
46
47 .PHONY: python version python-install python-clean version-clean
48 ##########
49 wsdl:
50         $(MAKE) -C wsdl
51
52 # propagate DESTDIR from the specfile
53 wsdl-install:
54         $(MAKE) -C wsdl install
55
56 wsdl-clean:
57         $(MAKE) -C wsdl clean
58
59 .PHONY: wsdl wsdl-install wsdl-clean
60
61 ##########
62 tests-install:
63         mkdir -p $(DESTDIR)/usr/share/sfa/tests
64         install -m 755 tests/*.py $(DESTDIR)/usr/share/sfa/tests/
65
66 tests-uninstall:
67         rm -rf $(DESTDIR)/usr/share/sfa/tests
68
69 .PHONY: tests-install tests-uninstall
70
71 ########## refreshing methods package metafile
72 # Metafiles - manage Legacy/ and Accessors by hand
73 init := sfa/methods/__init__.py
74
75 index: $(init)
76
77 index-clean:
78         rm $(init)
79
80 methods_now := $(sort $(shell fgrep -v '"' sfa/methods/__init__.py 2>/dev/null))
81 # what should be declared
82 methods_paths := $(filter-out %/__init__.py, $(wildcard sfa/methods/*.py))
83 methods_files := $(sort $(notdir $(methods_paths:.py=)))
84
85 ifneq ($(methods_now),$(methods_files))
86 sfa/methods/__init__.py: force
87 endif
88 sfa/methods/__init__.py:
89         (echo '## Please use make index to update this file' ; echo 'all = """' ; cd sfa/methods; ls -1 *.py | grep -v __init__ | sed -e 's,.py$$,,' ; echo '""".split()') > $@
90
91 force:
92
93 ##########
94 # a lot of stuff in the working dir is just noise
95 files:
96         @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg|pickle)$$'
97
98 git-files:
99         @git ls-files | egrep -v '\.(doc|html|pdf)$$'
100
101 tags:
102         $(MAKE) git-files | xargs etags
103
104 .PHONY: files tags
105
106 signatures:
107         (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
108 .PHONY: signatures
109
110 ########## for uploading onto pypi
111 # use pypitest instead for tests (both entries need to be defined in your .pypirc)
112 PYPI_TARGET=pypi
113 PYPI_TARBALL_HOST=root@build.onelab.eu
114 PYPI_TARBALL_TOPDIR=/build/sfa
115
116 # a quick attempt on pypitest did not quite work as expected
117 # I was hoping to register the project using "setup.py register"
118 # but somehow most of my meta data did not make it up there
119 # and I could not find out why
120 # so I went for the manual method instead
121 # there also was a web dialog prompting for a zip file that would
122 # be used to initialize the project's home dir but this too
123 # did not seem to work the way I was trying to use it, so ...
124
125 # this target is still helpful to produce the readme in html from README.md
126 index.zip index.html: README.md
127         python readme.py
128
129 # I need to run this on my mac as my pypi
130 # run git pull first as this often comes afet a module-tag
131 # we need to re-run make so the version is right
132 git_pypi: git pypi
133
134 git:
135         git pull
136         $(MAKE) version
137
138 # run this only once the sources are in on the right tag
139 pypi: index.html
140         setup.py sdist upload -r $(PYPI_TARGET)
141         ssh $(PYPI_TARBALL_HOST) mkdir -p $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
142         rsync -ai dist/sfa-$(VERSIONTAG).tar.gz $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
143
144 # cleanup
145 clean: readme-clean
146
147 readme-clean:
148         rm -f index.html index.zip
149
150 ########## sync
151 # 2 forms are supported
152 # (*) if your plc root context has direct ssh access:
153 # make sync PLC=private.one-lab.org
154 # (*) otherwise, for test deployments, use on your testmaster
155 # $ run export
156 # and cut'n paste the export lines before you run make sync
157
158 ifdef PLC
159 SSHURL:=root@$(PLC):/
160 SSHCOMMAND:=ssh root@$(PLC)
161 else
162 ifdef PLCHOSTLXC
163 SSHURL:=root@$(PLCHOSTLXC):/vservers/$(GUESTNAME)
164 SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh -o StrictHostKeyChecking=no $(GUESTHOSTNAME)
165 else
166 ifdef PLCHOSTVS
167 SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
168 SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
169 endif
170 endif
171 endif
172
173 synccheck:
174 ifeq (,$(SSHURL))
175         @echo "sync: I need more info from the command line, e.g."
176         @echo "  make sync PLC=boot.planetlab.eu"
177         @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
178         @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
179         @exit 1
180 endif
181
182 LOCAL_RSYNC_EXCLUDES    += --exclude '*.pyc'
183 LOCAL_RSYNC_EXCLUDES    += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
184 RSYNC_EXCLUDES          := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
185 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
186 RSYNC                   := rsync -ai $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
187
188 CLIENTS = $(shell ls clientbin/*.py)
189
190 BINS =  ./config/sfa-config-tty ./systemd/sfa-setup.sh \
191         ./sfa/server/sfa-start.py \
192         ./clientbin/sfaadmin.py \
193         $(CLIENTS)
194
195 synclib: synccheck
196         +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python3.\*/site-packages/
197 syncmigrations:
198         +$(RSYNC) ./sfa/storage/migrations/versions/*.py $(SSHURL)/usr/share/sfa/migrations/versions/
199 syncbin: synccheck
200         +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
201 syncservices: synccheck
202         +$(RSYNC) ./systemd/*.service  $(SSHURL)/lib/systemd/system
203         +$(RSYNC) ./systemd/sfa-setup.sh  $(SSHURL)/usr/bin
204 syncconfig:
205         +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
206 synctest: synccheck
207         +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
208 syncrestart: synccheck
209         -$(SSHCOMMAND) systemctl --system daemon-reload
210         $(SSHCOMMAND) systemctl restart sfa-db
211         $(SSHCOMMAND) systemctl restart sfa-aggregate
212
213 syncmig:
214         +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
215
216
217 # full-fledged
218 sync: synclib syncbin syncservices syncconfig syncrestart
219 syncdeb: synclibdeb syncbin syncservices syncconfig syncrestart
220 # 99% of the time this is enough
221 syncfast: synclib syncrestart
222
223 .PHONY: synccheck synclib syncbin syncconfig synctest syncrestart sync syncfast
224
225 ##########
226 CLIENTLIBFILES= \
227 sfa/examples/miniclient.py \
228 sfa/__init__.py \
229 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
230 sfa/trust/{certificate,__init__}.py \
231 sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py
232
233 clientlibsync:
234         @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
235         rsync -ai --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)
236
237 #################### convenience, for debugging only
238 # make +foo : prints the value of $(foo)
239 # make ++foo : idem but verbose, i.e. foo=$(foo)
240 ++%: varname=$(subst +,,$@)
241 ++%:
242         @echo "$(varname)=$($(varname))"
243 +%: varname=$(subst +,,$@)
244 +%:
245         @echo "$($(varname))"