This is so out of date now
ShepardDB is a project for storing archaeological data, and making it accessable
through a website interface. While it is no where near production ready yet,
it will take advantage of NoSQL databases which will be critical to comprehensively
storing and accessing the data. Most archaeological databases are made with
RDBMS SQL databases (usually older versions), which cannot easily handle the
complexity of data that represents the real world. This project aims to remedy
this problem.
- Install Virtualbox and Vagrant
- git clone this repo
- open a Terminal, and run "vagrant up"
- Wait about 10 min
- open a browser: http://127.0.0.1:8080
sudo su -
cd /var/www/sheparddb/
sudo ./shepard.py
open http://127.0.0.1:9999 in a browser
- http://uwsgi.readthedocs.io/en/latest/Configuration.html
- http://uwsgi-docs.readthedocs.io/en/latest/Options.html
- http://uwsgi.readthedocs.io/en/latest/Systemd.html
- http://uwsgi.readthedocs.io/en/latest/Logging.html
sudo su -
cd /var/www/sheparddb/
sudo uwsgi --plugin http,python --http :8000 \
--ini /vagrant/config/uwsgi/sheparddb.ini \
--honour-stdin
vagrant ssh
sudo su -
cd /var/www/sheparddb
export PYTHONPATH=$(pwd)
pylint shepard.py --reports=n
pylint ./modules/Countries/controller.py --reports=n
reset the database, flask unit testing now does this automatically
sudo su - postgres -c "psql -f /vagrant/psql/db_reset.sql" > /dev/null
delete all existing .pyc files...
find . -name \*.pyc -delete
nosetests --verbosity=2
http://nose.readthedocs.io/en/latest/usage.html http://manpages.ubuntu.com/manpages/trusty/man1/nosetests.1.html
nosetests --with-xcoverage --cover-package=sheparddb \
-x -d -s --verbosity=2 --no-byte-compile
nosetests --with-xcoverage --cover-package=sheparddb.modules.Countries \
-x -d -s --verbosity=2 --no-byte-compile
clonedigger --cpd-output -o clonedigger.xml ./ > /dev/null
sloccount --duplicates --wide --details . | fgrep -v .svn > sloccount.sc || :
su - postgres -c "psql -f /vagrant/psql/db_reset.sql"
Ensure that you have the Postgres 9.5 client. To install it, on Ubuntu Wily 15.10:
sudo su -
echo "deb http://apt.postgresql.org/pub/repos/apt/ wily-pgdg main" > \
/etc/apt/sources.list.d/postgres.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
apt-get install -y postgresql-client-9.5
Connect to the database, from host machine:
psql -U shepard -d sheparddb -h 127.0.0.1 -W
# the password is "shepard"
Reset the database, within the guest VM:
sudo su - postgres -c "psql -f /vagrant/psql/db_reset.sql"
# become the postgres user, and run the command psql, with the file db_reset.sql
- add new col to db schema
- add example db data
- run database reset script
- add new attribute to the model
- add new attribute to the model init function
- update view one template
- update view all template???
- update the add and edit HTML templates
- update the add and edit functions in controller
- test add
- test edit
- test delete
- test ALL other features (yes really, you may have broken them)
sudo service mongod start
sudo service mongod stop
sudo service mongod restart
MongoDB test dataset in data folder, primer-dataset.json
mongod
# python log
sudo nano /var/log/sheparddb/info.log
watch tail -32 /var/log/sheparddb/info.log
# uwsgi log
sudo nano /var/log/uwsgi/app/sheparddb.log
sudo nano /var/log/uwsgi/app/uwsgi.log
# nginx logs
sudo nano /var/log/nginx/access.log
sudo nano /var/log/nginx/error.log
# install Java
sudo apt-get update
sudo apt-get install -y openjdk-7-jre unzip python-dev
# install Selenium Server
# Always use a month(s) old build because the newest never works right
cd ~/Downloads
wget -q http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar
# install Selenium Chrome driver
# https://sites.google.com/a/chromium.org/chromedriver/downloads
# https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
wget http://chromedriver.storage.googleapis.com/2.24/chromedriver_linux64.zip
unzip ./chromedriver_linux64.zip
sudo mv ./chromedriver /usr/local/sbin
# install Python lettuce_webdriver
sudo -H pip install lettuce lettuce_webdriver nose python-Levenshtein --upgrade
# install Python postgres driver
# http://initd.org/psycopg/docs/install.html#installation
sudo apt-get install -y python-psycopg2
# in host machine
cd ~/Sites/sheparddb/data/selenium
# test that Selenium can be run
python ./selenium_test.py
# run all features
lettuce
# run one feature
lettuce ./features/country.feature
# run a single step, in a feature
lettuce ./features/country.feature -s 1 --failfast
# run individual steps, in a feature
lettuce ./features/country.feature -s 1,2
Don't use Python virtual environments. They don't really offer robust dependency isolation, and are an anti-patter in production systems. Instead, just use a Vagrant VM.
https://pythonrants.wordpress.com/2013/12/06/why-i-hate-virtualenv-and-pip/
- run pylint, sloccount, radon
- group related functions into a class
- a class should do one thing well
- a class should be less than 500 lines, 20 functions
- a function should be less than 50 lines
- move more than 3 lines of duplicate code into a base class (Push Down)
- use Yoda conditions, ex: (if None is var_name)
- on failure, log it, and abort()
- review app logs, uwsgi logs, nginx logs, fix errors
- all logs should ideally be clean all the time
- read all the documentation:
- Flask
- Blueprints
- Jinja
- SQLAlchemy
- Werkzeug
- uwsgi
- nginx
- follow the PEP8 standard
- document your code using the Sphinx documetation format
- use the Flask Blueprint Divisional layout http://exploreflask.com/en/latest/blueprints.html#divisional
# change the working directory to the website
cd /var/www/sheparddb
# search for a string in files, case insensitive
grep -inr "<string>"
# run linting
pylint ./*.py