Installation for tutorial

Goal

Install janitoo and all needed tools.

Needed tools

Janitoo is hosted on github and we need a decent editor :

$ sudo apt-get install git vim

Initial clone

Create a directory for Janitoo. It is recommended to use the default one (/opt/janitoo), unless you’re ready to update a lot a configuration files :

$ sudo mkdir -p /opt/janitoo/src
$ sudo chown -Rf ${USER}:${USER} /opt/janitoo

Janitoo is hosted on github, so you need to clone it into the created directory. /opt/janitoo/src is called the janitoo source.

$ cd /opt/janitoo/src
$ git clone https://github.com/bibi21000/janitoo.git

Janitoo has a makefile for semi-automated installations. Let’s link it :

$ ln -s /opt/janitoo/src/janitoo/Makefile.all Makefile

And use it. Create the needed directories for Janitoo:

$ make directories

Install dependencies and develop sources for Python:

$ make module=janitoo deps
$ sudo make module=janitoo develop

Install mosquitto

$ make module=janitoo_mosquitto clone

Install modules

Create the list of packages in /opt/janitoo/src using your favorite editor ... or vim ;) :

$ vim Makefile.local

Order is important. If some package appears in eggs dependencies before they’ve been downloaded, you’ll run a ‘binary’ version of the package, not the one installed in src.

# Common makefile for janitoo's projects
#

# You can set these variables from the command line.
ARCHBASE      = archive
BUILDDIR      = build
DISTDIR       = dists
NOSEOPTS      = --verbosity=2
PYLINTOPTS    = --max-line-length=140 --max-args=9 --min-public-methods=0

ifndef PYTHON_EXEC
PYTHON_EXEC=python
endif

ifndef message
message="Auto-commit"
endif

python_version_full := $(wordlist 2,4,$(subst ., ,$(shell ${PYTHON_EXEC} --version 2>&1)))

python_version_major = $(word 1,${python_version_full})
python_version_minor = $(word 2,${python_version_full})
python_version_patch = $(word 3,${python_version_full})

ifdef VIRTUAL_ENV
	PYTHON_EXEC=${VIRTUAL_ENV}/bin/python
	python_version_full := $(wordlist 2,4,$(subst ., ,$(shell ${PYTHON_EXEC} --version 2>&1)))
	PIP_EXEC=${VIRTUAL_ENV}/bin/pip
	NOSE=${VIRTUAL_ENV}/bin/nosetests
	PYLINT=${VIRTUAL_ENV}/bin/pylint
	python_version_major = $(word 1,${python_version_full})
	python_version_minor = $(word 2,${python_version_full})
	python_version_patch = $(word 3,${python_version_full})
else
	PIP_EXEC=pip
	ifeq (${python_version_major},3)
		PIP_EXEC=pip3
	endif
	NOSE=$(shell which nosetests)
	PYLINT=$(shell which pylint)
endif

janitoo_version := $(shell ${PYTHON_EXEC} _version.py 2>/dev/null)

SUBMODULES   = $(shell find . -maxdepth 1 -iname jani\* -type d|sort|sed -e 's/janitoo_nosetests_flask//g'|sed -e 's/janitoo_nosetests//g'|sed -e 's/janitoo_sphinx//g')
COREMODULES   = janitoo janitoo_factory janitoo_factory_exts janitoo_db janitoo_flask janitoo_flask_socketio janitoo_manager janitoo_manager_proxy janitoo_datalog_rrd janitoo_thermal janitoo_hostsensor janitoo_layouts
TESTMODULES   = janitoo_nosetests janitoo_nosetests_flask

#~ NOSECOVER     = --cover-package=${MODULENAME} --with-coverage --cover-inclusive --cover-html --cover-html-dir=${BUILDDIR}/docs/html/tools/coverage --with-html --html-file=${BUILDDIR}/docs/html/tools/nosetests/index.html
NOSECOVER     = --cover-package=${MODULENAME} --with-coverage --cover-inclusive --cover-html --cover-html-dir=${BUILDDIR}/docs/html/tools/coverage
NOSEDOCKER     = --cover-package=${NOSEMODULES},${MODULENAME},${MOREMODULES} --with-coverage --cover-inclusive --with-xunit --xunit-testsuite-name=${MODULENAME}

MODULENAME   = $(shell basename `pwd`)
DOCKERNAME   = $(shell echo ${MODULENAME}|sed -e "s|janitoo_||g")
DOCKERVOLS   =
DOCKERPORT   = 8882
NOSEMODULES  = janitoo,janitoo_factory,janitoo_db
MOREMODULES  = janitoo_factory_ext,janitoo_raspberry

DEBIANDEPS := $(shell [ -f debian.deps ] && cat debian.deps)
BASHDEPS := $(shell [ -f bash.deps ] && echo "bash.deps")
JANITOODEPS := $(shell [ -f janitoo.deps ] && echo janitoo.deps)
BOWERDEPS := $(shell [ -f bower.deps ] && cat bower.deps)

TAGGED := $(shell git tag | grep -c v${janitoo_version} )

help:
	@echo "Please use \`make <target>' where <target> is one of"
	@echo "  build           : build the module"
	@echo "  develop         : install for developpers"
	@echo "  install         : install for users"
	@echo "  uninstall       : uninstall the module"
	@echo "  deps            : install dependencies for users"
	@echo "  doc   	    	 : make documentation"
	@echo "  tests           : launch tests"
	@echo "  clean           : clean the development directory"

env:
	@echo "Python ${PYTHON_EXEC} (${python_version_full})"
	@echo "Pip ${PIP_EXEC}"
	@echo "Nose ${NOSE}"
	@echo "Modules ${SUBMODULES}"
	@echo "Core modules ${COREMODULES}"

clean-doc:
	-rm -Rf ${BUILDDIR}/docs
	-rm -Rf ${BUILDDIR}/janidoc
	-rm -f objects.inv
	-rm -f generated_doc
	-rm -f janidoc

janidoc:
	-ln -s /opt/janitoo/src/janitoo_sphinx janidoc

apidoc:
	-rm -rf ${BUILDDIR}/janidoc/source/api
	-mkdir -p ${BUILDDIR}/janidoc/source/api
	cp -Rf janidoc/* ${BUILDDIR}/janidoc/
	cd ${BUILDDIR}/janidoc/source/api && sphinx-apidoc --force --no-toc -o . ../../../../src/
	cd ${BUILDDIR}/janidoc/source/api && mv ${MODULENAME}.rst index.rst

doc: janidoc apidoc
	- [ -f transitions_graph.py ] && python transitions_graph.py
	-git commit -m "Update bus fsm image" rst/images/fsm_bus.png
	-cp -Rf rst/* ${BUILDDIR}/janidoc/source
	sed -i -e "s/MODULE_NAME/${MODULENAME}/g" ${BUILDDIR}/janidoc/source/tools/index.rst
	make -C ${BUILDDIR}/janidoc html
	cp ${BUILDDIR}/janidoc/source/README.rst README.rst
	-ln -s $(BUILDDIR)/docs/html generated_doc
	@echo
	@echo "Documentation finished."

github.io:
	git checkout --orphan gh-pages
	git rm -rf .
	touch .nojekyll
	git add .nojekyll
	git commit -m "Initial import" -a
	git push origin gh-pages
	git checkout master
	@echo
	@echo "github.io branch initialised."

doc-full: tests pylint doc-commit

doc-commit: doc
	git checkout gh-pages
	cp -Rf build/docs/html/* .
	git add *.html
	git add *.js
	git add tools/
	git add api/
	-git add _images/
	-git add _modules/
	-git add _sources/
	-git add _static/
	git commit -m "Auto-commit documentation" -a
	git push origin gh-pages
	git checkout master
	@echo
	@echo "Documentation published to github.io."

pylint:
	-mkdir -p ${BUILDDIR}/docs/html/tools/pylint
	$(PYLINT) --output-format=html $(PYLINTOPTS) src/${MODULENAME} >${BUILDDIR}/docs/html/tools/pylint/index.html

You’re now ready to clone the needed modules. sudo password may be asked during this phase :

$ make clone-all

Wait, wait and wait, specially on a raspberry.

After that, all the dependencies are installed. You can jump to the first tutorial.

Install Client tools

Janitoo contains remote client tools that you can install on your local computer (runing Debian or Ubuntu). Simply clone the main janitoo package :

$ sudo mkdir -p /opt/janitoo/src
$ cd /opt/janitoo/src && git clone https://github.com/bibi21000/janitoo.git

And install it :

$ cd /opt/janitoo/src/janitoo && sudo make develop

Check that the tools are correctly installed :

$ jnt_query --help
usage: jnt_query [-h] [--debug] [--output {txt,raw}]
                 {query,cmds,genres,types,caps,node,network} ...

Browse and interact with the Janitoo nework.

positional arguments:
  {query,cmds,genres,types,caps,node,network}
                        The command to launch
    query               Query a node value
    cmds                Show all available command classes for values
    genres              Show all available genres for values
    types               Show all available types for values
    caps                Show all available capabilties for a node
    node                Request infos from a node
    network             Request infos from network (broadcast)

optional arguments:
  -h, --help            show this help message and exit
  --debug               Enable debug mode
  --output {txt,raw}    Enable debug mode

Update your clone

It not need now, but you can update all modules in your clones using :

$ make pull-all

Some packages may have update their entry-points, you need to develop all :

$ sudo make develop-all

To uninstall :

$ sudo make uninstall-all

If you encounter strange errors, missing modules, ..., uninstall (maybe twice) and develop again :

$ sudo make uninstall-all
$ sudo make develop-all