diff --git a/README.md b/README.md index 600d4df..36d62f8 100644 --- a/README.md +++ b/README.md @@ -1,55 +1,79 @@ # README # - ### Requirements: -The webserver is a python3 application and only requires python to be installed. Requires python 3.5 or above. It does not require any other webserver (apache, ...) - -Installed using `pip`: +The webserver is a python application and requires python 3.5+ to be installed. -- CherryPy (>=3.7.0) -- Mako (>=1.0.1) -- Markdown (>=2.6.2) -- PyYAML (>=3.11) -- bcrypt (>=2.0.0) +The following additional python packages are required: -### System setup: +- CherryPy +- Mako +- Markdown +- PyYAML +- Pygments +- SQLAlchemy +- bcrypt -Open a terminal and navigate to a directory where this software is to be installed, e.g. `/var/www` or `/home/username`. -Run the following commands: +These can be installed globally or in a python virtual environment. ```.bash +# install in a virtualenv +pyvenv-3.5 venv/perguntations # or choose another virtualenv directory +source venv/perguntations/bin/activate # activate virtualenv + +pip3.5 install cherrypy +pip3.5 install mako +pip3.5 install markdown +pip3.5 install pyyaml +pip3.5 install pygments +pip3.5 install sqlalchemy +pip3.5 install bcrypt +``` + +To install `perguntations`: +```.bash cd WHERE/TO/PUT/THE/SOFTWARE +git clone https://USERNAME@bitbucket.org/USERNAME/perguntations.git +``` + +where USERNAME is your account on bitbucket. + +### System setup: + +The following commands will show how to run a demonstration test: -# get software using git -git clone https://mjsb@bitbucket.org/mjsb/perguntations.git -cd perguntations +```.bash +cd WHERE/YOU/INSTALLED/perguntations -# create database (if no csv file is provided, a database with 5 fake students is created for debugging) -./initdb_from_csv.py YOUR_CSV_FILE_HERE -mv students.db SOMEWHERE +# create database. +# a database with 5 fake students is created if no CSV file is provided +./initdb_from_csv.py OPTIONAL_CSV_FILE +mv students.db demo/ -# update test configuration with the correct database file. +# edit test configuration and check if everything looks right vi demo/test.yaml -# Edit line 7 to something like -# database: SOMEWHERE/students.db -# edit server configuration +# edit server configuration and check if everything looks right vi config/server.conf -# Edit lines 26--27 to point to the desired log files location. +``` + +We are now ready to run the server: +```.bash # get help ./serve.py --help # run demo test ./serve.py demo/test.yaml +``` -# open browser at http://127.0.0.1:8080/ -# the professor is number 0 +Open the browser at `http://127.0.0.1:8080/` and login as user number `0` (administrator) and: -# ^C to terminate the server -``` +1. Authorize students by clicking the checkboxes. +2. Open a different browser at `http://127.0.0.1:8080/` and login as one of the authorized students. Answer the questions and submit. + +The server can be stoped from the terminal with ^C. ### Troubleshooting diff --git a/demo/test.yaml b/demo/test.yaml index 87a92b0..5de0a29 100644 --- a/demo/test.yaml +++ b/demo/test.yaml @@ -4,7 +4,7 @@ title: Exame de Demonstração # Database with student credentials and grades of all questions and tests done # The database is an sqlite3 file generate with the script initdb_from_csv.py -database: ~/Work/Projects/perguntations/demo/students.db +database: demo/students.db # (optional) Generate a file for each test done by a student. # It includes the questions, answers and grades. diff --git a/initdb.py b/initdb.py index 4449a07..82c1348 100755 --- a/initdb.py +++ b/initdb.py @@ -35,24 +35,27 @@ Session = sessionmaker(bind=engine) try: session = Session() - # add administrator and fake student accounts - session.add_all([ - Student(id='0', name='Professor', password=''), - Student(id='student1', name='Student1', password=''), - Student(id='student2', name='Student2', password=''), - Student(id='student3', name='Student3', password=''), - Student(id='student4', name='Student4', password=''), - Student(id='student5', name='Student5', password=''), - ]) + # add administrator + session.add(Student(id='0', name='Professor', password='')) - # add enrolled students from csv file + # add students if args.csvfile: + # from csv file if available try: csvreader = csv.DictReader(open(args.csvfile, encoding='iso-8859-1'), delimiter=';', quotechar='"') except EnvironmentError: print('CSV file "{0}" not found!'.format(args.csvfile)) else: session.add_all([Student(id=r['N.º'], name=fix(r['Nome']), password='') for r in csvreader]) + else: + # otherwise add 5 fake students + session.add_all([ + Student(id='student1', name='Student1', password=''), + Student(id='student2', name='Student2', password=''), + Student(id='student3', name='Student3', password=''), + Student(id='student4', name='Student4', password=''), + Student(id='student5', name='Student5', password=''), + ]) session.commit() diff --git a/serve.py b/serve.py index d58aa8b..869fe88 100755 --- a/serve.py +++ b/serve.py @@ -313,7 +313,6 @@ if __name__ == '__main__': app = App(filename, vars(arg)) except Exception as e: logging.critical('Can\'t start application.') - raise e # FIXME just for testing sys.exit(1) # --- create webserver diff --git a/test.py b/test.py index 51545d9..ab9f2a0 100644 --- a/test.py +++ b/test.py @@ -179,7 +179,6 @@ class TestFactory(dict): 'show_points': self['show_points'], 'show_ref': self['show_ref'], 'debug': self['debug'], - # 'answers_dir': self['answers_dir'], 'database': self['database'], 'questions_dir': self['questions_dir'], 'files': self['files'], -- libgit2 0.21.2