Skip to content

Commit

Permalink
Merge pull request #128 from dhylands/add-date-cmd
Browse files Browse the repository at this point in the history
Add a date command
  • Loading branch information
dhylands authored Mar 7, 2020
2 parents f38a350 + 3ef56b1 commit 42c39bd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions rshell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,14 @@ def cp(src_filename, dst_filename):
return False


def date():
import time
tm = time.localtime()
dow = ('Mon', 'Tue', 'Web', 'Thu', 'Fri', 'Sat', 'Sun')
mon = ('???', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
return repr('{} {} {:2d} {:02d}:{:02d}:{:02d} {}'.format(dow[tm[6]], mon[tm[1]], tm[2], tm[3], tm[4], tm[5], tm[0]))


def eval_str(string):
"""Executes a string containing python code."""
output = eval(string)
Expand Down Expand Up @@ -2188,6 +2196,34 @@ def do_cp(self, line):
print_err(err.format(src_filename, dst_filename))
break

argparse_date = (
add_arg(
'-b', '--board',
dest='board',
action='store',
help='Specify which board to get the date for',
default=None
),
)

def do_date(self, line):
"""date [-b boardname]
Displays the current date and time for the board indicated by the -b option,
or, if no board is specified, then it will use the current directory to
determine the board.
"""
args = self.line_to_args(line)
if args.board is None:
dev, _ = get_dev_and_path(cur_dir)
else:
dev = find_device_by_name(args.board)
if dev is None:
self.print('Host:', eval(date()))
else:
self.print('{}: {}'.format(dev.name, trim(dev.remote_eval(date))))


def do_echo(self, line):
"""echo TEXT...
Expand Down

0 comments on commit 42c39bd

Please sign in to comment.