Skip to content

Commit

Permalink
pyterm: prefix pyterm commands with /
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegHahm committed Aug 1, 2014
1 parent dd469b1 commit f816d74
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions dist/tools/pyterm/pyterm.py
Expand Up @@ -67,6 +67,11 @@ def preloop(self):
receiver_thread.setDaemon(1)
receiver_thread.start()

def precmd(self, line):
if (line.startswith("/")):
return "PYTERM_" + line[1:]
return line

def default(self, line):
for tok in line.split(';'):
tok = self.get_alias(tok)
Expand All @@ -79,15 +84,15 @@ def complete_date(self, text, line, begidx, endidm):
date = time.strftime("%Y-%m-%d %H:%M:%S")
return ["{}".format(date)]

def do_reset(self, line):
def do_PYTERM_reset(self, line):
self.ser.setDTR(1)
self.ser.setDTR(0)

def do_exit(self, line):
def do_PYTERM_exit(self, line):
readline.write_history_file()
sys.exit(0)

def do_save(self, line):
def do_PYTERM_save(self, line):
if not self.config.has_section("general"):
self.config.add_section("general")
self.config.set("general", "port", self.port)
Expand Down Expand Up @@ -115,11 +120,11 @@ def do_save(self, line):
self.config.write(config_fd)
print("Config saved")

def do_show_config(self, line):
def do_PYTERM_show_config(self, line):
for key in self.__dict__:
print(str(key) + ": " + str(self.__dict__[key]))

def do_alias(self, line):
def do_PYTERM_alias(self, line):
if line.endswith("list"):
for alias in self.aliases:
print("{} = {}".format(alias, self.aliases[alias]))
Expand All @@ -129,7 +134,7 @@ def do_alias(self, line):
return
self.aliases[line.split('=')[0].strip()] = line.split('=')[1].strip()

def do_rmalias(self, line):
def do_PYTERM_rmalias(self, line):
if not self.aliases.pop(line, None):
sys.stderr.write("Alias not found")

Expand All @@ -139,21 +144,21 @@ def get_alias(self, tok):
return self.aliases[alias] + tok[len(alias):]
return tok

def do_ignore(self, line):
def do_PYTERM_ignore(self, line):
self.ignores.append(re.compile(line.strip()))

def do_unignore(self, line):
def do_PYTERM_unignore(self, line):
for r in self.ignores:
if (r.pattern == line.strip()):
print("Remove ignore for %s" % r.pattern)
self.ignores.remove(r)
return
sys.stderr.write("Ignore for %s not found\n" % line.strip())

def do_filter(self, line):
def do_PYTERM_filter(self, line):
self.filters.append(re.compile(line.strip()))

def do_unfilter(self, line):
def do_PYTERM_unfilter(self, line):
for r in self.filters:
if (r.pattern == line.strip()):
print("Remove filter for %s" % r.pattern)
Expand Down

0 comments on commit f816d74

Please sign in to comment.