db: Fix user management functions

* Return expected data type, not one-tuples
* Throw ElbeDBError in get_userid and get_user_role

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Merge login-related code into one function

Instead of verify_password, get_userid, get_user_role, introduce the
function get_logindata, which does all these things at once, so we do
only have one database query per login instead of three.

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Use scoped_session instead of plain session

This allows us to access the database from multiple threads, see:
http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#thread-local-scope
First step in making the db code thread safe.

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Reject set_xml when project is being built

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Only allow get_files for built projects

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Fix needs_rebuild => needs_build

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Make create_project thread-safe

* Use os.makedirs directly without checking for the directory first and
  catch the error if the directory already exists, so check and creation
  are one atomic unit, and cannot be disturbed by another application on
  the system.

* Fail more nicely if the project already exists in the database.

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>
db: Reject del_project if build in progress

Signed-off-by: Stefan Gast <stefan.gast@linutronix.de>