<commit_before>#!/usr/bin/python
"""Arcom RC210 control - XMLRPC Client

   KD7DK/Doug, KG7AUL/CK 12/16

   Copyright 2016 <NAME>, KG7AUL
   Released under Apache License V2.0
   http://www.apache.org/licenses/LICENSE-2.0.txt

   Reference: RCP Protocol and Serial Port Operations
   (available from the Arcom website)
"""
import getopt
import os
import re
import sys
import time
import xmlrpclib
from time import sleep
from configparser import ConfigParser

config_file = '.arcom.conf'
testing = True
verbose = 1
Valid_Options = ['testing=', 'verbose=']


def countdown(t):
  """Count down t seconds printing the time in minutes:seconds.
     Allows users to interrupt out of the countdown.
  """
  while t:
    try:
      mins, secs = divmod(t, 60)
      timeformat = '{:02d}:{:02d}'.format(mins, secs)
      sys.stdout.write("\rCountdown: " + timeformat + "< [CTRL+C to re-enable]")
      sys.stdout.flush()
      sleep(1)
      t -= 1
    except KeyboardInterrupt:
      print ""
      break

def interact(cfg):
  """Main user interaction loop.
     We pass in a configuration object which must at a minimum have callsign (call).
  """
  arcom = xmlrpclib.ServerProxy("http://localhost:45000")
  call = cfg.get('arcom', 'call')
  if not re.match(r'[A-Za-z]+\d[A-Za-z]+', call):
    print "No call specified in .arcom.conf (e.g. call = N7AAA)."
    return
  identity = arcom.getIdentity(call)

  def ask_confirm(question, default):
    """Prompt for user yes/no response with a possible default"""
    valid = {"yes": True, "y": True, "ye": True,
             "no": False, "n": False}
    if default is None:
      prompt = " [y/n] "
    elif default == "yes":
      prompt = " [Y/n] "
    elif default == "no":
      prompt = " [y/N] "
    else:
      raise ValueError("invalid default answer: '%s'" % default)

    while True:
      sys.stdout.write(question + prompt)
      choice = raw_input().lower()
      if default is not None and choice == '':
        return valid[default]
      elif choice in valid:
        return valid[choice]
      else:
        sys.stdout.write("Please respond with 'yes' or 'no' "
                         "(or 'y' or 'n').\n")

  def disable_for_minutes(minutes):
    """Disable for specified number of seconds.
       If the users interrupts the countdown, re-enable immediately.
    """
    if ask_confirm("Are you SURE? [Action will be logged.]\n", "no"):
      print "DISABLING Port 1 XMIT - %02d:00 Minutes" % minutes
      arcom.port1Disable(call)
      arcomlogInterference(minutes)
      countdown(minutes*60)
      arcom.port1Enable(call)
      print "\rPort 1 XMIT RE-ENABLED"

  def printStatus(status):
    for key, value in sorted(status.items()):
      if key == 'testing' and value:
        print " |             TESTING MODE!                    |"
      else:
        print " | %-16.16s %-27.27s |" % (key, value)

  def print_menu(status):       ## Your menu design here
    """Render the menu."""
    #TODO(dpk): we should use curses library here?
    os.system('clear') # this is expensive.
    print " ", 8 * "-", "%6.6s - Arcom RC210 Control" % identity, 8 * "-"
    printStatus(status)
    print " |", 44 * " ", "|"
    print " | 0.  Exit                                     |"
    print " | 1.  DISABLE Port 1 XMIT - 05:00 Minutes      |"
    print " | 2.  DISABLE Port 1 XMIT - 10:00 Minutes      |"
    print " | 3.  DISABLE Port 1 XMIT - 15:00 Minutes      |"
    print " | 4.  DISABLE Port 1 XMIT                      |"
    print " | 5.  ENABLE  Port 1 XMIT                      |"
    print " | 6.  UN-BRIDGE IRLP NODE Port 3</>1           |"
    print " | 7.  BRIDGE    IRLP NODE Port 3<->1           |"
    print " | 8.  RESTART CONTROLLER                       |"
    print " | 9.  SET DATE/TIME                            |"
    print " | 10. GET LAST 10 LOG ENTRIES                  |"
    print " |", 44 * " ", "|"
    print " ", 30 * "-", "KG7AUL/KD7DK", "--"

  def listLog(entries):
    """Display the log entry tuples (time, call, string)."""
    for entry in entries:
      seconds, call, string = entry
      tm = time.localtime(seconds)
      print "%s [%s] %s" % (time.strftime('%x %X', tm), call, string)

  def dispatch(line):
    """Decide what do to.  Eventually table driven?"""
    try:
      choice = int(line)
    except ValueError:
      choice = 99

    if choice is 1:
      disable_for_minutes(5)
    elif choice is 2:
      disable_for_minutes(10)<commit_msg>Revert "Merge pull request #11 from dpkingston/tweak-menu"<commit_after>#!/usr/bin/python
"""Arcom RC210 control - XMLRPC Client

   KD7DK/Doug, KG7AUL/CK 12/16

   Copyright 2016 <NAME>, KG7AUL
   Released under Apache License V2.0
   http://www.apache.org/licenses/LICENSE-2.0.txt

   Reference: RCP Protocol and Serial Port Operations
   (available from the Arcom website)
"""
import getopt
import os
import re
import sys
import time
import xmlrpclib
from time import sleep
from configparser import ConfigParser

config_file = '.arcom.conf'
testing = True
verbose = 1
Valid_Options = ['testing=', 'verbose=']


def countdown(t):
  """Count down t seconds printing the time in minutes:seconds.
     Allows users to interrupt out of the countdown.
  """
  while t:
    try:
      mins, secs = divmod(t, 60)
      timeformat = '{:02d}:{:02d}'.format(mins, secs)
      sys.stdout.write("\rCountdown: " + timeformat + "< [CTRL+C to re-enable]")
      sys.stdout.flush()
      sleep(1)
      t -= 1
    except KeyboardInterrupt:
      print ""
      break

def interact(cfg):
  """Main user interaction loop.
     We pass in a configuration object which must at a minimum have callsign (call).
  """
  arcom = xmlrpclib.ServerProxy("http://localhost:45000")
  call = cfg.get('arcom', 'call')
  if not re.match(r'[A-Za-z]+\d[A-Za-z]+', call):
    print "No call specified in .arcom.conf (e.g. call = N7AAA)."
    return
  identity = arcom.getIdentity(call)

  def ask_confirm(question, default):
    """Prompt for user yes/no response with a possible default"""
    valid = {"yes": True, "y": True, "ye": True,
             "no": False, "n": False}
    if default is None:
      prompt = " [y/n] "
    elif default == "yes":
      prompt = " [Y/n] "
    elif default == "no":
      prompt = " [y/N] "
    else:
      raise ValueError("invalid default answer: '%s'" % default)

    while True:
      sys.stdout.write(question + prompt)
      choice = raw_input().lower()
      if default is not None and choice == '':
        return valid[default]
      elif choice in valid:
        return valid[choice]
      else:
        sys.stdout.write("Please respond with 'yes' or 'no' "
                         "(or 'y' or 'n').\n")

  def disable_for_minutes(minutes):
    """Disable for specified number of seconds.
       If the users interrupts the countdown, re-enable immediately.
    """
    if ask_confirm("Are you SURE? [Action will be logged.]\n", "no"):
      print "DISABLING Port 1 XMIT - %02d:00 Minutes" % minutes
      arcom.port1Disable(call)
      arcomlogInterference(minutes)
      countdown(minutes*60)
      arcom.port1Enable(call)
      print "\rPort 1 XMIT RE-ENABLED"

  def printStatus(status):
    for key, value in sorted(status.items()):
      if key == 'testing' and value:
        print " |             TESTING MODE!                    |"
      else:
        print " | %-16.16s %-27.27s |" % (key, value)

  def print_menu(status):       ## Your menu design here
    """Render the menu."""
    #TODO(dpk): we should use curses library here?
    os.system('clear') # this is expensive.
    print " ", 8 * "-", "%6.6s - Arcom RC210 Control" % identity, 8 * "-"
    printStatus(status)
    print " |", 44 * " ", "|"
    print " | 0.  Quit                                     |"
    print " | 1.  DISABLE Port 1 XMIT - 05:00 Minutes      |"
    print " | 2.  DISABLE Port 1 XMIT - 10:00 Minutes      |"
    print " | 3.  DISABLE Port 1 XMIT - 15:00 Minutes      |"
    print " | 4.  DISABLE Port 1 XMIT                      |"
    print " | 5.  ENABLE  Port 1 XMIT                      |"
    print " | 6.  UN-BRIDGE IRLP NODE Port 3</>1           |"
    print " | 7.  BRIDGE    IRLP NODE Port 3<->1           |"
    print " | 8.  RESTART CONTROLLER                       |"
    print " | 9.  SET DATE/TIME                            |"
    print " | 10. GET LAST 10 LOG ENTRIES                  |"
    print " |", 44 * " ", "|"
    print " ", 30 * "-", "KG7AUL/KD7DK", "--"

  def listLog(entries):
    """Display the log entry tuples (time, call, string)."""
    for entry in entries:
      seconds, call, string = entry
      tm = time.localtime(seconds)
      print "%s [%s] %s" % (time.strftime('%x %X', tm), call, string)

  def dispatch(line):
    """Decide what do to.  Eventually table driven?"""
    try:
      choice = int(line)
    except ValueError:
      choice = 99

    if choice is 1:
      disable_for_minutes(5)
    elif choice is 2:
      disable_for_minutes(10)
{'fraction_non_alphanumeric': 0.13286400715163704, 'fraction_numerical': 0.02436026371661638, 'mean_word_length': 2.163662071403323, 'pattern_counts': {'":': 14, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6655340', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2866, 'n_words': 891}