Example #1
0
 def setfll(self, mode=None):
     if mode == None:
         print 'setfll requires an argument to set the file logging level'
         print '  setfll(logging.DEBUG) for everything'
         print '  setfll(logging.INFO) for info and above'
         print '  setfll(logging.WARNING) for warning and above'
         print '  setfll(logging.ERROR) for errors and above'
         print '  setfll(logging.CRITICAL) for critical messages only'
     else:
         lm = customlogger.LoggerManager()
         lm.setFileLoggingLevel(mode)
import linux_hub
import api
import Queue
import socket
import fcntl
import struct
import sys
import time

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 35093, struct.pack('256s', ifname[:15]))[20:24])


if __name__ == '__main__':
    customlogger.LoggerManager(True)
    zigbee_functional = False
    tcpip_functional = False
    linux_hub.setup_gpio()
    linux_hub.reset_ncp()
    dummy_queue = Queue.Queue(1)
    bridge_config = {'extended_pan_id': 0,
     'radio_power': 8,
     'network_create': False,
     'network_permit_joining': False,
     'print_progress_dots': False,
     'purge_link_keys': True}
    try:
        device = api.WeminucheApi(dummy_queue, bridge_config)
        device.getStackVersionString()
        device.shutdown()
Example #3
0
 def executeBridgeCommand(self, command):
     start_time = time.time()
     command_name = command.command_name
     self.logger.debug('Running executeBridgeCommand with %s' % command)
     if command.command_name == 'add_device_encryption_key':
         if command.params.has_key(
                 'device_address') and command.params.has_key(
                     'encryption_key'):
             device_address = command.params['device_address']
             encryption_key_base64 = command.params['encryption_key']
             encryption_key_bin = base64.b64decode(encryption_key_base64)
             encryption_key_seq = struct.unpack('BBBBBBBBBBBBBBBB',
                                                encryption_key_bin)
             self.device.TCAddOrUpdateKey(
                 byte_tuple.convertToEui64(device_address),
                 encryption_key_seq)
             return 0
         raise TypeError, "BridgeCommand 'add_device_encryption_key' takes two arguments, 'device_address' and 'encryption_key'"
     elif command.command_name == 'set_cloud_log_level':
         lm = customlogger.LoggerManager()
         level = command.param_value_for_key('level')
         if isinstance(level, int):
             level = command.params['level']
             if level < 10:
                 level = 10
             elif level > 50:
                 level = 50
         if isinstance(level, str) or isinstance(level, unicode):
             level = level.lower()
             log_level = logging.WARNING
             if level == 'debug':
                 log_level = logging.DEBUG
             elif level == 'info':
                 log_level = logging.INFO
             elif level == 'warning':
                 log_level = logging.WARNING
             elif level == 'error':
                 log_level = logging.ERROR
             elif level == 'critical':
                 log_level = logging.CRITICAL
             self.logger.debug('Setting cloud logging level to %d' %
                               log_level)
             result = lm.setCloudLoggingLevel(log_level)
             return result
         raise TypeError, "BridgeCommand 'set_cloud_log_level' takes a 'level' argument of type string"
     elif command.command_name == 'leave':
         result = self.device.emberLeaveNetwork()
         return result
     if command.command_name == 'form':
         channels = command.param_value_for_key('channels')
         if not isinstance(channels, list):
             channels = [11, 14, 15, 19, 20, 24, 25]
         result = self.device.scanForUnusedPanId(channels)
         return result
     if command.command_name == 'pjoin':
         duration = command.param_value_for_key('duration')
         if isinstance(duration, str) or isinstance(
                 duration, int) or isinstance(duration, unicode):
             self.device.emberPermitJoining(int(duration))
         else:
             self.device.emberPermitJoining(255)
     else:
         if command.command_name == 'restart':
             self.logger.warning("Issuing 'restart' flag!")
             self.should_restart = True
             return 0
         else:
             if command.command_name == 'reboot':
                 self.logger.warning("Issuing 'reboot' flag!")
                 self.should_reboot = True
                 return 0
             self.logger.error("Unknown BridgeCommand name '%s'" %
                               command.command_name)
             return 1
Example #4
0
 ) = parser.parse_args()
 if options.pid:
     if os.path.exists(PID_FILE):
         with open(PID_FILE, 'r') as f:
             running_pid = f.read()
         raise Exception(
             'Script is already running with pid %s. Remove %s if the process is no longer running'
             % (running_pid, PID_FILE))
     else:
         pid = str(os.getpid())
         with open(PID_FILE, 'w') as f:
             f.write(pid)
 log_queue = None
 if options.cloudlog or options.htmllog:
     log_queue = Queue.Queue(LOG_QUEUE_SIZE)
 customlogger.LoggerManager(options.daemon, options.logfile, log_queue)
 app = BergCloudSocketBridge(options, log_queue)
 if options.logfile_level != '':
     app.setfll(int(options.logfile_level))
 if options.cloudlog_level != '':
     app.setcll(int(options.cloudlog_level))
 if options.daemon:
     sys.stdout = customlogger.StdOutLogger()
     sys.stderr = customlogger.StdErrLogger()
     signal.signal(signal.SIGTERM, app.shutdown)
     signal.signal(signal.SIGINT, app.shutdown)
     signal.signal(signal.SIGALRM, app.shutdown)
     print 'Loggers and signal handlers installed',
 app.run()
 if not options.daemon:
     help = 'Type app.help() for more detailed help'