Skip to content

Commit 1ff8d94

Browse files
authored
Merge version 3.4.0 (#199)
2 parents d27b1a8 + 8854901 commit 1ff8d94

File tree

9 files changed

+303
-38
lines changed

9 files changed

+303
-38
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- "3.6"
3+
- "3.7"
44

55
install:
66
- "pip install -r requirements.txt"

Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
FROM python:3.6-stretch
1+
FROM python:3.7-slim-buster
22
MAINTAINER Devin Matte <[email protected]>
33

4-
RUN mkdir /opt/packet
4+
RUN apt-get -yq update && \
5+
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev && \
6+
apt-get -yq clean all
57

6-
ADD requirements.txt /opt/packet
8+
RUN mkdir /opt/packet
79

810
WORKDIR /opt/packet
911

10-
RUN apt-get -yq update && \
11-
apt-get -yq --allow-unauthenticated install libsasl2-dev libldap2-dev libssl-dev && \
12-
pip install -r requirements.txt && \
13-
apt-get -yq clean all
12+
COPY requirements.txt /opt/packet
13+
14+
RUN pip install -r requirements.txt
1415

15-
ADD . /opt/packet
16+
COPY . /opt/packet
1617

1718
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
1819
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
1920
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
2021
apt-get -yq update && \
21-
apt-get -yq install nodejs npm yarn && \
22+
apt-get -yq --no-install-recommends install nodejs yarn && \
2223
yarn install && \
2324
npm install -g gulp && \
2425
gulp production && \
2526
rm -rf node_modules && \
2627
apt-get -yq remove nodejs npm yarn && \
28+
apt-get -yq autoremove && \
2729
apt-get -yq clean all
2830

2931
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# CSH Web Packet
22

3-
[![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/)
3+
[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)
44
[![Build Status](https://travis-ci.com/ComputerScienceHouse/packet.svg?branch=develop)](https://travis-ci.com/ComputerScienceHouse/packet)
55

66
Packet is used by CSH to facilitate the freshmen packet portion of our introductory member evaluation process. This is
77
the second major iteration of packet on the web. The first version was
88
[Tal packet](https://github.com/TalCohen/CSHWebPacket).
99

1010
## Setup
11-
**Requires Python 3.6 or newer.**
11+
**Requires Python 3.7 or newer.**
1212

1313
To get the server working you'll just need the Python dependencies and some secrets. There will be some UI issues due
1414
to missing assets though. To solve that you'll want to set up the front end dependencies or download a copy of the

config.env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
ONESIGNAL_INTRO_APP_AUTH_KEY = environ.get("PACKET_ONESIGNAL_INTRO_APP_AUTH_KEY", None)
4747
ONESIGNAL_INTRO_APP_ID = environ.get("PACKET_ONESIGNAL_INTRO_APP_ID", "6eff123a-0852-4027-804e-723044756f00")
4848

49+
# Sentry Config
50+
SENTRY_DSN = environ.get("PACKET_SENTRY_DSN", "")
51+
4952
# Slack URL for pushing to #general
5053
SLACK_WEBHOOK_URL = environ.get("PACKET_SLACK_URL", None)
5154

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": "CSH Packet",
33
"name": "csh-packet",
4-
"version": "3.3.3",
4+
"version": "3.4.0",
55
"description": "A web app implementation of the CSH introductory packet.",
66
"bugs": {
77
"url": "https://github.com/ComputerScienceHouse/packet/issues",
@@ -10,7 +10,8 @@
1010
"license": "MIT",
1111
"contributors": [
1212
"Devin Matte (https://devinmatte.com/)",
13-
"Joel Eager (https://github.com/JoelEager)"
13+
"Joel Eager (https://github.com/JoelEager)",
14+
"Max Meinhold (https://github.com/mxmeinhold)"
1415
],
1516
"repository": {
1617
"type": "git",

packet/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
The application setup and initialization code lives here
33
"""
44

5-
import os
6-
import logging
75
import json
6+
import logging
7+
import os
88

99
import csh_ldap
1010
import onesignal
@@ -15,6 +15,10 @@
1515
from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientMetadata
1616
from flask_sqlalchemy import SQLAlchemy
1717

18+
import sentry_sdk
19+
from sentry_sdk.integrations.flask import FlaskIntegration
20+
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
21+
1822
app = Flask(__name__)
1923
gzip = Gzip(app)
2024

@@ -60,6 +64,12 @@
6064
# LDAP
6165
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
6266

67+
# Sentry
68+
sentry_sdk.init(
69+
dsn=app.config['SENTRY_DSN'],
70+
integrations=[FlaskIntegration(), SqlalchemyIntegration()]
71+
)
72+
6373
app.logger.info('OIDCAuth and LDAP configured')
6474

6575
# pylint: disable=wrong-import-position

packet/commands.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Defines command-line utilities for use with packet
33
"""
44

5+
import sys
6+
57
from secrets import token_hex
68
from datetime import datetime, time, timedelta
79
import csv
@@ -31,9 +33,9 @@ def create_secret():
3133

3234
class CSVFreshman:
3335
def __init__(self, row):
34-
self.name = row[0]
35-
self.rit_username = row[3]
36-
self.onfloor = row[1] == 'TRUE'
36+
self.name = row[0].strip()
37+
self.rit_username = row[3].strip()
38+
self.onfloor = row[1].strip() == 'TRUE'
3739

3840

3941
def parse_csv(freshmen_csv):
@@ -219,31 +221,59 @@ def ldap_sync():
219221

220222

221223
@app.cli.command('fetch-results')
222-
def fetch_results():
224+
@click.option('-f', '--file', 'file_path', required=False, type=click.Path(exists=False, writable=True),
225+
help='The file to write to. If no file provided, output is sent to stdout.')
226+
@click.option('--csv/--no-csv', 'use_csv', required=False, default=False, help='Format output as comma separated list.')
227+
@click.option('--date', 'date_str', required=False, default='', help='Packet end date in the format MM/DD/YYYY.')
228+
def fetch_results(file_path, use_csv, date_str):
223229
"""
224230
Fetches and prints the results from a given packet season.
225231
"""
226-
end_date = datetime.combine(input_date("Enter the last day of the packet season you'd like to retrieve results "
232+
end_date = None
233+
try:
234+
end_date = datetime.combine(datetime.strptime(date_str, '%m/%d/%Y').date(), packet_end_time)
235+
except ValueError:
236+
end_date = datetime.combine(input_date("Enter the last day of the packet season you'd like to retrieve results "
227237
'from'), packet_end_time)
228238

229-
for packet in Packet.query.filter_by(end=end_date).all():
230-
print()
231239

232-
print('{} ({}):'.format(packet.freshman.name, packet.freshman.rit_username))
240+
file_handle = open(file_path, 'w', newline='') if file_path else sys.stdout
233241

242+
column_titles = ['Name (RIT Username)', 'Upperclassmen Score', 'Total Score', 'Upperclassmen', 'Freshmen',
243+
'Miscellaneous', 'Total Missed']
244+
data = list()
245+
for packet in Packet.query.filter_by(end=end_date).all():
234246
received = packet.signatures_received()
235247
required = packet.signatures_required()
236248

237-
print('\tUpperclassmen score: {:0.2f}%'.format(received.member_total / required.member_total * 100))
238-
print('\tTotal score: {:0.2f}%'.format(received.total / required.total * 100))
239-
print()
240-
241-
print('\tUpperclassmen: {}/{}'.format(received.upper, required.upper))
242-
print('\tFreshmen: {}/{}'.format(received.fresh, required.fresh))
243-
print('\tMiscellaneous: {}/{}'.format(received.misc, required.misc))
244-
print()
245-
246-
print('\tTotal missed:', required.total - received.total)
249+
row = [
250+
'{} ({}):'.format(packet.freshman.name, packet.freshman.rit_username),
251+
'{:0.2f}%'.format(received.member_total / required.member_total * 100),
252+
'{:0.2f}%'.format(received.total / required.total * 100),
253+
'{}/{}'.format(received.upper, required.upper),
254+
'{}/{}'.format(received.fresh, required.fresh),
255+
'{}/{}'.format(received.misc, required.misc),
256+
required.total - received.total,
257+
]
258+
data.append(row)
259+
260+
if use_csv:
261+
writer = csv.writer(file_handle)
262+
writer.writerow(column_titles)
263+
writer.writerows(data)
264+
else:
265+
for row in data:
266+
file_handle.write(f'''
267+
268+
{row[0]}
269+
\t{column_titles[1]}: {row[1]}
270+
\t{column_titles[2]}: {row[2]}
271+
\t{column_titles[3]}: {row[3]}
272+
\t{column_titles[4]}: {row[4]}
273+
\t{column_titles[5]}: {row[5]}
274+
275+
\t{column_titles[6]}: {row[6]}
276+
''')
247277

248278

249279
@app.cli.command('extend-packet')

0 commit comments

Comments
 (0)