Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Added xonsh shell in dynamic #167

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
650 changes: 650 additions & 0 deletions dynamic/formatter.py

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions dynamic/lib/pretty_date_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import print_function
from __future__ import division

import calendar
from datetime import datetime
import pytz
import time


def pretty_date_time(date_time):
"""Prints a pretty datetime similar to what's seen on Hacker News.

Gets a datetime object or a int() Epoch timestamp and return a
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
'just now', etc.

Adapted from: http://stackoverflow.com/questions/1551382/user-friendly-time-format-in-python # NOQA

Args:
* date_time: An instance of datetime.

Returns:
A string that represents the pretty datetime.
"""
now = datetime.now(pytz.utc)
if type(date_time) is int:
diff = now - datetime.fromtimestamp(date_time)
elif type(date_time) is time.struct_time:
date_time = datetime.fromtimestamp(calendar.timegm(date_time),
tz=pytz.utc)
diff = now - date_time
elif isinstance(date_time, datetime):
diff = now - date_time
elif not date_time:
diff = now - now
second_diff = diff.seconds
day_diff = diff.days
if day_diff < 0:
return ''
if day_diff == 0:
if second_diff < 10:
return "just now"
if second_diff < 60:
return str(second_diff) + " seconds ago"
if second_diff < 120:
return "1 minute ago"
if second_diff < 3600:
return str(second_diff // 60) + " minutes ago"
if second_diff < 7200:
return "1 hour ago"
if second_diff < 86400:
return str(second_diff // 3600) + " hours ago"
if day_diff == 1:
return "Yesterday"
if day_diff < 7:
return str(day_diff) + " days ago"
if day_diff < 31:
return str(day_diff // 7) + " week(s) ago"
if day_diff < 365:
return str(day_diff // 30) + " month(s) ago"
return str(day_diff // 365) + " year(s) ago"

4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ configparser==5.0.2
crayons==0.4.0
selenium==3.141.0
webdriver-manager==3.3.0
simple-term-menu==1.0.1
simple-term-menu==1.0.1
xonsh==0.11.0
jedis==0.18.2
3 changes: 3 additions & 0 deletions script/dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python -u
from xonsh.main import main
main()
2 changes: 2 additions & 0 deletions script/dynamic.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
python -m xonsh.main
8 changes: 8 additions & 0 deletions script/dynamic_complete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_dynamic_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_DYNAMIC_COMPLETE=complete $1 ) )
return 0
}

complete -F _dynamic_completion -o default dynamic;
3 changes: 3 additions & 0 deletions script/xonsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python -u
from xonsh.main import main
main()
2 changes: 2 additions & 0 deletions script/xonsh.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
python -m xonsh.main
2 changes: 2 additions & 0 deletions scripts/dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from xonsh.main import main
main()
2 changes: 2 additions & 0 deletions scripts/xonsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from xonsh.main import main
main()
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"selenium==3.141.0",
"webdriver-manager==3.3.0",
"simple-term-menu==1.0.1",
"xonsh==0.11.0",
"prompt_toolkit==3.0",
"jedi==0.18.2"
]

setuptools.setup(
Expand Down
104 changes: 104 additions & 0 deletions xonsh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
__version__ = "0.8.10"


# amalgamate exclude jupyter_kernel parser_table parser_test_table pyghooks
# amalgamate exclude winutils wizard pytest_plugin fs macutils pygments_cache
# amalgamate exclude jupyter_shell
import os as _os

if _os.getenv("XONSH_DEBUG", ""):
pass
else:
import sys as _sys

try:
from xonsh import __amalgam__

completer = __amalgam__
_sys.modules["xonsh.completer"] = __amalgam__
contexts = __amalgam__
_sys.modules["xonsh.contexts"] = __amalgam__
lazyasd = __amalgam__
_sys.modules["xonsh.lazyasd"] = __amalgam__
lazyjson = __amalgam__
_sys.modules["xonsh.lazyjson"] = __amalgam__
color_tools = __amalgam__
_sys.modules["xonsh.color_tools"] = __amalgam__
platform = __amalgam__
_sys.modules["xonsh.platform"] = __amalgam__
pretty = __amalgam__
_sys.modules["xonsh.pretty"] = __amalgam__
codecache = __amalgam__
_sys.modules["xonsh.codecache"] = __amalgam__
lazyimps = __amalgam__
_sys.modules["xonsh.lazyimps"] = __amalgam__
parser = __amalgam__
_sys.modules["xonsh.parser"] = __amalgam__
tokenize = __amalgam__
_sys.modules["xonsh.tokenize"] = __amalgam__
tools = __amalgam__
_sys.modules["xonsh.tools"] = __amalgam__
ansi_colors = __amalgam__
_sys.modules["xonsh.ansi_colors"] = __amalgam__
ast = __amalgam__
_sys.modules["xonsh.ast"] = __amalgam__
commands_cache = __amalgam__
_sys.modules["xonsh.commands_cache"] = __amalgam__
diff_history = __amalgam__
_sys.modules["xonsh.diff_history"] = __amalgam__
events = __amalgam__
_sys.modules["xonsh.events"] = __amalgam__
foreign_shells = __amalgam__
_sys.modules["xonsh.foreign_shells"] = __amalgam__
jobs = __amalgam__
_sys.modules["xonsh.jobs"] = __amalgam__
jsonutils = __amalgam__
_sys.modules["xonsh.jsonutils"] = __amalgam__
lexer = __amalgam__
_sys.modules["xonsh.lexer"] = __amalgam__
openpy = __amalgam__
_sys.modules["xonsh.openpy"] = __amalgam__
style_tools = __amalgam__
_sys.modules["xonsh.style_tools"] = __amalgam__
xontribs = __amalgam__
_sys.modules["xonsh.xontribs"] = __amalgam__
dirstack = __amalgam__
_sys.modules["xonsh.dirstack"] = __amalgam__
inspectors = __amalgam__
_sys.modules["xonsh.inspectors"] = __amalgam__
proc = __amalgam__
_sys.modules["xonsh.proc"] = __amalgam__
shell = __amalgam__
_sys.modules["xonsh.shell"] = __amalgam__
timings = __amalgam__
_sys.modules["xonsh.timings"] = __amalgam__
xonfig = __amalgam__
_sys.modules["xonsh.xonfig"] = __amalgam__
base_shell = __amalgam__
_sys.modules["xonsh.base_shell"] = __amalgam__
environ = __amalgam__
_sys.modules["xonsh.environ"] = __amalgam__
tracer = __amalgam__
_sys.modules["xonsh.tracer"] = __amalgam__
readline_shell = __amalgam__
_sys.modules["xonsh.readline_shell"] = __amalgam__
replay = __amalgam__
_sys.modules["xonsh.replay"] = __amalgam__
aliases = __amalgam__
_sys.modules["xonsh.aliases"] = __amalgam__
dumb_shell = __amalgam__
_sys.modules["xonsh.dumb_shell"] = __amalgam__
built_ins = __amalgam__
_sys.modules["xonsh.built_ins"] = __amalgam__
execer = __amalgam__
_sys.modules["xonsh.execer"] = __amalgam__
imphooks = __amalgam__
_sys.modules["xonsh.imphooks"] = __amalgam__
main = __amalgam__
_sys.modules["xonsh.main"] = __amalgam__
del __amalgam__
except ImportError:
pass
del _sys
del _os
# amalgamate end
2 changes: 2 additions & 0 deletions xonsh/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from xonsh.main import main
main()
Loading