def nipple_switch(self, status=None): if "nipple" in self.names_devices: status_xinput = {"on": "enable", "off": "disable"} if status_xinput.has_key(status): log.info("change nipple to {status}".format(status=status)) engage_command("xinput {status} \"{name_device}\"".format( status=status_xinput[status], name_device=self.names_devices["nipple"])) else: _message = "unknown nipple status \"{status}\" " +\ "requested" log.error(_message.format(status=status)) sys.exit() else: log.debug("nipple status unchanged")
def main(options): filename_log = options["--logfile"] global program program = propyte.Program(options=options, name=name, version=version, logo=logo, filename_log=filename_log) global log from propyte import log log.debug("message at level DEBUG") log.info("message at level INFO") log.warning("message at level WARNING") log.error("message at level ERROR") log.critical("message at level CRITICAL") program.terminate()
def main(options): global program program = propyte.Program(options=options, name=name, version=version, logo=logo) global log from propyte import log log.info("") input_data_filename = options["--data"] log.info( "input data file: {filename}".format(filename=input_data_filename)) log.debug("start to print log messages at various levels") log.debug("message at level DEBUG") log.info("message at level INFO") log.warning("message at level WARNING") log.error("message at level ERROR") log.critical("message at level CRITICAL") log.debug("stop printing log messages at various levels") function_1() log.info("") program.terminate()
def main(options): global program program = propyte.Program( options = options, name = name, version = version, logo = logo ) global log from propyte import log log.info("") input_data_filename = options["--data"] log.info("input data file: {filename}".format( filename = input_data_filename )) log.debug("start to print log messages at various levels") log.debug("message at level DEBUG") log.info("message at level INFO") log.warning("message at level WARNING") log.error("message at level ERROR") log.critical("message at level CRITICAL") log.debug("stop printing log messages at various levels") function_1() log.info("") program.terminate()
def main(options): filename_log = options["--logfile"] global program program = propyte.Program( options = options, name = name, version = version, logo = logo, filename_log = filename_log ) global log from propyte import log log.debug("message at level DEBUG") log.info("message at level INFO") log.warning("message at level WARNING") log.error("message at level ERROR") log.critical("message at level CRITICAL") program.terminate()
def touchpad_orientation(self, orientation=None): if "touchpad" in self.names_devices: coordinate_transformation_matrix = { "left": "0 -1 1 1 0 0 0 0 1", "right": "0 1 0 -1 0 1 0 0 1", "inverted": "-1 0 1 0 -1 1 0 0 1", "normal": "1 0 0 0 1 0 0 0 1" } if coordinate_transformation_matrix.has_key(orientation): log.info("change touchpad to {orientation}".format( orientation=orientation)) engage_command( "xinput set-prop \"{name_device}\" \"Coordinate " "Transformation Matrix\" " "{matrix}".format( name_device=self.names_devices["touchpad"], matrix=coordinate_transformation_matrix[orientation])) else: log.error("unknown touchpad orientation \"{orientation}\"" " requested".format(orientation=orientation)) sys.exit() else: log.debug("touchpad orientation unchanged")
def main(options): global program program = propyte.Program(options=options, name=name, version=version, logo=logo) global log from propyte import log # access options and arguments database = options["--inputdatabase"] database_out = options["--outputdatabase"] # Access database. database = abstraction.access_database(filename=database) log.info("database metadata:") abstraction.log_database_metadata(filename=database) # Print the tables in the database. log.info("tables in database: {tables}".format(tables=database.tables)) # Access the exchanges table. tablename = "exchanges" log.info("access table \"{tablename}\"".format(tablename=tablename)) # Print the columns of the table. log.info("columns in table \"{tablename}\": {columns}".format( tablename=tablename, columns=database[tablename].columns)) # Print the number of rows of the table. log.info( "number of rows in table \"{tablename}\": {number_of_rows}".format( tablename=tablename, number_of_rows=str(len(database[tablename])))) # Build a list of unique exchanges. exchanges = [] for entry in database[tablename].all(): # Create a new exchange object for the existing exchange data, check its # utterance data against existing utterance data in the new list of # exchanges and append it to the new list of exchanges if it does not # exist in the list. exchange = abstraction.Exchange( utterance=entry["utterance"], response=entry["response"], utterance_time_UNIX=entry["utteranceTimeUNIX"], response_time_UNIX=entry["responseTimeUNIX"], utterance_reference=entry["utteranceReference"], response_reference=entry["responseReference"], exchange_reference=entry["exchangeReference"]) # Check new exchange against exchanges in new list. append_flag = True for exchange_in_new_list in exchanges: if exchange.utterance == exchange_in_new_list.utterance: append_flag = False if append_flag is True: log.debug("keep exchange \"{utterance}\"".format( utterance=exchange.utterance)) exchanges.append(exchange) else: log.debug("skip exchange \"{utterance}\"".format( utterance=exchange.utterance)) # Save the exchanges to the new database. log.info("save exchanges to database (only those not saved previously)") abstraction.save_exchanges_to_database(exchanges=exchanges, filename=database_out) # Save metadata to the new database. abstraction.save_database_metadata(filename=database_out) program.terminate()
def main(options): global program program = propyte.Program( options = options, name = name, version = version, logo = logo ) global log from propyte import log host = "127.0.0.1" # 10.0.0.41 port_number = 2718 filename_peers = options["--peersfile"] log.info("") # Read the local peers list. if not os.path.exists(filename_peers): log.error("file {filename} not found".format( filename = filename_peers )) program.terminate() peers_list_local = [line.rstrip("\n") for line in open(filename_peers)] peers_consensus = shijian.List_Consensus() peers_consensus.append(tuple(peers_list_local)) log.debug("peers list local: {peers}".format( peers = peers_list_local )) log.debug("peers list consensus: {peers}".format( peers = peers_consensus.consensus() )) port = int(str(port_number), 10) address_remote = (host, port) # Create a datagram socket for UDP. socket_UDP = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Set the socket to be reusable. socket_UDP.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Set the socket to accept incoming broadcasts. socket_UDP.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) # Disengage socket blocking. socket_UDP.setblocking(False) # Set the socket to accept connections on the port. socket_UDP.bind(("", port)) # Communicate data in a loop. log.info("Ctrl c to exit") while True: # receive try: # buffer size: 8192 message, address = socket_UDP.recvfrom(8192) message = message.rstrip("\n") if message: log.debug("{address}:{port_number}> {message}".format( address = address[0], port_number = port_number, message = message )) # upcoming: message accept/reject procedure # Record the sender ID in order to limit the number of senders # such that scalability problems do not manifest. # Record the message ID in order to avoid parsing it again. # If a peers list is detected, parse it and add it to the # consensus. if "peers =" in message: peers_list_remote = eval(message.lstrip("peers =").rstrip(";")) peers_consensus.append(tuple(peers_list_remote)) if len(peers_consensus) >= 3: peers_consensus_list = list(peers_consensus.consensus()) log.debug("consensus peers list: {peers_consensus_list}".format( peers_consensus_list = peers_consensus_list )) log.debug("update local peers list with consensus peers list") peers_list_local = peers_consensus_list # upcoming functionality # If a heartbeat is detected, send the local peers list. if "heartbeat" in message: message_send = "peers = {peers_list_local};".format( peers_list_local = peers_list_local ) socket_UDP.sendto(message_send, address) except: pass # send message_send =\ "message_text = heartbeat; message_ID = {message_ID};".format( message_ID = shijian.UID() ) socket_UDP.sendto(message_send, address_remote) time.sleep(1) log.info("") program.terminate()
def main(options): global program program = propyte.Program(options=options, name=name, version=version, logo=logo) global log from propyte import log filename_database = options["--inputdatabase"] filename_database_out = options["--outputdatabase"] name_table = options["--table"] name_table_metadata = options["--tablemetadata"] log.info("\naccess database {filename}".format(filename=filename_database)) database = dataset.connect("sqlite:///{filename_database}".format( filename_database=filename_database)) log.info("access table \"{name_table}\"".format(name_table=name_table)) table = database[name_table] log.info( "number of rows in table \"{name_table}\": {number_of_rows}".format( name_table=name_table, number_of_rows=str(len(table)))) # Fix database with data version 2015-01-06T172242Z. # Build a list of unique exchanges. exchanges = [] for entry in table: utterance = entry["utterance"] response = entry["response"] utterance_time_UNIX = entry["utteranceTimeUNIX"] response_time_UNIX = entry["responseTimeUNIX"] utterance_reference = entry["utteranceReference"] response_reference = entry["responseReference"] exchange_reference = entry["exchangeReference"] if type(utterance_reference) is tuple: log.debug("\nchange utterance reference") log.debug("from:\n{utterance_reference}".format( utterance_reference=utterance_reference)) utterance_reference = utterance_reference[0] log.debug("to:\n{utterance_reference}".format( utterance_reference=utterance_reference)) if type(response_reference) is tuple: log.debug("\nchange response reference") log.debug("from:\n{response_reference}".format( response_reference=response_reference)) response_reference = response_reference[0] log.debug("to:\n{response_reference}".format( response_reference=response_reference)) if exchange_reference[0] == "(": log.debug("\nchange exchange reference") log.debug("from:\n{exchange_reference}".format( exchange_reference=exchange_reference)) exchange_reference = ast.literal_eval(exchange_reference) exchange_reference = unicode(str(exchange_reference[0]), "utf-8") log.debug("to:\n{exchange_reference}".format( exchange_reference=exchange_reference)) # Create a new exchange object using the fixed entries and append it to # the list of modified exchanges. exchange = abstraction.Exchange( utterance=utterance, response=response, utterance_time_UNIX=utterance_time_UNIX, response_time_UNIX=response_time_UNIX, utterance_reference=utterance_reference, response_reference=response_reference, exchange_reference=exchange_reference) exchange.printout() exchanges.append(exchange) # Save the exchanges to the new database. log.info("save exchanges to database") abstraction.save_exchanges_to_database(exchanges=exchanges, filename=filename_database_out) # Save metadata to the new database. abstraction.save_database_metadata(filename=filename_database_out) program.terminate()