def upload(pnum, pind, ffiles, fpieces, fbytes, buf): piece = tor.pieces[pind] url = piece.upload_url try: r = js._session.post(url=url, params={"api_key" : js._api_key}, files={'piece_file' : ("piece_file", buf) } ) r.raise_for_status() bs = ET.fromstring(r.content) log(DEBUG3, "issueAPIRequest: node %r" % bs) status = bs.find("status") log(DEBUG2, "status=%r" % status) if status is None: raise APIError("%s protocol failure!"% url) if status.text != "SUCCESS": m = bs.find("message") h = bs.find("info_hash") if h is not None and m is not None: raise APIError("%s failed: %s (info_hash=%s)!"% (url, unicode(urllib.unquote(m.text)), unicode(urllib.unquote(h.text)))) elif m is not None: raise APIError("%s failed: %s!"% (url, unicode(urllib.unquote(m.text)))) else: raise APIError("%s failed!"% url) except Exception, e: print "Caught %s uploading piece %d, aborting" % (e, pind)
def setcheckProgress(self, tor, npieces, piecesChecked, downloadedFiles, downloadedPieces, downloadedBytes): log(DEBUG3) tor.checkProgress = piecesChecked / float(npieces) tor.checkPieces = downloadedPieces tor.checkPercentage = downloadedBytes / float(tor.size) return self._quitPending
def delete(self): log(DEBUG) self._torrent.delete() if self._aria: self._aria.delete()
def updatePeers(self, force = False): if time.time() < self._peersValidUntil and not force: return log(DEBUG) try: bs = issueAPIRequest(self._jsit(), "/torrent/peers.csp", params = {"info_hash" : self._hash}) fieldmap = {"direction" : "direction", "ip_address" : "ip_address", "peer_id" : "peer_id", "percentage_as_decimal" : "percentage", "port" : "port" } self._peers = [] for r in bs.find_all("row"): t = TPeer(self) fillFromXML(t, r, fieldmap) t.cleanupFields() self._peers.append(t) self._peersValidUntil = time.time() + peerValidityLength except Exception,e : log(ERROR, u"Caught exception %s updating peers for torrent %s!\n" % (e, self._name))
def markMsgRead(self, message_num): # unpack the seen cookie seencookiename = "%s.WR" % self.listname seencookie = self.ncgi.hdf.getValue("Cookie.%s" % seencookiename, "") if seencookie: c_parts = string.split(seencookie,",") else: c_parts = [] mnum_str = "%s" % message_num try: index = c_parts.remove(mnum_str) log("already seen in cookie: %s" % message_num) except ValueError: log("markread: %s" % message_num) # yes, it's new! # make a new seen cookie! (only 200 entries) c_parts.insert(0,mnum_str) new_seencookie = string.join(c_parts[:200],",") self.ncgi.cookieSet(seencookiename,new_seencookie,persist=1) # add to whichread DB self.addToDB(message_num) # append to whichread log fp = open("%s/whichreadchanges.log" % self._path,"ab+") fp.write("%s %s\n" % (self._whichReadID,mnum_str)) fp.close()
def isonlineServers(self): log(" *** isonlineServers()", 'debug') cur_time = time.strftime("%Y-%m-%d - %H:%M.%S") output = " {0}\n NETWORK MONITOR\n {1}\n {0}\n\n[SERVERS]\n".format('-'*21, cur_time) q = queue.Queue() for server in self.servers: p = Async_ping(q, server, self.margin) p.run() q.put(p) output += p.output + '\n' log(p.server + ': ' + p.status, p.loglevel) if self.host: website_status = self.isonlineWebsite() output += website_status if self.mailsent: output += ' :) Mail sent at {0} because:\n "{1}" was offline with error {2}.'.format( self.mailsent_time, self.host, self._website_error) elif self.mailsent == False: output += ' :( Could not send email at {0}, error {1}\n (Website error was: {2})'.format( self.mailsent_time, self.mail_error, self._website_error) for i in range(1,self.polling): os.system("cls") next_in = "\n\n\n\n ===========\n Next in: {0} \n ===========\n {1}".format( str(self.polling-i), self.__repr__()) print(output + next_in) time.sleep(1)
def stringsHDF(self, prefix, locations, lang='en', exist=0, tiered=0): hdf = neo_util.HDF() if exist and lang == 'en': return hdf done = {} locations.sort() maps = self.tdb.maps.fetchRows( ('lang', lang) ) maps_d = {} for map in maps: maps_d[int(map.string_id)] = map strings = self.tdb.strings.fetchRows() strings_d = {} for string in strings: strings_d[int(string.string_id)] = string count = 0 for loc in locations: s_id = int(loc.string_id) if done.has_key(s_id): continue try: s_row = maps_d[s_id] if exist: continue except KeyError: try: s_row = strings_d[s_id] except KeyError: log("Missing string_id %d, skipping" % s_id) continue count = count + 1 if tiered: hdf.setValue("%s.%d.%d.%s" % (prefix, int(s_id) / TIER1_DIV, int(s_id) / TIER2_DIV, s_id), s_row.string) else: hdf.setValue("%s.%s" % (prefix, s_id), s_row.string) done[s_id] = 1 if exist == 1: log("Missing %d strings for lang %s" % (count, lang)) return hdf
def sendmail(BOUNCE_RETURN_ADDRESS,TO_ADDRESS_LIST,BODY): global DISABLED if DISABLED: log ("Not sending to %s" % repr(TO_ADDRESS_LIST)) return try: mod_to_list = [] for address in TO_ADDRESS_LIST: mod_to_list.append(shell_escape(address)) mod_bounce_address = shell_escape(BOUNCE_RETURN_ADDRESS) cmd = "/usr/lib/sendmail -oi -f'%s' -- %s" % (mod_bounce_address, string.join(mod_to_list, ' ')) fp = os.popen(cmd, "w", 16384) fp.write(BODY) r = fp.close() if not r: return if os.WIFEXITED(r): if os.WEXITSTATUS(r): raise "cmd '%s' returned %d" % (cmd, os.WEXITSTATUS(r)) elif os.WIFSIGNALED(r): raise "cmd '%s' ended on signal %d" % (cmd, os.WTERMSIG(r)) elif os.WIFSTOPPED(r): raise "cmd '%s' ended on signal %d" % (cmd, os.WSTOPSIG(r)) except IOError: delayed_queue(BOUNCE_RETURN_ADDRESS, TO_ADDRESS_LIST, BODY) except: import handle_error handle_error.handleException("Unable to send message") delayed_queue(BOUNCE_RETURN_ADDRESS, TO_ADDRESS_LIST, BODY)
def __init__(self, cleanupLeftovers = False, port = 6800, private = False): log(DEBUG, "Starting aria process...\n"); # Start aria process self._username = "******" + str(random.randint(0,100000)) * private self._password = "******" + str(random.randint(0,100000)) * private self._proc = subprocess.Popen(["aria2c", "--enable-rpc=true", "--rpc-user="******"--rpc-passwd="+self._password, "--rpc-listen-port=%d" % port], stdout=subprocess.PIPE) self._server = xmlrpclib.ServerProxy('http://%s:%s@localhost:%d/rpc' % (self._username, self._password, port)) socket.setdefaulttimeout(5) # Do a quick timeout to catch problems # wait for server to start up running = False while not running: try: self._server.aria2.tellActive() running = True except IOError: time.sleep(0.2) except xmlrpclib.ProtocolError, e: log(ERROR, u"Couldn't connect to aria process. Is an old one still running? Aborting...\n") raise e
def test_setup(self): ndb = self.ndb # feed in machines t1 = ndb.machines.getMachine("t1") t4 = ndb.machines.getMachine("t4") t5 = ndb.machines.getMachine("t5") # set machine roles... allroles = ndb.roles.fetchAllRows() if not allroles: role = ndb.roles.newRow() role.name = "testrole" role.is_shared=1 role.save() allroles = [role] for a_role in allroles: ndb.mach_roles.addMachineRole(t1,a_role) ndb.mach_roles.addMachineRole(t4,a_role) ndb.mach_roles.addMachineRole(t5,a_role) # create role triggers cur_triggers = ndb.role_triggers.fetchRows( ('role_id', a_role.role_id) ) if not cur_triggers: ntrigger = ndb.role_triggers.newRow() ntrigger.role_id = a_role.role_id serv_for_trig = ndb.services.getService("disk/size:cur") log("serv_for_trig: %s" % serv_for_trig.serv_id) ntrigger.serv_id = serv_for_trig.serv_id ntrigger.level = "1" ntrigger.source_pattern = "sda1" ntrigger.save()
def percentage(self): # This can happen if everything has been downloaded already. if len(self._gids) == 0: return 100. total = 0. completed = 0. # Use multicall to reduce pressure on aria2 mc = xmlrpclib.MultiCall(self._aria()._server) for g in self._gids: mc.aria2.tellStatus(g, ["completedLength", "totalLength"]) res = mc() for i,s in enumerate(res): log(DEBUG2, "%s: total=%s completed=%s\n" % (self._gids[i], s["totalLength"], s["completedLength"])) total += int(s["totalLength"]) completed += int(s["completedLength"]) # Do we know the full size a priory? if self._fullsize: total = self._fullsize completed += self._finishedBytes # Add completed a priori parts # This can happen at startup, before any sizes are known if total == 0: return 0 # Make sure we return 100 for completion. Float math is tricky. if total == completed: return 100. return completed * 100. / total
def computeTrendTime_Linear(self,serv_id,source_id,target): # 0. load data h_data = self.ndb.monitor_history.fetchRows( [ ('serv_id', serv_id), ('source_id', source_id)] ) # we have to have data to compute trends! if len(h_data) < 10: return -1 coeff = self._linCoeff(h_data) def lin_f(x,par): m,b = par return (m*x) + b def lin_fsolve(y,par): m,b = par return (y-b) / m b,m = coeff values = m,b try: at = lin_fsolve(float(target),values) time_to_target = (at - time.time()) log("time_to_target = " + str(time_to_target)) except ZeroDivisionError: time_to_target = -1 return time_to_target
def main(argv, stdout, environ): progname = argv[0] optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug"]) testflag = 0 if len(args) != 0: usage(progname) return lock = do_lock(DISCUSS_DATA_ROOT, "archiver.lock") global DONE #signal.signal(signal.SIGTERM, handleSignal) log("archiver: start") try: while not DONE: try: archive_dirs() except: handle_error.handleException("Archiver Error") if DONE: break # tlog("sleeping") time.sleep(10) finally: os.unlink(os.path.join(DISCUSS_DATA_ROOT, "archiver.lock"))
def log (self, level = None, msg = None): if msg is None: msg = self.message if level is None: level = self.level log (self.__class__.__module__, level, msg)
def loadMap(self, file, prefix, lang): log("Loading map for language %s" % lang) hdf = neo_util.HDF() hdf.readFile(file) obj = hdf.getChild(prefix) updates = 0 new_r = 0 while obj is not None: s_id = obj.name() str = obj.value() try: map_r = self.tdb.maps.fetchRow( [('string_id', s_id), ('lang', lang)]) except odb.eNoMatchingRows: map_r = self.tdb.maps.newRow() map_r.string_id = s_id map_r.lang = lang new_r = new_r + 1 if map_r.string != str: updates = updates + 1 map_r.string = str map_r.save() obj = obj.next() log("New maps: %d Updates: %d" % (new_r, updates - new_r))
def start(self): SHOULD_DISPLAY = 1 if self._israwpage: SHOULD_DISPLAY = 0 ncgi = self.ncgi if self.readDefaultHDF: try: if not self.pagename is None: ncgi.hdf.readFile("%s.hdf" % self.pagename) except: log("Error reading HDF file: %s.hdf" % (self.pagename)) DISPLAY_ERROR = 0 ERROR_MESSAGE = "" # call page main function! try: self.main() except DisplayDone: SHOULD_DISPLAY = 0 except Redirected: # catch redirect exceptions SHOULD_DISPLAY = 0 except DisplayError, num: ncgi.hdf.setValue("Query.error", str(num)) if self._error_template: ncgi.hdf.setValue("Content", self._error_template) else: DISPLAY_ERROR = 1
def geocode_by_semantics(project, address, port): from pymongo import MongoClient client = MongoClient(address, port) db = client[project] search_json = {'$or': [{'latlng': [0, 0]}, {'latlng': [-1, -1]}], 'verified': True} users = db.users.find(search_json) count = db.users.find(search_json).count() print count i = 0 for user in users: i += 1 verified_info = user['verified_info'] username = user['username'] verified_info = verified_info.replace(u'主持人', '').replace(u'职员', '').replace(u'院长', '').replace(u'经理', '') verified_info = verified_info.split(u' ')[0] if verified_info == u'前' or u'www' in verified_info or u'律师' in verified_info or u'学者' in verified_info or u'作家' in verified_info or u'媒体人' in verified_info or u'诗人' in verified_info: verified_info = '' locational_info = verified_info if locational_info == '': locational_info = username if verified_info != '': latlng = geocode(verified_info) else: continue log(NOTICE, '#%d geocode the user by its semantic info %s. %d posts remain. latlng: %s ' % (i, verified_info.encode('gbk', 'ignore'), count - i, str(latlng))) if latlng[0] != -1 and latlng[0] != 0: db.users.update({'userid': user['userid']}, {'$set': {'latlng': latlng}}) log(NOTICE, "mission compeletes.")
def piecePriority(self, p): prio = self.priority + (1. / math.log10(max(self._size - self.downloadedBytes, 0) + 10)) * 1000 if self._pdl().hasServerFailed(p.url): prio -= 10000000 log(DEBUG2, "%s (%s) self._size=%d self.downloadedBytes=%d prio=%f" % (self._jtorrent().name, p, self._size, self.downloadedBytes, prio)) return prio
def fixbody(raw_body): log("-- fixbody") # FIX #1: reassemble broken URLs def fixurl(m): log("matched url: %s" % m.group(0)) result = re.sub(" ?[\r\n]","",m.group(0)) log("fixed url: %s" % result) return result raw_body = re.sub("[a-z]+://\S+" "(" "(" "(/ ?\r?\n(?![a-z]{0,7}://))" "|" "( ?\r?\n/)" "|" "(- ?\r?\n)" ")+" "\S+)+" "(?= ?\r?\n]>\\))", fixurl,raw_body) raw_body = re.sub("[a-z]+://\S+( ?\r?\n(?![a-z]{0,7}://)\S+)+",fixurl,raw_body) # FIX #2: space pad URLs which are surrounded by (), <> or [] raw_body = re.sub("([<([])([a-z]+://[^ ]+)([>)\\]])","\\1 \\2 \\3",raw_body) # FIX #3: remove Yahoo! Groups ad chunks # done with fixes return raw_body
def hasChildren(self, parent): if parent and not parent.isValid(): log(DEBUG4, "yes") return True else: log(DEBUG4, "no") return False
def data(self, index, role): if not index.isValid(): return None tc = torrent_colums[index.column()] if role == Qt.TextAlignmentRole: try: return tc["align"] except KeyError: return 0x82 # Qt.AlignRight | Qt.AlignVCenter doesn't work if role == Qt.DisplayRole or role == Qt.EditRole: v = tc["acc"](self.mgr[index.row()], tc["vname"]) if role == Qt.DisplayRole: try: v = tc["map"](v) except KeyError: pass log(DEBUG2, "v=%s\n" % v) return v return None
def stop(self): log(DEBUG) self._torrent.stop() if self._aria: self._aria.stop()
def addTorrentFiles(self): log(INFO) fns,ftype = QFileDialog.getOpenFileNames(self, "Open Torrent File", "", "Torrent Files (*.torrent)") for fn in fns: tor = self.mgr.addTorrentFile(fn, basedir=pref("downloads", "basedir", "downloads"), unquoteNames=pref("downloads", "unquoteNames", True), interpretDirectories=pref("downloads", "interpretDirectories", True))
def updateTrackers(self, force = False): if time.time() < self._trackersValidUntil and not force: return log(DEBUG) try: bs = issueAPIRequest(self._jsit(), "/torrent/trackers.csp", params = {"info_hash" : self._hash}) fieldmap = { "downloaded": "downloaded", "interval": "interval", "last_announce": "last_announce", "leechers": "leechers", "seeders": "seeders", "peers": "peers", "url": "url", "message": "message" } self._trackers = [] for r in bs.find_all("row"): t = TTracker(self) fillFromXML(t, r, fieldmap) t.cleanupFields() self._trackers.append(t) self._trackersValidUntil = time.time() + trackerValidityLength except IOError,e : log(ERROR, u"Caught exception %s updating trackers for torrent %s!\n" % (e, self._name))
def connect(self): log(DEBUG, "Starting aria process...") try: self._proc = subprocess.Popen( [ "aria2c", "--enable-rpc=true", "--rpc-user="******"--rpc-passwd=" + self._password, "--rpc-listen-port=%d" % self._port, ], stdout=subprocess.PIPE, ) except OSError: raise AriaError("Couldn't start aria, is it installed and in your PATH?") self._server = xmlrpclib.ServerProxy( "http://%s:%s@localhost:%d/rpc" % (self._username, self._password, self._port) ) socket.setdefaulttimeout(10) # Do a quick timeout to catch problems, but not too quick or aria will time out... # wait for server to start up running = False while not running: try: self._server.aria2.tellActive() running = True except IOError: time.sleep(0.2) except xmlrpclib.ProtocolError, e: log(ERROR, u"Couldn't connect to aria process. Is an old one still running? Aborting...") raise e
def __init__(self, username, password): log(DEBUG) self._session = requests.Session() # Adapter to increase retries ad = requests.adapters.HTTPAdapter() # Older requests version don't expose the constructor arg :( ad.max_retries=5 self._session.mount('http://', ad) ad = requests.adapters.HTTPAdapter() # Older requests version don't expose the constructor arg :( ad.max_retries=5 self._session.mount('https://', ad) self._connected = False self._api_key = None # Torrents self._torrentsValidUntil = 0 self._torrents = [] self._dataRemaining = 0 # General attributes self._labelsValidUntil = 0 self._labels = [] # Torrent updates self._newTorrents = [] self._deletedTorrents = [] # Connect already? if username and password: self._username = username self._password = password self.connect()
def runpingweb(ip=webIP): # If no IP is passed, 8.8.8.8 is used result = pingweb(ip) check_section(ip) # Check if IP is in the conf file, if not, add it. status = check_option(ip,"status") # Add option if it does not exist check_option(ip,"last-alive-time") # Add option if it does not exist print result if result == "0": # No connection text = ("No connection to %s"%(ip)) if status == "connected": # Only log if previous state was "Connected" log(text) write_config(ip,'status', 'disconnected') return text elif result == "1" and status == "connected": # Connection OK write_config(ip,"last-alive-time",dateandtime()) # Log alivetime elif result == "1" and status != "connected": write_config(ip, 'status', 'connected') lastAliveStr = config.get(ip,'last-alive-time') if lastAliveStr != "": # Time exists lastAlive = datetime.strptime(lastAliveStr, '%Y-%m-%d %H:%M:%S') nowtime = datetime.strptime(str(dateandtime()), '%Y-%m-%d %H:%M:%S') alivetime_diff = nowtime - lastAlive # Calculate time since last time it was alive text = ("Connection to %s restored after %s offline"%(ip,str(alivetime_diff))) elif lastAliveStr == "": # No time has been recorded text = ("First connection to IP %s"%(ip)) write_config(ip,"last-alive-time",dateandtime()) log(text)
def syncTorrents(self, force = False, downloadMode = "No"): '''Synchronize local list with data from JSIT server: add new, remove deleted ones''' log(DEBUG) if self._jsit is None: log(DEBUG, "self._jsit is None, skipping.") return None, None self._jsit.updateTorrents(force = force) new, deleted = self._jsit.resetNewDeleted() for d in deleted: t = self.lookupTorrent(d) if t: # Don't do delete, as it's already gone from JSIT # Keep deleted around for listing them as finished... #self._torrents.remove(t) #t.release() pass for n in new: # Do we have this one already? t = self.lookupTorrent(n) if not t: t = self._jsit.lookupTorrent(n) self._torrents.append(Torrent(self, jsittorrent = t, downloadMode = downloadMode, basedir = prefDir("downloads", "basedir", "downloads"))) return new, deleted
def die (self,killer): self._next._previous = self._previous self._previous._next = self._next self._sprite.undraw() Character.units.remove(self) log(str(self)+" has died") self._alive = False
def check_mail(self, message): self.check_folders() maildir = mailbox.Maildir(self._maildir, None, True) #maildir.get_folder(folder) try: email_message = email.message_from_string(message) message_id = email_message.__getitem__("Message-Id") subject = email_message.__getitem__("Subject") log("[%s] Got new e-mail for user \"%s\" with subject \"%s\"" % (message_id, self._username, subject), STD_OUT) self._parser.parse(email_message) if "folder" in self._parser: folder = self._parser["folder"] create_dir = self._parser["create dir"] log("[%s] Storing Mail in %s" % (message_id, folder), STD_OUT) self.store_mail_in_folder(maildir, message, create_dir, folder) # If nothing matches else: log("[%s] Storing mail in std. folder" % (message_id), STD_OUT) self.store_mail_in_folder(maildir, message, message_id) except StandardError, err: log("Programm Error: %s" % (err), STD_ERR) log("[%s] Storing mail in std. folder" % (message_id), STD_OUT) self.store_mail_in_folder(maildir, message)
def testValidateNomeFalse(): nomes = [ '1Alan', 'Alan', 'A1am', ] expression = not any(map(validateNome, nomes)) log(expression, sys._getframe().f_code.co_name) return expression
def messages(tokenId): fechaInicio = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f") log(f'***Se llamo al notification event de mensaje***\n') if 'application/json' in request.headers['content-type']: thread = threading.Thread(target=wavySendJson, args=(request.json, )) thread.start() return Response(status=200) else: return Response(status=526)
def processNew(self, data, client): log(logging.DEBUG, "%s" % json.dumps(data)) # If client did not authenticate, can't communicate if client.canCommunicate == False: log(logging.ERROR, "Client didn't authenticate") return nonce = data['packet_id'] timestamp = int(time.time() * 1000) try: decNonce = decipherAssymetricMessage(self.privateKey, base64.b64decode(nonce)) except Exception as e: print(e) log(logging.ERROR, "Could not decipher the nonce %s" % nonce) client.sessionKey = client.sendResult( { "packet_id": nonce, "error": "Malformed nonce", "timestamp": timestamp }, client.sessionKey, client.salt) return if 'id' not in data.keys(): log( logging.ERROR, "No \"id\" field in \"processNew\" message: " + json.dumps(data)) client.sessionKey = client.sendResult( { "packet_id": bytesToString(base64.b64encode(decNonce)), "error": "wrong message format", "timestamp": timestamp }, client.sessionKey, client.salt) return user = int(data['id']) if user != client.id: log(logging.ERROR, "ID does not match the user: "******"packet_id": bytesToString(base64.b64encode(decNonce)), "error": "ID does not match the user", "timestamp": timestamp }, client.sessionKey, client.salt) return client.sessionKey = client.sendResult( { "packet_id": bytesToString(base64.b64encode(decNonce)), "result": self.registry.userNewMessages(user), "timestamp": timestamp }, client.sessionKey, client.salt)
def preset_mode(self, mode): if mode == self.mode_preset: return log(INFO, 'Display preset mode: {}'.format(mode.name)) if self.mode_preset != self.mode: self.__unset_mode__(self.mode_preset) if mode == MODE.PLAY_ONE_TRACK: self.drawer.rectangle( (self.HORIZONTAL_MARGIN - self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 1 + self.SELECTION_MARGIN, self.HORIZONTAL_MARGIN + self.play_track_text_width + self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 2), outline=self.PRESET_COLOR) elif mode == MODE.PLAY_ALL_TRACKS: self.drawer.rectangle( (self.LEFT_PANEL_MID_WIDTH - self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 1 + self.SELECTION_MARGIN, self.LEFT_PANEL_MID_WIDTH + self.play_all_text_width + self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 2), outline=self.PRESET_COLOR) elif mode == MODE.LOOP_ONE_TRACK: self.drawer.rectangle( (self.HORIZONTAL_MARGIN - self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 2 + self.SELECTION_MARGIN, self.HORIZONTAL_MARGIN + self.loop_track_text_width + self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 3), outline=self.PRESET_COLOR) elif mode == MODE.STOP: self.drawer.rectangle( (self.LEFT_PANEL_MID_WIDTH - self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 2 + self.SELECTION_MARGIN, self.LEFT_PANEL_MID_WIDTH + self.stop_text_width + self.SELECTION_MARGIN, self.BIGGER_LINE_HEIGHT * 3), outline=self.PRESET_COLOR) else: log(ERROR, 'Got an unsupported mode to preset: {}'.format(mode.name)) self.mode_preset = mode self.is_refresh_needed = True return
def createConversation(tokenId, cJson): log('***Creando conversación con API de five9***\n') url = 'https://app-atl.five9.com:443/appsvcs/rs/svc/conversations' data = cJson headers = {'Content-Type': 'application/json', 'Authorization' : f'Bearer-{tokenId}', 'farmId' : '3000000000000000021'} log(f'url: {url}\n') log(f'Json para generar la conversación: {data}\n') log(f'Headers: {headers}\n') response = requests.post(url, data = json.dumps(data), headers = headers) log(f'Código de respuesta de la API: {response.status_code}\n')
def addClient(self, csock, addr): """Add a client connecting in csock.""" if csock in self.clients: log(logging.ERROR, "Client NOT Added: %s already exists" % self.clients[csock]) return client = Client(csock, addr) self.clients[client.socket] = client log(logging.DEBUG, "Client added: %s" % client)
def __send_command__(self, command): log(DEBUG, "Sending command: 0x{:02X}".format(command)) self.__output_gpio__(LCD_SCREEN_DC_PIN, 0) self.__output_gpio__(LCD_SCREEN_CS_PIN, 0) self.spi_device.write_bytes([command]) self.__output_gpio__(LCD_SCREEN_CS_PIN, 1) return
def get_file_name(): flag = int( input("if you want to name the config file type 1 else type 2:\n")) if (flag == 1): name = input("type your file name!(not included \".yaml\")\n") else: time = datetime.datetime.now().strftime('%m%d%H%M') name = time log(" [Info] successed to get file name!") return name
def remove_input_file(input_fullname): filename_with_ext = os.path.basename(input_fullname) filename_without_ext, ext = os.path.splitext(filename_with_ext) log(INFO, 'Removing input {}'.format(filename_without_ext)) os.remove(input_fullname) return
def build_one_vector(self,raw_quest,bShow=True): quest=[self.word_to_id.get(word,self.word_to_id['<UNK>']) for word in raw_quest] if len(quest)>=self.args.max_document_lenth: quest=quest[:self.args.max_document_lenth] else: #pad_sequences补0是往前面补 quest=(self.args.max_document_lenth-len(quest))*[self.word_to_id['<UNK>']]+quest if (bShow==True): log('问题:{}\n向量:{}'.format(raw_quest,quest)) return np.array(quest)
def click_load(self, event): try: # Load preset # Update text fields: self.textCtrl_Server.SetValue(self.main.config.parameters["presets"]) #self.textCtrl_Port.SetValue(parent.config.parameters["presets"]) #self.choice_Protocol.SetSelection(2) # BOGUS log('Load preset.') except Exception as e: error(self, "while loading preset: " + str(e))
def loadbalance_resrc(auth, region, sub_res, resource_id=None): res_url = get_url(auth, 'lb', sub_res, resource_id) try: resp = httprequest.httpclient('GET', res_url, auth[0]) log.info('RESP:' + str(resp.json())) except Exception as e: log(e) resp = {'code': 404, 'message': 'RESOURCE NOT FOUND'} return make_response(json.dumps(resp), 404) return make_response(json.dumps(resp.json()), resp.status_code)
def __toggle_view(self, name, visible): views = self.application().view.available_main_views() for view in views: log(str(view)) if self.application().view.is_view_visible( name) and visible is not True: self.application().view.hide_view(name) else: self.application().view.show_view(name)
def check_folders(self): folders = ["new", "tmp", "cur"] for folder in folders: path = os.path.join(self._maildir, folder) if not os.path.isdir(path): if not os.access(self._maildir, os.W_OK): log("Can not write in: \"%s\"" % (path), STD_ERR) else: log("Dir not found: \"%s\"" % (path), STD_ERR) os.mkdir(path)
def charge_p(this, name, sp): if type(sp) == str and sp[-1] == '%': percent = int(sp[:-1]) this.s1.charge(this.conf['s1_sp']*percent/100) this.s2.charge(this.conf['s2_sp']*percent/100) this.s3.charge(this.conf['s3_sp']*percent/100) log('sp', name, '%d%% '%percent,'%d/%d, %d/%d, %d/%d'%(\ this.s1.charged, this.s1.sp, this.s2.charged, this.s2.sp, this.s3.charged, this.s3.sp) ) this.think_pin('prep') return
def read_test_emails(username, maildir, test_data_dir): log("Using test-data from directory: %s" % test_data_dir, STD_OUT) for entry in os.listdir(test_data_dir): test_mail_path = os.path.join(test_data_dir, entry) if os.path.isfile(test_mail_path) and test_mail_path.endswith(".mail"): log("Reading Test E-Mail: %s" % test_mail_path, STD_OUT) fh = open(test_mail_path, 'r') message = fh.read() fh.close() run_test(username, maildir, message)
def cardSort(self, cards): if not cards: return cards log(u'[cardSort_S] cards[%s]' % (cards), LOG_LEVEL_RELEASE) cards = sorted(cards, key=lambda x: x[1], reverse=True) sortedCards = sorted(cards, key=lambda x: card2val_map[x[0]], reverse=True) log(u'[cardSort_E] sortedCards[%s]' % (sortedCards), LOG_LEVEL_RELEASE) return sortedCards
def load_send(self,parsed): try: lst = parsed["result"] except KeyError: log(logging.ERROR,"{}\n".format(parsed["error"])) return None #log(logging.DEBUG,"MESSAGE {} SUCCESSFULLY SENT TO USER. RECEIPT {} SAVED".format(lst[0],lst[1])) print("Message {} Successfully Sent. Receipt {} Saved.\n".format(lst[0],lst[1]))
def doCurAction(self, action, cardList): ''' 执行操作 ''' log(u'[doCurAction] action[%s] cardList[%s]' % (action, cardList), LOG_LEVEL_RELEASE) if action not in self.doAction2callback: log(u'[doCurAction] action not in actions', LOG_LEVEL_RELEASE) return [] return self.doAction2callback[action](cardList)
def close(self): """Shuts down and closes this client's socket. Will log error if called on a client with closed socket. Never fails. """ log(logging.INFO, " Client.close(%s)" % self) try: self.socket.close() except: logging.exception(" Client.close(%s)" % self)
def draw_init(self): log(INFO, 'Display draw initialization image: {}'.format(self.INIT_IMAGE)) self.lcd_screen.module_init() self.lcd_screen.start_init_animation() return
def start_log(self, client_params, server_param): if client_params['params']['log'] == 'true': set_flag(True) log('现在开启log日志记录功能') else: log('现在关闭log日志记录功能') set_flag(False) params = {} params['success'] = 'true' server_param['result'] = params
def processSecure(self, data, client, msgControl=None): """ Process Message with type field "secure" """ msgControl = data['msgControl'] # flag de controlo if not base64.b64decode(msgControl) == secure.SHA256( str(client.nextRequest)): log( logging.INFO, colors.ERROR + "This messages is not the answer for the previews request." + colors.END) return # resposta a ser esperada pelo server client.nextRequest += 1 print "\n" log( logging.INFO, colors.INFO + " Expected Message!" + colors.END + " SEQ CODE: " + str(client.nextRequest - 1)) log( logging.INFO, colors.INFO + " Secure Request " + colors.WARNING + " username: "******" Integrity Checked Sucessfully" + colors.END) else: log( logging.INFO, colors.ERROR + " Message forged! Sorry! Aborting ..." + colors.END) return # Handling Request if req['type'] in dataFinal: self.messageTypes[req['type']](req, client, msgControl) return
def processSend(self, data, client): log(logging.DEBUG, "%s" % json.dumps(data)) data_error = "" if not set(data.keys()).issuperset(set({'src', 'dst', 'msg', 'copy'})): log(logging.ERROR, "Badly formated \"send\" message: " + json.dumps(data)) data_error = load_payload({"error": "wrong message format"}) payload, client.blockChain = ourCrypto.generate_integrity( data_error, client.sessionKeys, client.blockChain) client.sendResult(payload) return srcId = int(data['src']) dstId = int(data['dst']) msg = str("\n".join([data['msg']['text'], data['msg']['signature']])) copy = str("\n".join([data['copy']['copy'], data['copy']['signature']])) if not self.registry.userExists(srcId): log(logging.ERROR, "Unknown source id for \"send\" message: " + json.dumps(data)) data_error = {"error": "wrong parameters"} if not self.registry.userExists(dstId): log( logging.ERROR, "Unknown destination id for \"send\" message: " + json.dumps(data)) data_error = {"error": "wrong parameters"} if client.id != srcId or srcId == None: log( logging.ERROR, "No valid \"src id\" field in \"send\" message, (not your mail box): " + json.dumps(data)) data_error = { "error": "Cant send msg from other person, user your source ID" } if data_error: data_error = load_payload(data_error) payload, client.blockChain = ourCrypto.generate_integrity( data_error, client.sessionKeys, client.blockChain) client.sendResult(payload) return # Save message and copy payload = { "result": self.registry.sendMessage(srcId, dstId, msg, copy) } payload = load_payload(payload) payload, client.blockChain = ourCrypto.generate_integrity( payload, client.sessionKeys, client.blockChain) client.sendResult(payload)
def five9GetToken(): log('***Generando token con API de five9***\n') url = 'https://app-scl.five9.com:443/appsvcs/rs/svc/auth/anon?cookieless=true' data = json.dumps({"tenantName": "Telectronic Reseller"}) headers = {'Content-Type': 'application/json'} log(f'url: {url}\n') log(f'Json para generar la conversación: {data}\n') log(f'Headers: {headers}\n') response = requests.post(url, data = data, headers = headers) log(f'Codigo de respuesta de la API generar token: {response.status_code}\n') return response.json()['tokenId']
def get_file_tempo(self, index): if not 0 <= index < self.files_count: log( ERROR, 'Cannot get MIDI file tempo; out of range index: {}; using 1st file instead' .format(index)) index = 0 return self.files[index]['tempo']
def wavySendMessage(data): log('***Invocando API send message de wavy***\n') url = 'https://api-messaging.wavy.global/v1/whatsapp/send' urlHeaders = { 'Content-type': 'application/json', 'UserName': '******', 'AuthenticationToken': 'nouxAVNgqztEWAgVyYfj1qI2i8g-DToSty6bGz1P' } response = requests.post(url, json.dumps(data), headers=urlHeaders) log(f'Json devuelto: {response.json()}') print(log('*Evento finalizado*\n'))
def module_exit(self): log(INFO, 'Shutting down LCD screen') self.spi_device.close() self.__output_gpio__(LCD_SCREEN_RESET_PIN, 0) self.__output_gpio__(LCD_SCREEN_DC_PIN, 0) self.__output_gpio__(LCD_SCREEN_BL_PIN, 0) return
def right_with_angle(self, angle, is_blocking): log(DEBUG, 'Robot >>> turning right @ angle = {:3.2f}'.format(angle)) self.turn_angle_order = self.relative_yaw_angle - angle self.turn_speed_step = -TURNING_SPEED_STEP / 2 if is_blocking == True: # If requested, stay blocked here as long as turn is in progress while self.turn_angle_order != 0: time.sleep(IDLE_LOOP_SLEEP_TIME)
def sendMessage(tokenId, data): log('***Mandando mensaje con la API de five9***\n') messageText = data['data'][0]['message']['messageText'] url = f'https://app-atl.five9.com:443/appsvcs/rs/svc/conversations/{tokenId}/messages' headers = {'Content-Type': 'application/json', 'Authorization' : f'Bearer-{tokenId}', 'farmId' : '3000000000000000021'} message = {'message' : f'{messageText}'} log(f'url: {url}\n') log(f'Json para el envio de mensaje: {message}\n') log(f'Headers: {headers}\n') response = requests.post(url, data = json.dumps(message), headers = headers) log(f'Código de respuesta de la API: {response.status_code}\n')