-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move robotpy launcher to this repository
- Added some incremental improvements over old launcher - Still works with previously defined subcommand entry points - Fixes robotpy/mostrobotpy#51
- Loading branch information
Showing
5 changed files
with
418 additions
and
38 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
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,41 +1,4 @@ | ||
def main(): | ||
robotpy_logo = r""" | ||
/PPPPPPPPPPYYYYYYYYYY\ | ||
/PPPPPPPPPPPYYYYYYYYYYY\ | ||
/PPPPPPPPPPPPYYYYYYYYYYYY\ | ||
RRRRRR OOOOOO BBBBBB OOOOOO TTTTTTTT /PPP PPPY YYYYYY YY\ | ||
RR RR OO OO BB BB OO OO TT /PPPP PPPP PY YYYYYY YYY\ | ||
RR RR OO OO BB BB OO OO TT /PPPPP PPPPP PYY YYYY YYYYY\ | ||
RR RR OO OO BB BB OO OO TT /PPPPPP PPPPP PYY YYYY YYYYYY\ | ||
RR R OO OO BB B OO OO TT /PPPPPPP PPPP PYYY YY YYYYYYYY\ | ||
RRRRRR OO OO BBBBBB OO OO TT \PPPPPPP PPPYYYY YYYYYYYYY/ | ||
RR RR OO OO BB BB OO OO TT \PPPPPP PPPPPPPPYYYYY YYYYYYYYY/ | ||
RR RR OO OO BB BB OO OO TT \PPPPP PPPPPPPPYYYYY YYYYYYYY/ | ||
RR RR OO OO BB BB OO OO TT \PPPP PPPPPPPPYYYYY YYYYYYY/ | ||
RR RR OOOOOO BBBBBB OOOOOO TT \PPP PPPPPPPPYYYYY YYYYYY/ | ||
\PPPPPPPPPPPPYYYYYYYYYYYY/ | ||
\PPPPPPPPPPPYYYYYYYYYYY/ | ||
\PPPPPPPPPPYYYYYYYYYY/ | ||
""" | ||
|
||
try: | ||
from colorama import init, Back, Style | ||
|
||
init() | ||
robotpy_logo = ( | ||
robotpy_logo.replace("R", Back.BLUE + "R" + Style.RESET_ALL) | ||
.replace("O", Back.BLUE + "O" + Style.RESET_ALL) | ||
.replace("B", Back.BLUE + "B" + Style.RESET_ALL) | ||
.replace("T", Back.BLUE + "T" + Style.RESET_ALL) | ||
.replace("P", Back.BLUE + "P" + Style.RESET_ALL) | ||
.replace("Y", Back.BLUE + "Y" + Style.RESET_ALL) | ||
+ Style.RESET_ALL | ||
) | ||
except: | ||
pass | ||
|
||
print(robotpy_logo) | ||
|
||
from .main import main | ||
|
||
if __name__ == "__main__": | ||
main() |
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,65 @@ | ||
# novalidate | ||
|
||
import logging | ||
import pprint | ||
|
||
# TODO: Make these configurable | ||
log_datefmt = "%H:%M:%S" | ||
log_format = "%(asctime)s:%(msecs)03d %(levelname)-8s: %(name)-20s: %(message)s" | ||
|
||
|
||
def configure_logging(verbose): | ||
formatter = VerboseExceptionFormatter(fmt=log_format, datefmt=log_datefmt) | ||
|
||
# console logging | ||
handler = logging.StreamHandler() | ||
handler.setFormatter(formatter) | ||
|
||
logging.root.addHandler(handler) | ||
logging.root.setLevel(logging.DEBUG if verbose else logging.INFO) | ||
|
||
|
||
MAX_VARS_LINES = 30 | ||
MAX_LINE_LENGTH = 100 | ||
|
||
|
||
class VerboseExceptionFormatter(logging.Formatter): | ||
""" | ||
Taken from http://word.bitly.com/post/69080588278/logging-locals | ||
""" | ||
|
||
def __init__(self, log_locals_on_exception=True, *args, **kwargs): | ||
self._log_locals = log_locals_on_exception | ||
super(VerboseExceptionFormatter, self).__init__(*args, **kwargs) | ||
|
||
def formatException(self, exc_info): | ||
# First get the original formatted exception. | ||
exc_text = super(VerboseExceptionFormatter, self).formatException(exc_info) | ||
if not self._log_locals: | ||
return exc_text | ||
# Now we're going to format and add the locals information. | ||
output_lines = [exc_text, "\n"] | ||
|
||
# Retrieve locals from the innermost exception | ||
exc = exc_info[1] | ||
while exc.__cause__: | ||
exc = exc.__cause__ | ||
|
||
tb = exc.__traceback__ # This is the outermost frame of the traceback. | ||
if tb: # this should always be true, but sometimes someone messes up | ||
while tb.tb_next: | ||
tb = tb.tb_next # Zoom to the innermost frame. | ||
output_lines.append("Locals at innermost frame:\n") | ||
locals_text = pprint.pformat(tb.tb_frame.f_locals, indent=2) | ||
locals_lines = locals_text.split("\n") | ||
if len(locals_lines) > MAX_VARS_LINES: | ||
locals_lines = locals_lines[:MAX_VARS_LINES] | ||
locals_lines[-1] = "..." | ||
output_lines.extend( | ||
line[: MAX_LINE_LENGTH - 3] + "..." | ||
if len(line) > MAX_LINE_LENGTH | ||
else line | ||
for line in locals_lines | ||
) | ||
output_lines.append("\n") | ||
return "\n".join(output_lines) |
Oops, something went wrong.