def delete_query(self, name): if self.queries.has_key(name): q = self.queries[name] self.tree.remove_item(q[1]) del self.queries[name] else: debug(ERROR, "Attempt to remove non existing query %s" % name)
def prepareJob(self): if DEBUG: debug.debug( "Preparing the object; setting up the connection to the credential manager. Account: " + str(self.accountid)) self.c = rpyc.connect("localhost", 65123) self.pyteslaobj = self.c.root.getLoginToken(self.accountid)
def handle(self): data, sock = self.request DNSrequest = Message(data) #一条正向查询请求 if DNSrequest.header.QR == 0 and DNSrequest.header.Opcode == 0 and DNSrequest.questions[ 0].QTYPE == 1: #处理questions #检查请求的域名合法性 Rtype = self._chech_request(DNSrequest, DNSServer.hosts) # 构造返回包 response = Response(Rtype, DNSrequest, DNSServer.hosts, DNSServer.addr) # 发送返回信息 sock.sendto(response.get_response(), self.client_address) # 输出调试信息 debug(self.client_address, DNSrequest, response, DNSServer.debugMode) #非查询请求,返回错误信息 else: Rtype = 0 # 构造返回包 response = Response(Rtype, DNSrequest, DNSServer.hosts, DNSServer.addr) #发送返回信息 sock.sendto(response.get_response(), self.client_address)
def runjob(self, account): # Running the job at hand :) if DEBUG: debug.debug("Running the job for account: " + str(account.accountid)) print account account.runJob()
def deluser(self, name): for i in self.items: if lower(i[0]) == lower(name): self.items.remove(i) self.list.remove_items([i[1]]) return i debug(ERROR, "USER %s NOT FOUND IN" % name) debug(ERROR, self.items)
def deluser(self, nick): self.list.deluser(nick) if self.treeitems.has_key(nick): self.tree.remove_item(self.treeitems[nick]) del self.treeitems[nick] else: debug(ERROR, "Attempting to remove missing user %s from channel " \ "%s from tree" % (nick, self.name))
def delete_channel(self, name): if self.channels.has_key(name): c = self.channels[name] self.tree.remove_item(c[1]) del self.channels[name] # close window, etc? else: debug(ERROR, "Attempt to remove non existing channel %s" % name)
def exposed_getLoginToken(self, accountid, cartype="Tesla"): dbobject = database.Database() credentials = dbobject.getCredentials(accountid, cartype) debug.debug( "Got the credentials, logging in and returning object") if cartype == "Tesla": debug.debug( "here we go for Tesla") return pytesla.Connection(credentials[0], credentials[1]) else: return "Something else"
def exposed_getLoginToken(self, accountid, cartype="Tesla"): dbobject = database.Database() credentials = dbobject.getCredentials(accountid, cartype) debug.debug("Got the credentials, logging in and returning object") if cartype == "Tesla": debug.debug("here we go for Tesla") return pytesla.Connection(credentials[0], credentials[1]) else: return "Something else"
def startAllAccounts(self): if DEBUG: debug.debug("Starting all the accounts. We append a runJob and a runMetaJob to the scheduler") for account in self.accounts: if not account.running: # We schedule the task account.prepareJob() account.runMetaJob() self.jobs.append (self.sched.add_interval_job( self.runjob, args=[account], seconds= int(account.updateinterval)) ) self.metajobs.append( self.sched.add_interval_job (self.runMetajob, args=[account], minutes= 30) ) account.running = True
def tree_handler(self, item, event, name): """ handles events (button clicks) on items in our delegated part of the tree widget """ if name == "<messages>": self.get_msgwin().raisewin() elif self.channels.has_key(name): self.channels[name][0].raisewin() elif self.queries.has_key(name): self.queries[name][0].raisewin() else: debug(ERROR, "Received GtkTreeItem event for %s" % name)
def reset(self): path = self.cfg("logging.log_base") if os.path.isdir(path): if sys.platform[:4] == 'java': import java if java.io.File(path).canWrite(): self.disabled = 0 else: self.disabled = 1 elif os.access(path, os.W_OK): self.disabled = 0 else: self.disabled = 1 debug(ERROR, "%s is not a writable directory - logging disabled" % path) else: self.disabled = 1 debug(ERROR, "%s is not a directory - logging disabled" % path)
def __init__(self): if DEBUG: debug.debug("Loading logger") #self.databasehandler = databasehandler.DatabaseHandler(self) self.logger = logger.Logger(self) if DEBUG: debug.debug("Loading complete") debug.debug("Starting the schedule manager") self.schedulemanager = schedulemanager.ScheduleManager(self) if DEBUG: debug.debug("Schedule managr is loading, resorting to loop to keep the process alive")
def startAllAccounts(self): if DEBUG: debug.debug( "Starting all the accounts. We append a runJob and a runMetaJob to the scheduler" ) for account in self.accounts: if not account.running: # We schedule the task account.prepareJob() account.runMetaJob() self.jobs.append( self.sched.add_interval_job(self.runjob, args=[account], seconds=int( account.updateinterval))) self.metajobs.append( self.sched.add_interval_job(self.runMetajob, args=[account], minutes=30)) account.running = True
def attach_detach(self, win): ctr = win.get_container() if win.state == nestable.STATE_WINDOW: # windowed debug(DEBUG, "Moving %s from window to tab" % win.name) container = GtkVBox() self.tabmap[container] = win l = GtkLabel(win.name) l.set_name("label") l.show() win.nestTab(self.tabs, container, l) self.tabs.append_page(container, l) container.show() self.count = self.count + 1 else: # tabbed if len(self.tabs.children()) == 1: return 1 debug(DEBUG, "Moving %s from tab to window" % win.name) outer = win.get_outer_container() del self.tabmap[outer] win.nestWindow()
def view_winclose(self, source, target): if target == None: self.viewtext.close_msgwin() elif self.channels.has_key(target): # if we're active on the channel, part it which will indirectly # cause the window to close. c = self.serverState.getChannel(target) if c and (c.getstate() == model.channel.STATE_ACTIVE): self.irc.part(target) else: # we're not active - remove the window self.channels[target].destroy() del self.channels[target] self.viewtext.delete_channel(target) elif self.queries.has_key(target): # queries can be destroyed self.queries[target].destroy() del self.queries[target] self.viewtext.delete_query(target) else: debug(ERROR, "Received WIN_CLOSE event for unknown" \ "window: %s" % target)
def authenticatorMethod(sock): debug.debug( "got something!!") debug.debug(sock) data = sock.recv(10) debug.debug( data) if data != "0123456789": raise AuthenticationError("wrong secret") return sock, None
def authenticatorMethod(sock): debug.debug("got something!!") debug.debug(sock) data = sock.recv(10) debug.debug(data) if data != "0123456789": raise AuthenticationError("wrong secret") return sock, None
def __init__(self, parent): self.parent = parent self.accounts = [] self.jobs = [] self.metajobs = [] #self.createCarObjects() if DEBUG: debug.debug("Starting the scheduler object") self.sched = Scheduler() if DEBUG: debug.debug("Creating all the required objects from our database") self.createCarObjects() if DEBUG: debug.debug("Automate the previous creation on a 5 minute basis") self.sched.add_interval_job(self.createCarObjects, minutes=5) if DEBUG: debug.debug("Start the scheduler!") self.sched.start()
def connectionFailed(self): debug(DEBUG, "ERROR RECEIVED") self.viewtext.announce("Connection failed: %s" % self.irc.errstr) self.reset()
def connectionLost(self): debug(DEBUG, "ERROR RECEIVED") self.viewtext.announce("Connection lost: %s" % self.irc.errstr) self.reset()
def getDatabaseHandler(self): #return self.databasehandler if DEBUG: debug.debug("Returning new database object") return databasehandler.DatabaseHandler(self)
def runMetajob(self, account): # Running a different job, the meta one if DEBUG: debug.debug("Running the metajob for account: " + str(account.accountid)) account.runMetaJob()
def meta_close(self, source, text): debug.debug(debug.DEBUG, "QUIT") for c in self.controllers: c.quit(text) debug.debug(debug.DEBUG, "ALL CONNECTIONS HAVE QUIT") self.view.mainquit()
def runJob(self): #log("Running interval job") if DEBUG: debug.debug("Running the interval job for account: " + str(self.accountid)) for vehicle in self.pyteslaobj.vehicles(): # Charge states try: charge_state_data = vehicle.charge_state self.dbhandler.executeQueryNoResult( "INSERT INTO ChargeStates (carid, charging_state, charge_limit_soc, charge_limit_soc_std, charge_limit_soc_min, charge_limit_soc_max, charge_to_max_range, battery_heater_on, not_enough_power_to_heat, max_range_charge_counter, fast_charger_present, battery_range, est_battery_range, ideal_battery_range, battery_level, battery_current, charge_energy_added, charge_miles_added_rated, charge_miles_added_ideal, charger_voltage, charger_pilot_current, charger_actual_current, charger_power, time_to_full_charge, charge_rate, charge_port_door_open, scheduled_charging_start_time, scheduled_charging_pending, user_charge_enable_request, charge_enable_request, updated) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (self.vehicleid, charge_state_data["charging_state"], charge_state_data["charge_limit_soc"], charge_state_data["charge_limit_soc_std"], charge_state_data["charge_limit_soc_min"], charge_state_data["charge_limit_soc_max"], charge_state_data["charge_to_max_range"], charge_state_data["battery_heater_on"], charge_state_data["not_enough_power_to_heat"], charge_state_data["max_range_charge_counter"], charge_state_data["fast_charger_present"], charge_state_data["battery_range"], charge_state_data["est_battery_range"], charge_state_data["ideal_battery_range"], charge_state_data["battery_level"], charge_state_data["battery_current"], charge_state_data["charge_energy_added"], charge_state_data["charge_miles_added_rated"], charge_state_data["charge_miles_added_ideal"], charge_state_data["charger_voltage"], charge_state_data["charger_pilot_current"], charge_state_data["charger_actual_current"], charge_state_data["charger_power"], charge_state_data["time_to_full_charge"], charge_state_data["charge_rate"], charge_state_data["charge_port_door_open"], charge_state_data["scheduled_charging_start_time"], charge_state_data["scheduled_charging_start_time"], charge_state_data["scheduled_charging_pending"], charge_state_data["user_charge_enable_request"], int(time.time())), commit=True) except: if DEBUG: debug.debug( "!!!Failed to fetch the charging data for account " + str(self.accountid) + " and vehicle " + str(self.vehicleid) + ". See error printing below!!!") exc_type, exc_value, exc_traceback = sys.exc_info() print "*** Traceback ***" traceback.print_tb(exc_traceback, file=sys.stdout) print "*** Exception ***" traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) print "*** Traceback exc ***" traceback.print_exc() print "*** format_exc, first and last line ***" formatted_lines = traceback.format_exc().splitlines() print formatted_lines[0] print formatted_lines[-1] print "*** format_exception ***" print repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print "*** extract_tb ***" print repr(traceback.extract_tb(exc_traceback)) print "*** format_tb ***" print repr(traceback.format_tb(exc_traceback)) print "*** tb_lineno ***", exc_traceback.tb_lineno # Drive states try: drive_state_data = vehicle.drive_state self.dbhandler.executeQueryNoResult( "INSERT INTO DriveStates (carid, shift_state, speed, latitude, longitude, heading, gps_as_of, updated) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)", (self.vehicleid, drive_state_data["shift_state"], drive_state_data["speed"], drive_state_data["latitude"], drive_state_data["longitude"], drive_state_data["heading"], drive_state_data["gps_as_of"], int(time.time())), commit=True) except: if DEBUG: debug.debug( "!!!Failed to fetch the drive data for account " + str(self.accountid) + " and vehicle " + str(self.vehicleid) + ". See error printing below!!!") exc_type, exc_value, exc_traceback = sys.exc_info() print "*** Traceback ***" traceback.print_tb(exc_traceback, file=sys.stdout) print "*** Exception ***" traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) print "*** Traceback exc ***" traceback.print_exc() print "*** format_exc, first and last line ***" formatted_lines = traceback.format_exc().splitlines() print formatted_lines[0] print formatted_lines[-1] print "*** format_exception ***" print repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print "*** extract_tb ***" print repr(traceback.extract_tb(exc_traceback)) print "*** format_tb ***" print repr(traceback.format_tb(exc_traceback))
def on_connect(self): debug.debug("Welkom")
def irc_unknown(self, command, prefix, args): debug(ERROR, "Could not handle <%s %s %s>" % (command, prefix, args)) self.viewtext.insert("%s %s %s" % (prefix, command, join(args)))
def runMetaJob(self): # Meta job, meta data #log( "Running Meta Job") for vehicle in self.pyteslaobj.vehicles(): carid = vehicle.id vinnumber = vehicle.vin try: carmobile = vehicle.mobile_enabled except: #ZZZZZzzzzzzZZZZZ time.sleep(60) try: carmobile = vehicle.mobile_enabled except: # log this!! break vehicleid = self.dbhandler.executeQuery( "SELECT id from vehicles WHERE carid=%s and vinnumber=%s and accountid=%s", (carid, vinnumber, self.accountid)) if vehicleid == None: # Add it self.dbhandler.executeQueryNoResult( "INSERT INTO vehicles (carid, vinnumber, accountid, mobile_enabled, updated, brandid, typeid, countryid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", (carid, vinnumber, self.accountid, carmobile, int(time.time()), 1, 1, 1), commit=True) vehicleid = self.dbhandler.executeQuery( "SELECT id from vehicles WHERE carid=%s and vinnumber=%s and accountid = %s", (carid, vinnumber, self.accountid)) else: self.dbhandler.executeQueryNoResult( "UPDATE vehicles SET mobile_enabled=%s and updated=%s", (carmobile, int(time.time()))) # For later use self.vehicleid = vehicleid[0][0] try: climate_state_data = vehicle.climate_state climateid = self.dbhandler.executeQuery( "SELECT id FROM ClimateStates WHERE carid=%s", (vehicleid[0][0])) if climateid == None: # Insert self.dbhandler.executeQueryNoResult( "INSERT INTO ClimateStates (carid, inside_temp, outside_temp, driver_temp_settings, passenger_temp_setting, is_auto_conditioning_on, is_front_defroster_on, is_rear_defroster_on, fan_status, updated) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (vehicleid[0][0], climate_state_data["inside_temp"], climate_state_data["outside_temp"], climate_state_data["driver_temp_setting"], climate_state_data["passenger_temp_setting"], climate_state_data["is_auto_conditioning_on"], climate_state_data["is_front_defroster_on"], climate_state_data["is_rear_defroster_on"], climate_state_data["fan_status"], int(time.time())), commit=True) else: # Update self.dbhandler.executeQueryNoResult( "UPDATE ClimateStates SET inside_temp=%s, outside_temp=%s, driver_temp_setting=%s, passenger_temp_setting=%s, is_auto_conditioning_on=%s, is_front_defroster_on=%s, is_rear_defroster_on=%s, fan_status=%s, updated=%s WHERE id=%s", (climate_state_data["inside_temp"], climate_state_data["outside_temp"], climate_state_data["driver_temp_setting"], climate_state_data["passenger_temp_setting"], climate_state_data["is_auto_conditioning_on"], climate_state_data["is_front_defroster_on"], climate_state_data["is_rear_defroster_on"], climate_state_data["fan_status"], int( time.time()), climateid[0][0]), commit=True) except: if DEBUG: debug.debug( "!!!Failed to fetch the climate data for account " + str(self.accountid) + " and vehicle " + str(vehicleid[0][0]) + ". See error printing below!!!") exc_type, exc_value, exc_traceback = sys.exc_info() print "*** Traceback ***" traceback.print_tb(exc_traceback, file=sys.stdout) print "*** Exception ***" traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) print "*** Traceback exc ***" traceback.print_exc() print "*** format_exc, first and last line ***" formatted_lines = traceback.format_exc().splitlines() print formatted_lines[0] print formatted_lines[-1] print "*** format_exception ***" print repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print "*** extract_tb ***" print repr(traceback.extract_tb(exc_traceback)) print "*** format_tb ***" print repr(traceback.format_tb(exc_traceback)) # Climate information added # Gui states try: gui_settings_data = vehicle.gui_settings guisettingsid = self.dbhandler.executeQuery( "SELECT id FROM GUISettings WHERE carid=%s", (vehicleid[0][0])) if guisettingsid == None: # Adding self.dbhandler.executeQueryNoResult( "INSERT INTO GUISettings (carid, gui_distance_units, gui_temperature_units, gui_charge_rate_units, gui_24_hour_time, gui_range_display, updated) VALUES (%s,%s,%s,%s,%s,%s,%s)", (int(vehicleid[0][0]), gui_settings_data["gui_distance_units"], gui_settings_data["gui_temperature_units"], gui_settings_data["gui_charge_rate_units"], gui_settings_data["gui_24_hour_time"], gui_settings_data["gui_range_display"], int(time.time())), commit=True) else: # Update self.dbhandler.executeQueryNoResult( "UPDATE GUISettings SET gui_distance_units=%s, gui_temperature_units=%s, gui_charge_rate_units=%s, gui_24_hour_time=%s, gui_range_display=%s, updated=%s WHERE id=%s", (gui_settings_data["gui_distance_units"], gui_settings_data["gui_temperature_units"], gui_settings_data["gui_charge_rate_units"], gui_settings_data["gui_24_hour_time"], gui_settings_data["gui_range_display"], int(time.time()), guisettingsid[0][0]), commit=True) except: if DEBUG: debug.debug( "!!!Failed to fetch the GUI data for account " + str(self.accountid) + " and vehicle " + str(vehicleid[0][0]) + ". See error printing below!!!") exc_type, exc_value, exc_traceback = sys.exc_info() print "*** Traceback ***" traceback.print_tb(exc_traceback, file=sys.stdout) print "*** Exception ***" traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) print "*** Traceback exc ***" traceback.print_exc() print "*** format_exc, first and last line ***" formatted_lines = traceback.format_exc().splitlines() print formatted_lines[0] print formatted_lines[-1] print "*** format_exception ***" print repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print "*** extract_tb ***" print repr(traceback.extract_tb(exc_traceback)) print "*** format_tb ***" print repr(traceback.format_tb(exc_traceback)) # GUI data added # Last of the static: vehicle data try: vehicle_state_data = vehicle.vehicle_state vehiclestateid = self.dbhandler.executeQuery( "SELECT id FROM VehicleStates WHERE carid=%s", (vehicleid[0][0])) if vehiclestateid == None: # Insert self.dbhandler.executeQueryNoResult( "INSERT INTO VehicleStates (carid, df, dr, pf, ft, rt, car_version, locked, sun_roof_installed, sun_roof_state, sun_roof_percent_open, dark_rims, wheel_type, has_spoiler, roof_color, perf_config, exterior_color, updated) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (vehicleid[0][0], vehicle_state_data["df"], vehicle_state_data["dr"], vehicle_state_data["pf"], vehicle_state_data["ft"], vehicle_state_data["rt"], vehicle_state_data["car_version"], vehicle_state_data["locked"], vehicle_state_data["sun_roof_installed"], vehicle_state_data["sun_roof_state"], vehicle_state_data["sun_roof_percent_open"], vehicle_state_data["dark_rims"], vehicle_state_data["wheel_type"], vehicle_state_data["has_spoiler"], vehicle_state_data["roof_color"], vehicle_state_data["perf_config"], vehicle_state_data["exterior_color"], int( time.time())), commit=True) else: # Update self.dbhandler.executeQueryNoResult( "UPDATE VehicleStates SET df=%s,dr=%s, pf=%s, ft=%s, rt=%s, car_version=%s, locked=%s, sun_roof_installed=%s, sun_roof_state=%s, sun_roof_percent_open=%s, dark_rims=%s, wheel_type=%s, has_spoiler=%s, roof_color=%s, perf_config=%s, exterior_color=%s, updated=%s WHERE id=%s", (vehicle_state_data["df"], vehicle_state_data["dr"], vehicle_state_data["pf"], vehicle_state_data["ft"], vehicle_state_data["rt"], vehicle_state_data["car_version"], vehicle_state_data["locked"], vehicle_state_data["sun_roof_installed"], vehicle_state_data["sun_roof_state"], vehicle_state_data["sun_roof_percent_open"], vehicle_state_data["dark_rims"], vehicle_state_data["wheel_type"], vehicle_state_data["has_spoiler"], vehicle_state_data["roof_color"], vehicle_state_data["perf_config"], vehicle_state_data["exterior_color"], int( time.time()), int(vehicleid[0][0])), commit=True) except: if DEBUG: debug.debug( "!!!Failed to fetch the vehicle state data for account " + str(self.accountid) + " and vehicle " + str(vehicleid[0][0]) + ". See error printing below!!!") exc_type, exc_value, exc_traceback = sys.exc_info() print "*** Traceback ***" traceback.print_tb(exc_traceback, file=sys.stdout) print "*** Exception ***" traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) print "*** Traceback exc ***" traceback.print_exc() print "*** format_exc, first and last line ***" formatted_lines = traceback.format_exc().splitlines() print formatted_lines[0] print formatted_lines[-1] print "*** format_exception ***" print repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print "*** extract_tb ***" print repr(traceback.extract_tb(exc_traceback)) print "*** format_tb ***" print repr(traceback.format_tb(exc_traceback))
def on_disconnect(self): debug.debug( "Bye!")
def nickchange(self, old, new): debug(DEBUG, "Nickchange: %s -> %s" % (old, new)) item = self.deluser(old) return self.adduser(new, item[2])
def on_connect(self): debug.debug( "Welkom")
self.logger = logger.Logger(self) if DEBUG: debug.debug("Loading complete") debug.debug("Starting the schedule manager") self.schedulemanager = schedulemanager.ScheduleManager(self) if DEBUG: debug.debug("Schedule managr is loading, resorting to loop to keep the process alive") def getDatabaseHandler(self): #return self.databasehandler if DEBUG: debug.debug("Returning new database object") return databasehandler.DatabaseHandler(self) def log(self, msg): self.logger.log(msg) if __name__ == "__main__": if DEBUG: debug.debug("Starting the dataDaemon") dd = dataDaemon() while True: time.sleep(2) # We need this if DEBUG: pass #debug.debug( "Still running")
def delete_channel(self, name): if self.channels.has_key(name): c = self.channels[name] del self.channels[name] else: debug(ERROR, "Attempt to remove non existing channel %s" % name)
def on_disconnect(self): debug.debug("Bye!")