def save_file(incoming_data, file_name): answer = input( f"Enter 'Y' if you would like to save the data to {file_name}: " ).upper() if answer == 'Y': core.write_to_file(incoming_data, file_name) print(f'The data was saved to {file_name}')
def OnInit(self): """Override `wx.App.OnInit()`.""" # Read or create the model (table) # TODO: Read columns from config file logging.config.fileConfig('logging.cfg') # Backup the old data file if it exists outfile = 'data.csv' if os.path.isfile(outfile): backup = outfile[:-4] + '.bak' if os.path.isfile(backup): os.remove(backup) os.rename(outfile, backup) # Get column headings columns = core.get_columns() if columns: core.write_to_file(outfile, (columns,)) # Set up the serial port reader controller = core.DataManager(outfile) self.table = Table(columns) controller.datacallbacks.append(self.table.data_received) self.frame = Frame(None, 'pylibra', self.table, controller) self.frame.Show() self.SetTopWindow(self.frame) return True # No errors during init
def rild_pid(): # Shared code: belongs_to_rild = lambda fn: contents_of( fn).startswith("/system/bin/rild") try: last_known_pid = int( contents_of("/var/run/rild.pid") ) except IOError: last_known_pid = 1 # If rild no longer has a process ID of last_known_pid: if not belongs_to_rild("/proc/%i/cmdline"%last_known_pid): # find rild: for fn in glob("/proc/*/cmdline"): if belongs_to_rild( fn): last_known_pid = int( fn.split("/")[2] ) write_to_file( str(last_known_pid), "/var/run/rild.pid") return last_known_pid
def main(): """Main program entry function. Parse the command line, process the options and start the parser. """ # Make stdout write almost immediately sys.stdout = utils.FlushFile(sys.stdout) # Parse the command line options argsParser = optparse.OptionParser(version=core.__version__) argsParser.add_option( "-o", "--outfile", dest="outfile", help="output data to outfile (%default)", default="data.csv" ) options = argsParser.parse_args()[0] _LOGGER.info("Starting pylibra" + "-" * 30) _LOGGER.debug("Options: " + str(options)) # Backup the old data file if it exists if os.path.isfile(options.outfile): backup = options.outfile[:-4] + ".bak" if os.path.isfile(backup): os.remove(backup) os.rename(options.outfile, backup) # Read the settings file app = core.DataManager(options.outfile) app.datacallbacks.append(echo) columns = core.get_columns() if columns: core.write_to_file(options.outfile, (columns,)) # Start the parser app.start_parser() # Block until quit command is received while True: command = raw_input("Type q to quit:") if command[0] == "q": break # Stop the parser app.stop_parser() print "Quitting." _LOGGER.info("Exit OK." + "-" * 30)
def battery_level(): return battery.level() def backlight_brightness(): return backlight.brightness() def set_backlight_brightness( level): backlight.set_brightness( level) def temperature(): return battery.temperature() # My rild has a memory leak, although I don't want it restarted automatically # because I might be using the phone. # write_to_file( str(1), "/var/run/rild.pid") def rild_pid(): # Shared code: belongs_to_rild = lambda fn: contents_of( fn).startswith("/system/bin/rild") try: last_known_pid = int( contents_of("/var/run/rild.pid") ) except IOError: last_known_pid = 1 # If rild no longer has a process ID of last_known_pid: if not belongs_to_rild("/proc/%i/cmdline"%last_known_pid): # find rild: for fn in glob("/proc/*/cmdline"): if belongs_to_rild( fn): last_known_pid = int( fn.split("/")[2] ) write_to_file( str(last_known_pid), "/var/run/rild.pid")