a little nicer wrt pep8
[sfa.git] / Makefile
index 45136a5..90e70de 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,15 @@
 #
-## (Re)builds Python metafile (__init__.py) 
-# 
+## (Re)builds Python metafile (__init__.py)
+#
 # overwritten by the specfile
 DESTDIR="/"
-
+PREFIX=/usr
 ##########
-all: python wsdl 
+all: python
 
-install: python-install wsdl-install xmlbuilder-install tests-install
+install: python-install tests-install
 
-clean: python-clean wsdl-clean 
+clean: python-clean
 
 uninstall: python-uninstall tests-uninstall
 
@@ -20,46 +20,31 @@ rpmversion:=$(shell rpm -q --specfile sfa.spec --queryformat="%{version}\n" | he
 # somehow %{taglevel} is empty, turns out %{release} has what we want
 rpmtaglevel:=$(shell rpm -q --specfile sfa.spec --queryformat="%{release}\n" 2> /dev/null | head -1)
 VERSIONTAG=$(rpmversion)-$(rpmtaglevel)
-SCMURL=should-be-redefined-by-specfile
+# this used to be 'should-be-redefined-by-specfile' and it indeed should be
+SCMURL=git://git.onelab.eu/sfa.git
 
 python: version
 
 version: sfa/util/version.py
-sfa/util/version.py: sfa/util/version.py.in
+sfa/util/version.py: sfa/util/version.py.in force
        sed -e "s,@VERSIONTAG@,$(VERSIONTAG),g" -e "s,@SCMURL@,$(SCMURL),g" sfa/util/version.py.in > $@
 
-xmlbuilder-install:
-       cd xmlbuilder-0.9 && python setup.py install --root=$(DESTDIR) && cd -
-       rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/*egg-info
-
 # postinstall steps - various cleanups and tweaks for a nicer rpm
 python-install:
-       python setup.py install --root=$(DESTDIR)       
+       python3 setup.py install --prefix=$(PREFIX) --root=$(DESTDIR)
        chmod 444 $(DESTDIR)/etc/sfa/default_config.xml
        rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/*egg-info
-       rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/sfa/storage/sfa.sql
-       (cd $(DESTDIR)/usr/bin ; ln -s sfi.py sfi; ln -s sfascan.py sfascan)
+       rm -rf $(DESTDIR)/usr/lib*/python*/site-packages/sfa/storage/migrations
+       (cd $(DESTDIR)/usr/bin ; ln -s sfi.py sfi; ln -s sfascan.py sfascan; ln -s sfaadmin.py sfaadmin)
 
 python-clean: version-clean
-       python setup.py clean
+       python3 setup.py clean
 #      rm $(init)
 
 version-clean:
        rm -f sfa/util/version.py
 
-.PHONY: python version python-install python-clean version-clean xmlbuilder-install 
-##########
-wsdl: 
-       $(MAKE) -C wsdl 
-
-# propagate DESTDIR from the specfile
-wsdl-install:
-       $(MAKE) -C wsdl install 
-
-wsdl-clean:
-       $(MAKE) -C wsdl clean
-
-.PHONY: wsdl wsdl-install wsdl-clean
+.PHONY: python version python-install python-clean version-clean
 
 ##########
 tests-install:
@@ -73,7 +58,7 @@ tests-uninstall:
 
 ########## refreshing methods package metafile
 # Metafiles - manage Legacy/ and Accessors by hand
-init := sfa/methods/__init__.py 
+init := sfa/methods/__init__.py
 
 index: $(init)
 
@@ -88,84 +73,142 @@ methods_files := $(sort $(notdir $(methods_paths:.py=)))
 ifneq ($(methods_now),$(methods_files))
 sfa/methods/__init__.py: force
 endif
-sfa/methods/__init__.py: 
+sfa/methods/__init__.py:
        (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()') > $@
 
 force:
 
 ##########
 # a lot of stuff in the working dir is just noise
-scan:
-       @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg)$$' 
-tags:  
-       $(MAKE) scan | xargs etags
+files:
+       @find . -type f | egrep -v '^\./\.|/\.git/|/\.svn/|TAGS|AA-|~$$|egg-info|\.(py[co]|doc|html|pdf|png|svg|out|bak|dg|pickle)$$'
 
-.PHONY: scan tags
+git-files:
+       @git ls-files | egrep -v '\.(doc|html|pdf)$$'
+
+tags:
+       $(MAKE) git-files | xargs etags
+
+.PHONY: files tags
 
 signatures:
        (cd sfa/methods; grep 'def.*call' *.py > SIGNATURES)
 .PHONY: signatures
 
+########## for uploading onto pypi
+# use pypitest instead for tests (both entries need to be defined in your .pypirc)
+PYPI_TARGET=pypi
+PYPI_TARBALL_HOST=root@build.onelab.eu
+PYPI_TARBALL_TOPDIR=/build/sfa
+
+# a quick attempt on pypitest did not quite work as expected
+# I was hoping to register the project using "setup.py register"
+# but somehow most of my meta data did not make it up there
+# and I could not find out why
+# so I went for the manual method instead
+# there also was a web dialog prompting for a zip file that would
+# be used to initialize the project's home dir but this too
+# did not seem to work the way I was trying to use it, so ...
+
+# this target is still helpful to produce the readme in html from README.md
+index.zip index.html: README.md
+       python3 readme.py
+
+# I need to run this on my mac as my pypi
+# run git pull first as this often comes afet a module-tag
+# we need to re-run make so the version is right
+git_pypi: git pypi
+
+git:
+       git pull
+       $(MAKE) version
+
+# run this only once the sources are in on the right tag
+pypi: index.html
+       setup.py sdist upload -r $(PYPI_TARGET)
+       ssh $(PYPI_TARBALL_HOST) mkdir -p $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
+       rsync -ai dist/sfa-$(VERSIONTAG).tar.gz $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/$(VERSIONTAG)
+
+# cleanup
+clean: readme-clean
+
+readme-clean:
+       rm -f index.html index.zip
+
 ########## sync
 # 2 forms are supported
 # (*) if your plc root context has direct ssh access:
 # make sync PLC=private.one-lab.org
-# (*) otherwise, entering through the root context
-# make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr
-
-PLCHOST ?= testplc.onelab.eu
+# (*) otherwise, for test deployments, use on your testmaster
+# $ run export
+# and cut'n paste the export lines before you run make sync
 
-ifdef GUEST
-ifdef PLCHOST
-SSHURL:=root@$(PLCHOST):/vservers/$(GUEST)
-SSHCOMMAND:=ssh root@$(PLCHOST) vserver $(GUEST)
-endif
-endif
 ifdef PLC
 SSHURL:=root@$(PLC):/
 SSHCOMMAND:=ssh root@$(PLC)
+else
+ifdef PLCHOSTLXC
+SSHURL:=root@$(PLCHOSTLXC):/vservers/$(GUESTNAME)
+SSHCOMMAND:=ssh root@$(PLCHOSTLXC) ssh -o StrictHostKeyChecking=no $(GUESTHOSTNAME)
+else
+ifdef PLCHOSTVS
+SSHURL:=root@$(PLCHOSTVS):/vservers/$(GUESTNAME)
+SSHCOMMAND:=ssh root@$(PLCHOSTVS) vserver $(GUESTNAME) exec
+endif
+endif
+endif
+
+synccheck:
+ifeq (,$(SSHURL))
+       @echo "sync: I need more info from the command line, e.g."
+       @echo "  make sync PLC=boot.planetlab.eu"
+       @echo "  make sync PLCHOSTVS=.. GUESTNAME=.."
+       @echo "  make sync PLCHOSTLXC=.. GUESTNAME=.. GUESTHOSTNAME=.."
+       @exit 1
 endif
 
-LOCAL_RSYNC_EXCLUDES   += --exclude '*.pyc' 
+LOCAL_RSYNC_EXCLUDES   += --exclude '*.pyc'
 LOCAL_RSYNC_EXCLUDES   += --exclude '*.png' --exclude '*.svg' --exclude '*.out'
 RSYNC_EXCLUDES         := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
 RSYNC_COND_DRY_RUN     := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
-RSYNC                  := rsync -a -v $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
+RSYNC                  := rsync -ai $(RSYNC_COND_DRY_RUN) --no-owner $(RSYNC_EXCLUDES)
 
-CLIENTS = $(shell ls sfa/clientbin/*.py)
+CLIENTS = $(shell ls clientbin/*.py)
 
-BINS = ./config/sfa-config-tty ./config/gen-sfa-cm-config.py \
-       ./sfa/importer/sfa-import-plc.py ./sfa/importer/sfa-nuke-plc.py ./sfa/server/sfa-start.py \
+BINS = ./config/sfa-config-tty ./systemd/sfa-setup.sh \
+       ./sfa/server/sfa-start.py ./clientbin/sfaadmin.py keyconvert/keyconvert.py \
        $(CLIENTS)
 
-sync:
-ifeq (,$(SSHURL))
-       @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line"
-       @echo "  e.g. make sync PLC=private.one-lab.org"
-       @echo "  or   make sync PLCHOST=testbox1.inria.fr GUEST=vplc03.inria.fr"
-       @exit 1
-else
-       +$(RSYNC) --relative ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/
-       +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
+synclib: synccheck
+       +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python3.\*/site-packages/
+syncmigrations:
+       +$(RSYNC) ./sfa/storage/migrations/versions/*.py $(SSHURL)/usr/share/sfa/migrations/versions/
+syncbin: synccheck
        +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
-       +$(RSYNC) ./init.d/sfa  $(SSHURL)/etc/init.d/
+syncservices: synccheck
+       +$(RSYNC) ./systemd/*.service  $(SSHURL)/lib/systemd/system
+       +$(RSYNC) ./systemd/sfa-setup.sh  $(SSHURL)/usr/bin
+syncconfig:
        +$(RSYNC) ./config/default_config.xml $(SSHURL)/etc/sfa/
-       +$(RSYNC) ./sfa/storage/sfa.sql $(SSHURL)/usr/share/sfa/
-       $(SSHCOMMAND) exec service sfa restart
-endif
+synctest: synccheck
+       +$(RSYNC) ./tests/ $(SSHURL)/root/tests-sfa
+syncrestart: synccheck
+       -$(SSHCOMMAND) systemctl --system daemon-reload
+       $(SSHCOMMAND) systemctl restart sfa-db
+       $(SSHCOMMAND) systemctl restart sfa-aggregate
+       $(SSHCOMMAND) systemctl restart sfa-registry
 
-# 99% of the time this is enough
-fastsync:
-       +$(RSYNC) --relative ./sfa/ $(SSHURL)/usr/lib\*/python2.\*/site-packages/
-       $(SSHCOMMAND) exec service sfa restart
+syncmig:
+       +$(RSYNC) ./sfa/storage/migrations $(SSHURL)/usr/share/sfa/
 
-clientsync:
-       +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
 
-ricasync:
-       +$(RSYNC) --relative ./sfa/fd ./sfa/generic/fd.py ./sfa/rspecs/versions/federica.py $(SSHURL)/usr/lib\*/python2.\*/site-packages/
+# full-fledged
+sync: synclib syncbin syncservices syncconfig syncrestart
+syncdeb: synclibdeb syncbin syncservices syncconfig syncrestart
+# 99% of the time this is enough
+syncfast: synclib syncrestart
 
-.PHONY: sync fastsync clientsync
+.PHONY: synccheck synclib syncbin syncconfig synctest syncrestart sync syncfast
 
 ##########
 CLIENTLIBFILES= \
@@ -173,8 +216,18 @@ sfa/examples/miniclient.py \
 sfa/__init__.py \
 sfa/client/{sfaserverproxy,sfaclientlib,__init__}.py \
 sfa/trust/{certificate,__init__}.py \
-sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py 
+sfa/util/{sfalogging,faults,genicode,enumeration,__init__}.py
 
-clientlibsync: 
+clientlibsync:
        @[ -d "$(CLIENTLIBTARGET)" ] || { echo "You need to set the make variable CLIENTLIBTARGET"; exit 1; }
-       rsync -av --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)
+       rsync -ai --relative $(CLIENTLIBFILES) $(CLIENTLIBTARGET)
+
+#################### convenience, for debugging only
+# make +foo : prints the value of $(foo)
+# make ++foo : idem but verbose, i.e. foo=$(foo)
+++%: varname=$(subst +,,$@)
+++%:
+       @echo "$(varname)=$($(varname))"
++%: varname=$(subst +,,$@)
++%:
+       @echo "$($(varname))"