Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
Merge branch 'virtualenv' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Jun 25, 2018
2 parents 9f1aa03 + ee040eb commit 0451585
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.cache
.pytest_cache
.gradeforge_installed
.virtualenv
*.csv
books/
exams/
Expand Down
110 changes: 57 additions & 53 deletions gradeforge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,56 +109,60 @@
GRADES.add_argument('campus', nargs='?', type=str.lower,
choices=('columbia', 'aiken', 'upstate'))

ARGS = PARSER.parse_args()
if 'verbose' in ARGS.__dict__:
ARGS.verbose -= ARGS.quiet - 1 # verbosity defaults to 1

if ARGS.subparser == 'web':
app.config['ENV'] = ('development' if ARGS.verbose else 'production')
app.run(debug=ARGS.verbose > 0, port=ARGS.port, use_debugger=ARGS.verbose > 0)
elif ARGS.subparser == 'sql':
if ARGS.command == 'create':
# TODO: add params for csv files
create(database=ARGS.database)
elif not path.exists(ARGS.database):
raise ValueError("database '%s' does not exist or is invalid" % ARGS.database)
if ARGS.command == 'query':
print(query(ARGS.sql_query, database=ARGS.database))
elif ARGS.command == 'dump':
print(dump())
elif ARGS.subparser == 'parse':
if ARGS.info == 'exam':
parse_exam(ARGS.input, ARGS.output)
elif ARGS.info == 'bookstore':
parse_bookstore(ARGS.input, ARGS.output)
elif ARGS.info == 'grades':
parse_grades(ARGS.input, ARGS.output)
elif ARGS.info == 'catalog':
parse_catalog(ARGS.input, catalog_output=ARGS.output,
department_output=ARGS.departments)
else:
parse_sections(ARGS.input, instructor_output=ARGS.instructors,
term_output=ARGS.terms,
section_output=ARGS.output)
elif ARGS.subparser == 'combine':
if ARGS.info == 'grades':
combine_grades(ARGS.input)
elif ARGS.info == 'instructors':
combine_instructors(ARGS.input)
elif ARGS.info == 'terms':
combine_terms(ARGS.input)
else: # departments
combine_departments(ARGS.input)
else: # download
if ARGS.info == 'exam':
print(get_exam(ARGS.year, ARGS.season))
elif ARGS.info == 'sections':
print(get_sections(semester=parse_semester(ARGS.season, year=ARGS.year),
campus=ARGS.campus, term=ARGS.term))
elif ARGS.info == 'catalog':
print(get_catalog(semester=parse_semester(ARGS.season, year=ARGS.year)))
elif ARGS.info == 'bookstore':
print(get_bookstore(parse_semester(ARGS.season, year=ARGS.year),
ARGS.department, ARGS.number, ARGS.section))
else:
stdout.buffer.write(get_grades(ARGS.year, ARGS.season, ARGS.campus))
def main():
ARGS = PARSER.parse_args()
if 'verbose' in ARGS.__dict__:
ARGS.verbose -= ARGS.quiet - 1 # verbosity defaults to 1

if ARGS.subparser == 'web':
app.config['ENV'] = ('development' if ARGS.verbose else 'production')
app.run(debug=ARGS.verbose > 0, port=ARGS.port, use_debugger=ARGS.verbose > 0)
elif ARGS.subparser == 'sql':
if ARGS.command == 'create':
# TODO: add params for csv files
create(database=ARGS.database)
elif not path.exists(ARGS.database):
raise ValueError("database '%s' does not exist or is invalid" % ARGS.database)
if ARGS.command == 'query':
print(query(ARGS.sql_query, database=ARGS.database))
elif ARGS.command == 'dump':
print(dump())
elif ARGS.subparser == 'parse':
if ARGS.info == 'exam':
parse_exam(ARGS.input, ARGS.output)
elif ARGS.info == 'bookstore':
parse_bookstore(ARGS.input, ARGS.output)
elif ARGS.info == 'grades':
parse_grades(ARGS.input, ARGS.output)
elif ARGS.info == 'catalog':
parse_catalog(ARGS.input, catalog_output=ARGS.output,
department_output=ARGS.departments)
else:
parse_sections(ARGS.input, instructor_output=ARGS.instructors,
term_output=ARGS.terms,
section_output=ARGS.output)
elif ARGS.subparser == 'combine':
if ARGS.info == 'grades':
combine_grades(ARGS.input)
elif ARGS.info == 'instructors':
combine_instructors(ARGS.input)
elif ARGS.info == 'terms':
combine_terms(ARGS.input)
else: # departments
combine_departments(ARGS.input)
else: # download
if ARGS.info == 'exam':
print(get_exam(ARGS.year, ARGS.season))
elif ARGS.info == 'sections':
print(get_sections(semester=parse_semester(ARGS.season, year=ARGS.year),
campus=ARGS.campus, term=ARGS.term))
elif ARGS.info == 'catalog':
print(get_catalog(semester=parse_semester(ARGS.season, year=ARGS.year)))
elif ARGS.info == 'bookstore':
print(get_bookstore(parse_semester(ARGS.season, year=ARGS.year),
ARGS.department, ARGS.number, ARGS.section))
else:
stdout.buffer.write(get_grades(ARGS.year, ARGS.season, ARGS.campus))

if __name__ == '__main__':
quit(main())
24 changes: 22 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ TERM_OUTPUT = terms.csv
# make config; don't change until you read man (1) make
# WARNING: changing -j4 to -j will spawn arbitrary processes and probably set your computer thrashing
MAKEFLAGS += -j4 --warn-undefined-variables
ifeq ($(shell echo $$BASH_VERSION),,)
export ENV = .virtualenv/bin/activate
else
export BASH_ENV = .virtualenv/bin/activate
endif
SHELL = sh

# data variables
GRADEFORGE = python -m gradeforge
GRADEFORGE = gradeforge

# NOTE: BOOKSTORE_OUTPUT is not here because a) getting books for every section would
# get us IP-banned and b) cut doesn't work with newlines
Expand Down Expand Up @@ -61,6 +66,21 @@ sql: classes.sql
.PHONY: data
data: $(DATA)

.PHONY: install
install: .gradeforge_installed

.gradeforge_installed:
if [ -z $$VIRTUAL_ENV ]; then \
which virtualenv || { \
echo 'refusing to install globally; run `pip install .` to continue'; \
exit 1; \
}; \
virtualenv .virtualenv; \
. .virtualenv/bin/activate; \
pip install .; \
else pip install .; fi
touch $@

.PHONY: all_grades all_sections
all_grades: $(GRADES_OUTPUT)
all_sections: $(SECTIONS)
Expand All @@ -77,7 +97,7 @@ dump: sql
test: sql | images
# these are ordered from least to most picky
python -c 'from gradeforge.grades import png_for; png_for("NURS", "U497", "PC8", 201705)'
pytest --pyargs gradeforge
pytest gradeforge
pylint --extension-pkg-whitelist=lxml gradeforge | tee pylint.txt
if grep '^E:' pylint.txt; then exit 1; fi
gradeforge/test/match.py gradeforge/**.py
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
'Topic::Internet::WWW/HTTP::Dynamic Content'
# TODO: add license (full list at https://pypi.org/classifiers/)
),
entry_points={'console_scripts': ['gradeforge = gradeforge.__main__']}
entry_points={'console_scripts': ['gradeforge = gradeforge.__main__:main']}
)

0 comments on commit 0451585

Please sign in to comment.