-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
195 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
.* | ||
!.gitignore | ||
!.travis.yml | ||
*.deb | ||
*.pkg.tar.xz | ||
*.pyc | ||
*.rpm | ||
__pycache__/ | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
language: python | ||
python: | ||
- '2.7' | ||
- '3.4' | ||
branches: | ||
except: "/^v\\d/" | ||
install: true | ||
script: true | ||
deploy: | ||
provider: elasticbeanstalk | ||
access_key_id: "$AWS_ACCESS_KEY_ID" | ||
secret_access_key: "$AWS_SECRET_ACCESS_KEY" | ||
region: us-east-1 | ||
app: help50 | ||
env: help50 | ||
bucket_name: travis50 | ||
on: | ||
branch: master | ||
script: | ||
- pip install . | ||
- help50 foo | ||
jobs: | ||
include: | ||
- stage: deploy | ||
python: '3.4' | ||
install: skip | ||
script: skip | ||
deploy: | ||
- provider: script | ||
script: 'curl --fail --data "{ \"tag_name\": \"v$(python setup.py --version)\", | ||
\"target_commitish\": \"$TRAVIS_COMMIT\", \"name\": \"v$(python setup.py --version)\" | ||
}" --user bot50:$GITHUB_TOKEN https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases' | ||
on: | ||
branch: master | ||
- provider: pypi | ||
user: "$PYPI_USERNAME" | ||
password: "$PYPI_PASSWORD" | ||
on: | ||
branch: master | ||
notifications: | ||
slack: | ||
secure: JkISnzaottX+lkvYlNGUl1M7Pu9DpSmWsvR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KlgdwXWIvab/ErRpC8Omjabd+tPmNYWPyMHYGtprppO9DDW7oJ5XJ6PO/NyYwG4QlZ9vFabyAb2q97TXjZLNPqd85t4MhxlMxAZFbNkTEXdCdFMVpgGBJD8NUniYuns0a+g8HBZqgbKvv1XjJAFPYUNuOqqfBwxvVF5RLE7dErjcsu44NmrkI74LYoaDqTNNflZ4xGHMsg7o3BJQlBQBqJyKizhAxOHUyrGHUd7mklGANLj8me92UWhdrDx9Xtt3d3CNvocx9PyzPcTlTMA4E= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# help50 | ||
|
||
[![Build Status](https://travis-ci.org/cs50/help50.svg?branch=master)](https://travis-ci.org/cs50/help50) | ||
|
||
`help50` is a command line tool that makes an effort to translate some of the more arcane error messages that other tools, such as `clang` or `valgrind`, sometimes spit out. In this way, it serves as a "virtual TF" of sorts, hopefully helping nudge students in the right direction, so that they needn’t wait for a staff member at office hours when a little bit of translation of the error message is really all that’s needed to move on. | ||
|
||
### Installation | ||
|
||
``` | ||
pip install help50 | ||
``` | ||
|
||
### Usage | ||
|
||
* `help50 ./foo` | ||
* `CC=clang help50 make foo` | ||
* `help50 clang -o foo foo.c` | ||
* `./foo |& help50` | ||
* `CC=clang make foo |& help50` | ||
* `clang -o foo foo.c |& help50` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/usr/bin/env python | ||
from __future__ import print_function | ||
import io | ||
import os | ||
import signal | ||
import subprocess | ||
import sys | ||
import textwrap | ||
|
||
from argparse import ArgumentParser, REMAINDER | ||
from backports.shutil_get_terminal_size import get_terminal_size | ||
import requests | ||
import termcolor | ||
import ptyprocess | ||
|
||
|
||
def main(): | ||
def handler(signum, frame): | ||
"""Return 1 on Ctrl-C""" | ||
print("") | ||
sys.exit(1) | ||
signal.signal(signal.SIGINT, handler) | ||
|
||
parser = ArgumentParser(description="A command-line tool that helps " | ||
"students understand error messages.") | ||
parser.add_argument("-i", "--interactive", | ||
help="allow error messages to be written to " | ||
"stdin interactively", | ||
action="store_true") | ||
parser.add_argument("command", nargs=REMAINDER, | ||
default=[], help="command to be run") | ||
args = parser.parse_args(sys.argv[1:]) | ||
|
||
# Get IO byte streams | ||
if sys.version_info[0] < 3: | ||
stdin, stdout = sys.stdin, sys.stdout | ||
else: | ||
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer | ||
|
||
if args.command: | ||
# Capture stdout and stderr from process, and print it out | ||
with io.BytesIO() as iobytes: | ||
# Run command in pseudo-TTY (so processes don't think they're writing to a pipe) | ||
proc = ptyprocess.PtyProcess.spawn(["bash", "-c", " ".join(sys.argv[1:])]) | ||
tee(proc, iobytes, stdout) | ||
proc.wait() | ||
script = iobytes.getvalue().decode("utf-8") | ||
|
||
# Interactive stdin | ||
elif args.interactive: | ||
script = sys.stdin.read() | ||
|
||
# Non-interactive stdin | ||
elif not sys.stdin.isatty(): | ||
with io.BytesIO() as iobytes: | ||
tee(stdin, iobytes, stdout) | ||
script = iobytes.getvalue().decode("utf-8") | ||
|
||
# Disallow interactive without `-i` input (as potentially confusing) | ||
else: | ||
print("Careful, you forgot to tell me with which command you " | ||
"need help!") | ||
sys.exit(1) | ||
|
||
termcolor.cprint("\nAsking for help...", "yellow", end="") | ||
sys.stdout.flush() | ||
|
||
data = { | ||
"cmd": " ".join(sys.argv[1:]), | ||
"format": "ans", | ||
"script": script, | ||
"username": os.environ.get("C9_USER") | ||
} | ||
|
||
# Read help50 url and from environment variable, | ||
# defaulting to help.cs50.net | ||
app_url = os.environ.get("APP_URL") or "https://help.cs50.net/" | ||
|
||
# Get number of columns in terminal, defaulting to 80 | ||
columns, _ = get_terminal_size() | ||
if columns == 0: columns = 80 | ||
|
||
# Connect to server and print response, showing error message if unable to | ||
try: | ||
# Connect to server | ||
r = requests.post(app_url, data) | ||
except requests.exceptions.RequestException: | ||
termcolor.cprint(wrap("Ack, there seems to be a bug in help50! " | ||
"Please let [email protected] know " | ||
"with which error you need help!", | ||
columns), | ||
"yellow", end="") | ||
sys.exit(1) | ||
else: | ||
# Overwrite previous line with spaces | ||
print("\r{}\r".format(" " * columns), end="") | ||
termcolor.cprint(wrap(r.text.encode("utf-8").decode("unicode_escape"), | ||
columns), | ||
"yellow", end="") | ||
|
||
|
||
def tee(input, *outputs): | ||
"""Executes command, piping stdout and stderr to *outputs.""" | ||
while True: | ||
try: | ||
byte = input.read(1) | ||
except EOFError: | ||
byte = None | ||
|
||
if not byte: | ||
break | ||
|
||
for output in outputs: | ||
output.write(byte) | ||
output.flush() | ||
|
||
|
||
def wrap(string, columns): | ||
""" Wraps a string to the specified number of columns, | ||
preserving blank lines. | ||
""" | ||
return "\n".join( | ||
("\n".join(textwrap.wrap(line, columns)) | ||
for line in string.split("\n"))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
author="CS50", | ||
author_email="[email protected]", | ||
classifiers=[ | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: System Administrators", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Software Development" | ||
], | ||
description="This is help50, a command-line tool that helps students understand error messages.", | ||
install_requires=["argparse", "backports.shutil_get_terminal_size", "requests", "ptyprocess", "termcolor"], | ||
keywords="help50", | ||
name="help50", | ||
scripts=["help50"], | ||
url="https://github.com/cs50/help50", | ||
version="2.0.0" | ||
) |