Skip to content

Commit d27b1a8

Browse files
authored
Merge pull request #188 from ComputerScienceHouse/develop
Version 3.3.3
2 parents 8794095 + eb456da commit d27b1a8

18 files changed

+306
-247
lines changed

.pylintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ single-line-if-stmt = no
3030
no-space-check = trailing-comma,dict-separator
3131
max-module-lines = 1000
3232
indent-string = ' '
33+
string-quote=single-avoid-escape
34+
triple-quote=single
35+
docstring-quote=double
3336

3437
[MISCELLANEOUS]
3538
notes = FIXME,XXX,TODO

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ python:
55
install:
66
- "pip install -r requirements.txt"
77
script:
8-
- "pylint packet/routes packet"
8+
- "pylint --load-plugins pylint_quotes packet/routes packet"

package.json

Lines changed: 1 addition & 1 deletion
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.2",
4+
"version": "3.3.3",
55
"description": "A web app implementation of the CSH introductory packet.",
66
"bugs": {
77
"url": "https://github.com/ComputerScienceHouse/packet/issues",

packet/__init__.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,57 @@
2020

2121
# Load default configuration and any environment variable overrides
2222
_root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
23-
app.config.from_pyfile(os.path.join(_root_dir, "config.env.py"))
23+
app.config.from_pyfile(os.path.join(_root_dir, 'config.env.py'))
2424

2525
# Load file based configuration overrides if present
26-
_pyfile_config = os.path.join(_root_dir, "config.py")
26+
_pyfile_config = os.path.join(_root_dir, 'config.py')
2727
if os.path.exists(_pyfile_config):
2828
app.config.from_pyfile(_pyfile_config)
2929

3030
# Fetch the version number from the npm package file
31-
with open(os.path.join(_root_dir, "package.json")) as package_file:
32-
app.config["VERSION"] = json.load(package_file)["version"]
31+
with open(os.path.join(_root_dir, 'package.json')) as package_file:
32+
app.config['VERSION'] = json.load(package_file)['version']
3333

3434
# Logger configuration
35-
logging.getLogger().setLevel(app.config["LOG_LEVEL"])
36-
app.logger.info("Launching packet v" + app.config["VERSION"])
37-
app.logger.info("Using the {} realm".format(app.config["REALM"]))
35+
logging.getLogger().setLevel(app.config['LOG_LEVEL'])
36+
app.logger.info('Launching packet v' + app.config['VERSION'])
37+
app.logger.info('Using the {} realm'.format(app.config['REALM']))
3838

3939
# Initialize the extensions
4040
db = SQLAlchemy(app)
4141
migrate = Migrate(app, db)
42-
app.logger.info("SQLAlchemy pointed at " + repr(db.engine.url))
42+
app.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url))
4343

44-
APP_CONFIG = ProviderConfiguration(issuer=app.config["OIDC_ISSUER"],
45-
client_metadata=ClientMetadata(app.config["OIDC_CLIENT_ID"],
46-
app.config["OIDC_CLIENT_SECRET"]))
44+
APP_CONFIG = ProviderConfiguration(issuer=app.config['OIDC_ISSUER'],
45+
client_metadata=ClientMetadata(app.config['OIDC_CLIENT_ID'],
46+
app.config['OIDC_CLIENT_SECRET']))
4747

4848
# Initialize Onesignal Notification apps
49-
csh_onesignal_client = onesignal.Client(user_auth_key=app.config["ONESIGNAL_USER_AUTH_KEY"],
50-
app_auth_key=app.config["ONESIGNAL_CSH_APP_AUTH_KEY"],
51-
app_id=app.config["ONESIGNAL_CSH_APP_ID"])
49+
csh_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
50+
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
51+
app_id=app.config['ONESIGNAL_CSH_APP_ID'])
5252

53-
intro_onesignal_client = onesignal.Client(user_auth_key=app.config["ONESIGNAL_USER_AUTH_KEY"],
54-
app_auth_key=app.config["ONESIGNAL_INTRO_APP_AUTH_KEY"],
55-
app_id=app.config["ONESIGNAL_INTRO_APP_ID"])
53+
intro_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
54+
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
55+
app_id=app.config['ONESIGNAL_INTRO_APP_ID'])
5656

5757
# OIDC Auth
5858
auth = OIDCAuthentication({'app': APP_CONFIG}, app)
5959

6060
# LDAP
61-
_ldap = csh_ldap.CSHLDAP(app.config["LDAP_BIND_DN"], app.config["LDAP_BIND_PASS"])
61+
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
6262

63-
app.logger.info("OIDCAuth and LDAP configured")
63+
app.logger.info('OIDCAuth and LDAP configured')
6464

6565
# pylint: disable=wrong-import-position
6666
from . import models
6767
from . import context_processors
6868
from . import commands
6969
from .routes import api, shared
7070

71-
if app.config["REALM"] == "csh":
71+
if app.config['REALM'] == 'csh':
7272
from .routes import upperclassmen
7373
else:
7474
from .routes import freshmen
7575

76-
app.logger.info("Routes registered")
76+
app.logger.info('Routes registered')

packet/commands.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ldap_is_on_coop
1717

1818

19-
@app.cli.command("create-secret")
19+
@app.cli.command('create-secret')
2020
def create_secret():
2121
"""
2222
Generates a securely random token. Useful for creating a value for use in the "SECRET_KEY" config setting.
@@ -33,37 +33,37 @@ class CSVFreshman:
3333
def __init__(self, row):
3434
self.name = row[0]
3535
self.rit_username = row[3]
36-
self.onfloor = row[1] == "TRUE"
36+
self.onfloor = row[1] == 'TRUE'
3737

3838

3939
def parse_csv(freshmen_csv):
40-
print("Parsing file...")
40+
print('Parsing file...')
4141
try:
4242
with open(freshmen_csv, newline='') as freshmen_csv_file:
4343
return {freshman.rit_username: freshman for freshman in map(CSVFreshman, csv.reader(freshmen_csv_file))}
4444
except Exception as e:
45-
print("Failure while parsing CSV")
45+
print('Failure while parsing CSV')
4646
raise e
4747

4848

4949
def input_date(prompt):
5050
while True:
5151
try:
52-
date_str = input(prompt + " (format: MM/DD/YYYY): ")
53-
return datetime.strptime(date_str, "%m/%d/%Y").date()
52+
date_str = input(prompt + ' (format: MM/DD/YYYY): ')
53+
return datetime.strptime(date_str, '%m/%d/%Y').date()
5454
except ValueError:
5555
pass
5656

5757

58-
@app.cli.command("sync-freshmen")
59-
@click.argument("freshmen_csv")
58+
@app.cli.command('sync-freshmen')
59+
@click.argument('freshmen_csv')
6060
def sync_freshmen(freshmen_csv):
6161
"""
6262
Updates the freshmen entries in the DB to match the given CSV.
6363
"""
6464
freshmen_in_csv = parse_csv(freshmen_csv)
6565

66-
print("Syncing contents with the DB...")
66+
print('Syncing contents with the DB...')
6767
freshmen_in_db = {freshman.rit_username: freshman for freshman in Freshman.query.all()}
6868

6969
for csv_freshman in freshmen_in_csv.values():
@@ -98,25 +98,25 @@ def sync_freshmen(freshmen_csv):
9898
db.session.add(FreshSignature(packet=packet, freshman=freshmen_in_db[csv_freshman.rit_username]))
9999

100100
db.session.commit()
101-
print("Done!")
101+
print('Done!')
102102

103103

104-
@app.cli.command("create-packets")
105-
@click.argument("freshmen_csv")
104+
@app.cli.command('create-packets')
105+
@click.argument('freshmen_csv')
106106
def create_packets(freshmen_csv):
107107
"""
108108
Creates a new packet season for each of the freshmen in the given CSV.
109109
"""
110110
print("WARNING: The 'sync-freshmen' command must be run first to ensure that the state of floor is up to date.")
111-
if input("Continue? (y/N): ").lower() != "y":
111+
if input('Continue? (y/N): ').lower() != 'y':
112112
return
113113

114114
# Collect the necessary data
115-
base_date = input_date("Input the first day of packet season")
115+
base_date = input_date('Input the first day of packet season')
116116
start = datetime.combine(base_date, packet_start_time)
117117
end = datetime.combine(base_date, packet_end_time) + timedelta(days=14)
118118

119-
print("Fetching data from LDAP...")
119+
print('Fetching data from LDAP...')
120120
all_upper = list(filter(
121121
lambda member: not ldap_is_intromember(member) and not ldap_is_on_coop(member), ldap_get_active_members()))
122122

@@ -131,7 +131,7 @@ def create_packets(freshmen_csv):
131131

132132
# Create the new packets and the signatures for each freshman in the given CSV
133133
freshmen_in_csv = parse_csv(freshmen_csv)
134-
print("Creating DB entries and sending emails...")
134+
print('Creating DB entries and sending emails...')
135135
for freshman in Freshman.query.filter(Freshman.rit_username.in_(freshmen_in_csv)).all():
136136
packet = Packet(freshman=freshman, start=start, end=end)
137137
db.session.add(packet)
@@ -153,15 +153,15 @@ def create_packets(freshmen_csv):
153153
db.session.add(FreshSignature(packet=packet, freshman=onfloor_freshman))
154154

155155
db.session.commit()
156-
print("Done!")
156+
print('Done!')
157157

158158

159-
@app.cli.command("ldap-sync")
159+
@app.cli.command('ldap-sync')
160160
def ldap_sync():
161161
"""
162162
Updates the upper and misc sigs in the DB to match ldap.
163163
"""
164-
print("Fetching data from LDAP...")
164+
print('Fetching data from LDAP...')
165165
all_upper = {member.uid: member for member in filter(
166166
lambda member: not ldap_is_intromember(member) and not ldap_is_on_coop(member), ldap_get_active_members())}
167167

@@ -171,7 +171,7 @@ def ldap_sync():
171171
c_m = ldap_get_constitutional_maintainers()
172172
drink = ldap_get_drink_admins()
173173

174-
print("Applying updates to the DB...")
174+
print('Applying updates to the DB...')
175175
for packet in Packet.query.filter(Packet.end > datetime.now()).all():
176176
# Update the role state of all UpperSignatures
177177
for sig in filter(lambda sig: sig.member in all_upper, packet.upper_signatures):
@@ -215,89 +215,89 @@ def ldap_sync():
215215
db.session.add(sig)
216216

217217
db.session.commit()
218-
print("Done!")
218+
print('Done!')
219219

220220

221-
@app.cli.command("fetch-results")
221+
@app.cli.command('fetch-results')
222222
def fetch_results():
223223
"""
224224
Fetches and prints the results from a given packet season.
225225
"""
226226
end_date = datetime.combine(input_date("Enter the last day of the packet season you'd like to retrieve results "
227-
"from"), packet_end_time)
227+
'from'), packet_end_time)
228228

229229
for packet in Packet.query.filter_by(end=end_date).all():
230230
print()
231231

232-
print("{} ({}):".format(packet.freshman.name, packet.freshman.rit_username))
232+
print('{} ({}):'.format(packet.freshman.name, packet.freshman.rit_username))
233233

234234
received = packet.signatures_received()
235235
required = packet.signatures_required()
236236

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))
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))
239239
print()
240240

241-
print("\tUpperclassmen: {}/{}".format(received.upper, required.upper))
242-
print("\tFreshmen: {}/{}".format(received.fresh, required.fresh))
243-
print("\tMiscellaneous: {}/{}".format(received.misc, required.misc))
241+
print('\tUpperclassmen: {}/{}'.format(received.upper, required.upper))
242+
print('\tFreshmen: {}/{}'.format(received.fresh, required.fresh))
243+
print('\tMiscellaneous: {}/{}'.format(received.misc, required.misc))
244244
print()
245245

246-
print("\tTotal missed:", required.total - received.total)
246+
print('\tTotal missed:', required.total - received.total)
247247

248248

249-
@app.cli.command("extend-packet")
250-
@click.argument("packet_id")
249+
@app.cli.command('extend-packet')
250+
@click.argument('packet_id')
251251
def extend_packet(packet_id):
252252
"""
253253
Extends the given packet by setting a new end date.
254254
"""
255255
packet = Packet.by_id(packet_id)
256256

257257
if not packet.is_open():
258-
print("Packet is already closed so it cannot be extended")
258+
print('Packet is already closed so it cannot be extended')
259259
return
260260
else:
261-
print("Ready to extend packet #{} for {}".format(packet_id, packet.freshman_username))
261+
print('Ready to extend packet #{} for {}'.format(packet_id, packet.freshman_username))
262262

263-
packet.end = datetime.combine(input_date("Enter the new end date for this packet"), packet_end_time)
263+
packet.end = datetime.combine(input_date('Enter the new end date for this packet'), packet_end_time)
264264
db.session.commit()
265265

266-
print("Packet successfully extended")
266+
print('Packet successfully extended')
267267

268268

269269
def remove_sig(packet_id, username, is_member):
270270
packet = Packet.by_id(packet_id)
271271

272272
if not packet.is_open():
273-
print("Packet is already closed so its signatures cannot be modified")
273+
print('Packet is already closed so its signatures cannot be modified')
274274
return
275275
elif is_member:
276276
sig = UpperSignature.query.filter_by(packet_id=packet_id, member=username).first()
277277
if sig is not None:
278278
sig.signed = False
279279
db.session.commit()
280-
print("Successfully unsigned packet")
280+
print('Successfully unsigned packet')
281281
else:
282282
result = MiscSignature.query.filter_by(packet_id=packet_id, member=username).delete()
283283
if result == 1:
284284
db.session.commit()
285-
print("Successfully unsigned packet")
285+
print('Successfully unsigned packet')
286286
else:
287-
print("Failed to unsign packet; could not find signature")
287+
print('Failed to unsign packet; could not find signature')
288288
else:
289289
sig = FreshSignature.query.filter_by(packet_id=packet_id, freshman_username=username).first()
290290
if sig is not None:
291291
sig.signed = False
292292
db.session.commit()
293-
print("Successfully unsigned packet")
293+
print('Successfully unsigned packet')
294294
else:
295-
print("Failed to unsign packet; {} is not an onfloor".format(username))
295+
print('Failed to unsign packet; {} is not an onfloor'.format(username))
296296

297297

298-
@app.cli.command("remove-member-sig")
299-
@click.argument("packet_id")
300-
@click.argument("member")
298+
@app.cli.command('remove-member-sig')
299+
@click.argument('packet_id')
300+
@click.argument('member')
301301
def remove_member_sig(packet_id, member):
302302
"""
303303
Removes the given member's signature from the given packet.
@@ -306,9 +306,9 @@ def remove_member_sig(packet_id, member):
306306
remove_sig(packet_id, member, True)
307307

308308

309-
@app.cli.command("remove-freshman-sig")
310-
@click.argument("packet_id")
311-
@click.argument("freshman")
309+
@app.cli.command('remove-freshman-sig')
310+
@click.argument('packet_id')
311+
@click.argument('freshman')
312312
def remove_freshman_sig(packet_id, freshman):
313313
"""
314314
Removes the given freshman's signature from the given packet.

0 commit comments

Comments
 (0)