diff --git a/config.bat b/config.bat new file mode 100644 index 00000000..7b003886 --- /dev/null +++ b/config.bat @@ -0,0 +1,9 @@ +@echo off + +IF "%~1"=="" ( + echo "No docker container name given!" + EXIT /B 2 +) ELSE ( + docker run -it --name configuration-inator %1 python config/make_config.py + docker commit configuration-inator %1 +) \ No newline at end of file diff --git a/config.sh b/config.sh new file mode 100644 index 00000000..aa9cea1d --- /dev/null +++ b/config.sh @@ -0,0 +1,7 @@ +#! /bin/bash +if [$# -eq 0]; then + echo "No docker image name given!" +else + docker run -it --name configuration-inator $1 python config/make_config.py; + docker commit configuration-inator $1; +fi \ No newline at end of file diff --git a/config/make_config.py b/config/make_config.py index 50eaacc2..cd4ed6b8 100644 --- a/config/make_config.py +++ b/config/make_config.py @@ -1,8 +1,9 @@ #!/usr/bin/python ''' -Executable script to create the configuration file for the BMI3D code, a text file called '$BMI3D/config_files/config' +Executable script to create the configuration file for the BMI3D code, a text file called '$BMI3D/config/config' ''' import os +import sys from collections import OrderedDict stuff = OrderedDict() @@ -14,24 +15,32 @@ stuff['plexon IP address'] = dict(addr='10.0.0.13', port=6000) stuff['update_rates'] = dict(hdf_hz=60) +# Add an optional commandline flag to make setup non-interactive +use_defaults = '-y' in sys.argv or '--use-defaults' in sys.argv + from db import settings databases = list(settings.DATABASES.keys()) -for dbname in databases: - stuff['db_config_%s' % dbname] = dict(data_path='/storage') +for db_name in databases: + stuff[f'db_config_{db_name}'] = dict(data_path='/storage') -config_filename = '$BMI3D/config_files/config' +config_filename = '$BMI3D/config/config' config_fh = open(os.path.expandvars(config_filename), 'w') for system_name, system_opts in list(stuff.items()): - config_fh.write('[%s]\n' % system_name) + config_fh.write(f'[{system_name}]\n') print(system_name) for option, default in list(system_opts.items()): - print(option, default) - opt_val = input("Enter value for '%s' (default=%s): " % (option, str(default))) - if opt_val == '': + + if use_defaults: + print(f" Using default ({default}) for {option}") opt_val = default - config_fh.write('%s = %s\n' % (option, opt_val)) + else: + opt_val = input(f" Enter value for '{option}' (default={default}): ") + if opt_val == '': + opt_val = default + + config_fh.write(f'{option} = {opt_val}\n') config_fh.write('\n') print() diff --git a/config/namelist.py b/config/namelist.py index de2c86c2..3f72c3d7 100644 --- a/config/namelist.py +++ b/config/namelist.py @@ -2,12 +2,17 @@ Lookup table for features, generators and tasks for experiments ''' -## Get the list of experiment features -from .featurelist import features - -## Get the list of tasks -from .tasklist import tasks +# Get the list of experiment features +try: + from .featurelist import features +except (ImportError, ModuleNotFoundError): + features = {} +# Get the list of tasks +try: + from .tasklist import tasks +except (ImportError, ModuleNotFoundError): + tasks = {} # Derive generator functions from the tasklist (all generatorfunctions should be staticmethods of a task) generator_names = [] @@ -67,4 +72,4 @@ def __getitem__(self, name): ################################################################################ ################################################################################ -from .bmilist import * \ No newline at end of file +# from .bmilist import * \ No newline at end of file diff --git a/db/runserver.sh b/db/runserver.sh index d0e37a2d..06bfc14b 100755 --- a/db/runserver.sh +++ b/db/runserver.sh @@ -15,7 +15,7 @@ if [ -z "$BMI3D" ] fi #Check /storage (exist ) -storage=$(python $BMI3D/config_files/check_storage.py 2>&1) +storage=$(python $BMI3D/config/check_storage.py 2>&1) if [ $storage == 'False' ]; then echo "/storage does not exist --> if on Ismore, must mount" exit 1 @@ -28,8 +28,8 @@ if [ `ps aux | grep "manage.py runserver" | grep python | wc -l` -gt 0 ]; then fi # Check that a config file is in the correct place, $BMI3D/config -if [ ! -e $BMI3D/config_files/config ]; then - echo "ERROR: cannot find config file! Did you run $BMI3D/config_files/make_config.py?" +if [ ! -e $BMI3D/config/config ]; then + echo "ERROR: cannot find config file! Did you run $BMI3D/config/make_config.py?" exit 1 fi diff --git a/install/docker/bmi3d.base.dockerfile b/install/docker/bmi3d.base.dockerfile new file mode 100644 index 00000000..bd363a8c --- /dev/null +++ b/install/docker/bmi3d.base.dockerfile @@ -0,0 +1,55 @@ +##### ################################################################### #### +##### ---- Starting point when any os dependencies have been changed ---- #### +##### ################################################################### #### +FROM python:3 + +#### Connect up third-party repositories (rabbitmq and erlang) +RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash +RUN echo "deb http://dl.bintray.com/rabbitmq-erlang/debian bionic erlang" \ + >> /etc/apt/sources.list.d/bintray.erlang.list +RUN apt-get -y update + + +##### Install required ubuntu packages +RUN apt-get install -y \ + smbclient \ + cifs-utils \ + bison \ + flex \ + openssh-server \ + libusb-dev\ + libcomedi-dev \ + python-comedilib \ + swig \ + isc-dhcp-server \ + sqlite3 \ + vim + +# Install rabbitmq with it's erlang dependencies +RUN apt-get install -y --allow-unauthenticated \ + erlang-base-hipe \ + erlang-asn1 \ + erlang-crypto \ + erlang-eldap \ + erlang-ftp \ + erlang-inets \ + erlang-mnesia \ + erlang-os-mon \ + erlang-parsetools \ + erlang-public-key \ + erlang-runtime-tools \ + erlang-snmp \ + erlang-ssl \ + erlang-syntax-tools \ + erlang-tftp \ + erlang-tools \ + erlang-xmerl \ + rabbitmq-server + +####### Set up directories +RUN mkdir -v -p /code/src/ +RUN mkdir -v -p /backup && chown root /backup +RUN mkdir -v -p /storage/plots && chown -R root /storage\ +RUN mkdir -v -p /code/bmi3d/log + + diff --git a/install/docker/bmi3d.code.dockerfile b/install/docker/bmi3d.code.dockerfile new file mode 100644 index 00000000..47ffabd2 --- /dev/null +++ b/install/docker/bmi3d.code.dockerfile @@ -0,0 +1,17 @@ +#### ##################################################################### ##### +#### ---- Starting point when only small local changes have been made ---- ##### +#### ##################################################################### ##### +FROM bmi3d:python +COPY bmi3d/ /code/bmi3d/ +COPY bmi3d_tasks_analysis/ /code/bmi3d_tasks_analysis/ + +RUN python config/make_config.py --use-defaults && \ + python db/manage.py makemigrations && \ + python db/manage.py migrate + +# Fix all .sh files that might have aquired windows line endings +RUN for f in $(find /code/ -name "*.sh"); \ + do echo "fixing: $f" && sed -i 's/\r$//' $f; \ + done + +CMD [ "/bin/bash", "./db/runserver.sh" ] \ No newline at end of file diff --git a/install/docker/bmi3d.python.dockerfile b/install/docker/bmi3d.python.dockerfile new file mode 100644 index 00000000..ad6e49f6 --- /dev/null +++ b/install/docker/bmi3d.python.dockerfile @@ -0,0 +1,18 @@ +##### ################################################################### #### +##### ---- Starting point when python dependencies have been changed ---- #### +##### ################################################################### #### +FROM bmi3d:base + +# --- Expect cache invalidation here if source files have changed --- # +COPY bmi3d/requirements.txt /code/bmi3d/requirements.txt + +WORKDIR /code/bmi3d/ + +###### Install python dependencies +RUN pip install --upgrade pip +RUN pip install -r requirements.txt + +# Set env vars for future reference +ENV BMI3D="/code/bmi3d" \ + PYTHONPATH="${PYTHONPATH}:/code/bmi3d/:/code/bmi3d_tasks_analysis" + diff --git a/install/docker/src_code_install.sh b/install/docker/src_code_install.sh new file mode 100644 index 00000000..e53845c2 --- /dev/null +++ b/install/docker/src_code_install.sh @@ -0,0 +1,63 @@ +#!/bin/bash +####### Declare environment variables +CODE=/code +BMI3D=$CODE/bmi3d ### Directory in which to install the bmi3d software +USER=root # We're in a docker container so root is safe + +####### Download any src code +git clone https://github.com/sgowda/robotics_toolbox $HOME/code/robotics +# Phidgets code +#wget https://www.phidgets.com/downloads/phidget22/libraries/linux/libphidget22/libphidget22-1.1.20190417.tar.gz +#wget https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Python/Phidget22Python_1.1.20190418.zip + + +####### Install source code, configure software +# plexread module +#cd $BMI3D/riglib +which python +#python setup.py install + +# NIDAQ software -- deprecated! +# $HOME/code/bmi3d/riglib/nidaq/build.sh + +echo "TESTED IF HERE" + +# Phidgets libraries +#cd $CODE/src/ +#tar xzf libphidget.tar.gz +#cd libphidget* +#./configure +#make +#make install + +#cd $CODE/src/ +#unzip PhidgetsPython.zip +#cd PhidgetsPython +#python setup.py install + + + +####### Configure udev rules, permissions +# Phidgets +#cp $CODE/src/libphidget*/udev/99-phidgets.rules /etc/udev/rules.d +#chmod a+r /etc/udev/rules.d/99-phidgets.rules +# NIDAQ +cp $HOME/code/bmi3d/install/udev/comedi.rules /etc/udev/rules.d/ +chmod a+r /etc/udev/rules.d/comedi.rules +udevadm control --reload-rules +# Group permissions +usermod -a -G iocard $USER # NIDAQ card belongs to iocard group +usermod -a -G dialout $USER # Serial ports belong to 'dialout' group + + +####### Reconfigure .bashrc +sed -i '$a export PYTHONPATH=$PYTHONPATH:$HOME/code/robotics' $HOME/.bashrc +sed -i '$a export BMI3D=/home/lab/code/bmi3d' $HOME/.bashrc +sed -i '$a source $HOME/code/bmi3d/pathconfig.sh' $HOME/.bashrc +source $HOME/.bashrc + +chown -R $USER ~/.matplotlibs + +cd $HOME/code/bmi3d/db +python manage.py syncdb +# Add superuser 'lab' with password 'lab' diff --git a/requirements.txt b/requirements.txt index 91c5747e..a07bb2eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,8 +7,7 @@ traits pandas patsy statsmodels -PyOpenGL -PyOpenGL-accelerate +PyOpenGL Django pylibftdi nitime @@ -16,6 +15,7 @@ sphinx numpydoc tornado tables +sklearn pyserial h5py pygame