def debug(self, text, level=DebugLevel.Normal): # append to text view if self.settings['Debug']['Enabled'] and level >= self.settings['Debug']['Level']: self.pop(self.debug_buf) position = self.debug_buf.get_end_iter() self.debug_buf.insert(position, '[' + tools.get_time() + '] ' + text + '\n') logger.debug(text)
def run(self): # Register on bonjour chat self.id = random.randint(100000000000, 999999999999) txt = {} txt['1st'] = self.fullname txt['last'] = "" txt['status'] = 'avail' txt['port.p2pj'] = self.port txt['nick'] = self.fullname # txt['node'] = self.node txt['jid'] = self.node txt['email'] = self.node txt['version'] = 1 txt['txtvers'] = 1 logger.debug("txt register: %s" % str(txt)) txt = pybonjour.TXTRecord(txt, strict=True) self.sdRef = pybonjour.DNSServiceRegister( name=self.node, regtype='_presence._tcp', port=self.port, txtRecord=txt, callBack=self._register_callback) # Bonjour chat handcheck self.must_run = True while self.must_run: ready = select.select([self.sdRef], [], [], 1) if self.sdRef in ready[0]: pybonjour.DNSServiceProcessResult(self.sdRef)
def read(path, name, extension='html', access=RO_ACCESS): ''' read() tries to load the selected template and returns its content. ''' fullPath = os.path.join( path, str(name) + ('' if len(extension) and extension[0] == '.' else '.') + extension) if os.path.exists(fullPath): logger.debug(' loading template file at \'%s\'' % fullPath) cnt = '' try: fileObject = open(fullPath, 'r') cnt = fileObject.read() fileObject.close() if access == RO_ACCESS: cnt = REGEXP.sub('', cnt) except IOError: logger.error(' can\'t access template file: \'%s\'' % fullPath) return cnt else: logger.error(' template file doesn\'t exist: \'%s\'' % fullPath) return ''
def run(self): # Register on bonjour chat self.id = random.randint(100000000000, 999999999999) txt = {} txt['1st'] = self.fullname txt['last'] = "" txt['status'] = 'avail' txt['port.p2pj'] = self.port txt['nick'] = self.fullname # txt['node'] = self.node txt['jid'] = self.node txt['email'] = self.node txt['version'] = 1 txt['txtvers'] = 1 logger.debug("txt register: %s" % str(txt)) txt = pybonjour.TXTRecord(txt, strict=True) self.sdRef = pybonjour.DNSServiceRegister(name=self.node, regtype='_presence._tcp', port=self.port, txtRecord=txt, callBack=self._register_callback ) # Bonjour chat handcheck self.must_run = True while self.must_run: ready = select.select([self.sdRef], [], [], 1) if self.sdRef in ready[0]: pybonjour.DNSServiceProcessResult(self.sdRef)
def run(self): while self.parent.bonjour_auth_user == '': logger.debug("Waiting selection of an authorized bonjour contact") self.waiting_authorized_contact = True sleep(1) self.waiting_authorized_contact = False bonjour_auth_username = str(self.parent.bonjour_auth_user) self.auth_user = {bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username]} self.add_starting_friends() if config.usecontroler == QtCore.Qt.Checked: # Startup controller self.start_controller() self.must_run = True while self.must_run: sleep(0.1) if not recv_sms_q.empty(): new_sms = recv_sms_q.get() status = self.sms_received(new_sms['phone_number'], new_sms['message']) if status: recv_sms_q.task_done() if not send_sms_q.empty(): new_sms = send_sms_q.get() self.send_sms(new_sms['to'], new_sms['message']) send_sms_q.task_done() if not sms_history_q.empty(): sms = sms_history_q.get() insert_sms_in_history(sms) sms_history_q.task_done()
def write_auth(self): # TODO: Implements auth conf = config.getConfig() fileconf = config.getGlobalConfig() if conf.require('global') else config.getUserConfig() remove = conf.require('remove') if remove: fileconf.remove('gist.auth') fileconf.remove('gist.token') print 'Authentication removed, you may delete the token from your user panel.' return if fileconf.get('gist.auth', False) and not conf.get('force', False): logger.info('check current token') try: token = fileconf.require('gist.token') except exception.NoSuchOption: fileconf.remove('gist.auth') return self.write_auth() result = self._do_auth(token=token) if result: print 'Current token is valid, no auth required.' return print 'Current token is invalid, requesting a new token.' token = self._perform_auth() logger.info('auth ok.') fileconf.set('gist.auth', True) fileconf.set('gist.token', token) logger.debug('saving to config file.') fileconf.save() print 'Done!'
def __init__(self): logger.debug('call: ubuntupaste.__init__') self._actions = dict() self.req = requests.Session() logger.debug('http: set user-agent.') self.req.headers['User-Agent'] = config.full_version() super(UbuntuPaste, self).__init__()
def _add(func): global _actions logger.debug('decorator: add_action ' + action_name) if action_name in _actions: logger.fatal(action_name + ' already registered!') _actions[action_name] = func return func
def __init__(self): logger.debug('call: gist.__init__') self.req = requests.Session() logger.debug('http: set user-agent.') self.req.headers['User-Agent'] = config.full_version() self.req.headers['Accept'] = 'application/vnd.github.v3+json' super(Gist, self).__init__()
def image_dir(ctx, **kwargs): """Predict data using the selected model on a set of images.""" if not models.model_exists(kwargs['model']): raise click.UsageError("Model '{0}' does not exist.".format( kwargs['model']), ctx=ctx) if not weights.weights_exist(kwargs['model'], kwargs['iteration']): raise click.UsageError( "Model '{0}' (iteration: '{1}') does not exist.".format( kwargs['model'], kwargs['iteration']), ctx=ctx) ctx.obj['model'] = kwargs['model'] ctx.obj['weights'] = (kwargs['model'], kwargs['iteration']) logger.info('Scanning for images in `{0}`.'.format(kwargs['input'])) lst = [] for f in os.listdir(kwargs['input']): f_path = os.path.join(kwargs['input'], f) if not lib.utils.valid_image(f_path): continue lst.append(f_path) lst.sort() logger.info('Found {0} images in directory.'.format(len(lst))) X = [] with click.progressbar(label='Loading images...', length=len(lst), show_pos=True) as pbar: for im in lst: im = lib.utils.load_image(im) X.append(im) pbar.update(1) X = np.array(X) logger.info('Prediction starts.') try: Y = lib.tf.predict(X, ctx.obj['model'], ctx.obj['weights']) except Exception: logger.error("Unrecoverable error.", exc_info=True) exit(1) logger.debug("min(Y)={0}, max(Y)={1}, avg(Y)={2}, var(Y)={3}".format( np.min(Y), np.max(Y), np.average(Y), np.var(Y))) logger.debug("Y.shape={0}, Y.dtype={1}".format(Y.shape, Y.dtype)) with click.progressbar(label='Saving images...', length=len(Y), show_pos=True) as pbar: i = 0 for im in Y: im = lib.utils.save_image( os.path.join(kwargs['output'], os.path.basename(lst[i])), im) pbar.update(1) i += 1 logger.info('Completed predictions on {0} images.'.format(len(Y)))
def getUserConfig(): global _user_instance if _user_instance is None: logger.debug('opening user config') _user_instance = FileConfig(_user_filename) return _user_instance
def __process_media_file(self): self.__get_media_file() if self.current_processing_file is not None: try: logger.info("Processing file [{}]".format( self.current_processing_file.identifier)) logger.debug(self.current_processing_file) self.__execute_handbreak_command() logger.info("File [{}] processed successfully".format( self.current_processing_file.identifier)) logger.debug(self.current_processing_file) self.mfq[self.current_processing_file.id, self.current_processing_file. file_path] = MediaFileState.PROCESSED self.current_processing_file = None except HandbreakProcessInterrupted: self.__return_current_processing_file(MediaFileState.WAITING) except Exception: logger.exception( "File [{}] returning to processing queue after processing error, status [{}]" .format(self.current_processing_file.identifier, MediaFileState.FAILED.value)) self.__return_current_processing_file(MediaFileState.FAILED)
def send_sms(self, message): # Launch function logger.debug("Controller communication detected") params = None try: function_name, params = message.split(" ", 1) except ValueError, e: function_name = message
def getGlobalConfig(): if os.name != 'posix': raise OSError('No global config supported in your platform, currently only posix are supported.') global _global_instance if _global_instance is None: logger.debug('opening global config') _global_instance = FileConfig(_global_filename) return _global_instance
def function_search(self, params): """ Search a contact in order to add it """ logger.debug("Controller: `search' function called") res = search_contacts(str(params)) self.add_contact_dict = dict([(index + 1, contact) for index, contact in enumerate(res)]) message = "\r\n\t\tSearch result\r\n IDs\t Names\t\t\t\tNumbers\r\n" message = message + "\r\n".join([" %s\t- %s" % (index, " :\t".join(contact)) for index, contact in self.add_contact_dict.items()]) self.sms_to_bonjour(message)
def __return_current_processing_file(self, media_file_state): if self.current_processing_file is not None: self.mfq[self.current_processing_file.id, self.current_processing_file.file_path] = media_file_state logger.info( "File [{}] returned to processing queue, status [{}]".format( self.current_processing_file.identifier, media_file_state.value)) logger.debug(self.current_processing_file)
def __execute_handbreak_command(self): handbreak_command_logger = logging.getLogger( InterruptableSystemCommandThread.__module__) formatter = logging.Formatter( '[%(asctime)-15s] [%(levelname)s]: %(message)s') file_handler = logging.FileHandler( filename=self.current_processing_file.log_file_path, encoding='utf-8') file_handler.setFormatter(formatter) handbreak_command_logger.handlers = [file_handler] handbreak_command_logger.setLevel(logger.level) current_env = os.environ.copy() current_env["INPUT_FILE"] = self.current_processing_file.file_path current_env[ "OUTPUT_FILE"] = self.current_processing_file.transcoded_file_path logger.debug("Handbreak input file: {}".format( self.current_processing_file.file_path)) logger.debug("Handbreak output file: {}".format( self.current_processing_file.transcoded_file_path)) self.system_call_thread = InterruptableSystemCommandThread( self.handbreak_command, env=current_env, name=InterruptableSystemCommandThread.__module__) timer = Timer(self.handbreak_timeout, self.system_call_thread.kill) timer.start() self.system_call_thread.start() self.system_call_thread.join() if timer.is_alive(): timer.cancel() if self.system_call_thread.interrupted: message = "Handbreak process interrupted softly" logger.debug(message) raise HandbreakProcessInterrupted(message) elif self.system_call_thread.exit_code != 0: raise Exception( "Handbreak processes failed. Please, check the transcoding log file [{}]" .format(self.current_processing_file.log_file_path)) else: logger.debug( "Handbreak process finished successfully, removing the transcoding log file [{}]" .format(self.current_processing_file.log_file_path)) os.remove(self.current_processing_file.log_file_path) if self.delete_orig_file: logger.debug("Removing the source file [{}]".format( self.current_processing_file.file_path)) os.remove(self.current_processing_file.file_path) else: raise Exception("Handbreak processes killed after {} hours".format( self.handbreak_timeout / 60 / 60))
def set_auth(self, bonjour_auth_user): bonjour_auth_username = str(bonjour_auth_user) if bonjour_auth_username: auth_user = {bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username]} logger.debug("Bonjour contact which receive message: %s" % auth_user) for f in self.friend_list: f.auth_user = auth_user else: banner_notification("Avahi error, please restart HeySms")
def start(self): i = 0 ret = self.listen(self.host, self.port) while not ret: ret = self.listen(self.host, self.port + i) i = i + 1 self.port = self.port + i logger.debug("Bonjour server listen on port %s" % self.port) QtCore.QObject.connect(self, QtCore.SIGNAL("newConnection()"), self.accept_new_connection)
def loop_click(target_list, start, step): current_target_index = start while True: if target_clicked(target_list[current_target_index]): break if current_target_index >= len(target_list): logger.debug( "Can't AutoTarget because there's no target can be clicked") break current_target_index += step
def run(): """ Run the main system """ logger.debug("In run....") logger.debug("Full config %s", conf) # Start the server cherrypy.engine.start() cherrypy.engine.block()
def getGlobalConfig(): if os.name != 'posix': raise OSError( 'No global config supported in your platform, currently only posix are supported.' ) global _global_instance if _global_instance is None: logger.debug('opening global config') _global_instance = FileConfig(_global_filename) return _global_instance
def get_filtered_offers(self, offer_listings, condition='any'): filtered_offers = [] if len(offer_listings) <= 0: logger.debug('[NoOfferFound] %s - %s' % (offer_listings, self.filter)) return filtered_offers for offer_listing in offer_listings: fba = offer_listing['fba'] offer_condition = offer_listing['condition'] # print fba, offer_condition, offer_listing if condition.lower() == 'new' and offer_condition.lower() != 'new': continue # fba if self.filter['fba'] is not None and fba != self.filter['fba']: continue ships_domestically = offer_listing['domestic'] if self.filter[ 'domestic'] is not None and ships_domestically != self.filter[ 'domestic']: continue shipping_time = offer_listing['shipping_time'] if shipping_time is not None and fba is False: if shipping_time['min'] > self.filter['shipping_time']: continue rating = offer_listing['rating'] if rating['min'] < self.filter['rate'] and fba is False: continue feedback_count = offer_listing['feedback'] if feedback_count < self.filter['review'] and fba is False: continue subcondition = offer_listing['subcondition'] if self.dict_subcondition[ subcondition.lower()] < self.filter['subcondition']: continue filtered_offers.append(offer_listing) if len(filtered_offers) > 0: filtered_offers_str = [ str(filtered_offer) for filtered_offer in filtered_offers ] logger.debug('[FilteredOffer] %s - %s' % ("\n".join(filtered_offers_str), self.filter)) return filtered_offers
def __init__(self, filename=None): self.rc = ConfigParser.RawConfigParser() if filename is None: if os.name == 'posix': filelist = [_global_filename, _user_filename] else: filelist = [_user_filename] logger.debug('config loaded: ' + str(self.rc.read(filelist))) else: self.rc.read(filename) self._filename = filename
def fetch_between(content, start_flag, end_flag): start_len, end_len = len(start_flag), len(end_flag) start_pos = content.find(start_flag) logger.debug('start_pos: %d' % start_pos) if start_pos < 0: raise exception.ServerException('Start flag not found!') end_pos = content.find(end_flag, start_pos + start_len) logger.debug('end_pos: %d' % end_pos) if end_pos < 0: raise exception.ServerException('End flag not found!') return content[start_pos + start_len : end_pos]
def __init__(self, filename = None): self.rc = ConfigParser.RawConfigParser() if filename is None: if os.name == 'posix': filelist = [_global_filename, _user_filename] else: filelist = [_user_filename] logger.debug('config loaded: ' + str(self.rc.read(filelist))) else: self.rc.read(filename) self._filename = filename
def fetch_between(content, start_flag, end_flag): start_len, end_len = len(start_flag), len(end_flag) start_pos = content.find(start_flag) logger.debug('start_pos: %d' % start_pos) if start_pos < 0: raise exception.ServerException('Start flag not found!') end_pos = content.find(end_flag, start_pos + start_len) logger.debug('end_pos: %d' % end_pos) if end_pos < 0: raise exception.ServerException('End flag not found!') return content[start_pos + start_len:end_pos]
def fetch(payload, dbi=None): """抓取 payload['url'] 的檔案 並將最終讀取到的 url 寫入 payload['url_read'], response 寫入 payload['src'] """ import re from lxml.html import fromstring from lib import db, DB, logger from lib.util.text import to_unicode extra = {'classname': 'util.net.fetch()'} try: uo = urlopen(payload['url'], timeout=HTTP_TIMEOUT) if (uo.code != 200): raise IOError("HTTP response code=%d from %s" % (uo.code, uo.url)) portal = get_portal(uo.url) if portal: break_portal(portal, payload, uo) else: payload['src'] = uo.read() payload['url_read'] = uo.url except Exception as e: # 抓取出錯,留待記錄 (save_fetch) payload['src'] = 'error ' + unicode(e) payload['category'] = 'error' payload['exception'] = e if 'url_read' not in payload: payload['url_read'] = payload['url'] if dbi is None: _dbi = DB() else: _dbi = dbi try: db.save_fetch(payload['url'], to_unicode(payload['src']), payload['category'], dbi=_dbi) except Exception as e: logger.warning('DB save_fetch failed for url %s' % payload['url'], extra=extra) logger.debug(e) if dbi is None: _dbi.disconnect() if 'error' == payload['category']: # raise the exception to skip the parsing process logger.info("failed fetching %s" % payload['url'], extra=extra) raise payload['exception'] return payload
def set_auth(self, bonjour_auth_user): bonjour_auth_username = str(bonjour_auth_user) if bonjour_auth_username: auth_user = { bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username] } logger.debug("Bonjour contact which receive message: %s" % auth_user) for f in self.friend_list: f.auth_user = auth_user else: banner_notification("Avahi error, please restart HeySms")
def removeSummaryData(perfList): ''' Removes the summary entries of the performance data like for example the performance data for the JDBC Provider level ''' oldLenght = len(perfList) l.debug("Lenght of performance data list before removal: '%d'" % (oldLenght)) tmpList = [] rmvTagsList = [] for tmpDict in perfList: tmpList.append(tmpDict["tags"]) tmpListLength = len(tmpList) l.debug("Lenght of tags list before removal: '%d'" % (tmpListLength)) tmpList.sort() for i in range(tmpListLength - 1): if (tmpList[i + 1].startswith(tmpList[i])): rmvTagsList.append(tmpList[i]) l.debug("Removing tag entry: '%s'" % (tmpList[i])) ## ## Build the return list perfList = [x for x in perfList if (x["tags"] not in rmvTagsList)] newLenght = len(perfList) l.debug("Lenght of performance data list after removal: '%d'" % (newLenght)) return (perfList)
def writeToInflux(parmInfluxUrl, parmInfluxDb, parmTargetUser, parmTargetPwd, perfList, whitelistDict): ''' writes the data to the influx DB using the write REST API ''' l.debug("writeToInflux with the following parameters: \nparmInfluxUrl: '%s'\n parmInfluxDb: '%s'\n parmTargetUser: '******'\n parmTargetPwd: '%s'\n len(perfList): : '%s'" % (parmInfluxUrl, parmInfluxDb, parmTargetUser, parmTargetPwd, len(perfList))) try: (urlSchema, urlHost, urlPort) = o.splitHttpUrlString(parmInfluxUrl) except Exception as e: raise Exception, sys.exc_info()[1] ## ## influxdb write end-point with query string tmpUri = "/write" tmpUri += o.buildQueryString(db=parmInfluxDb, precision="ms", p=parmTargetPwd, u=parmTargetUser) l.debug("Uri to /write Influx: '%s'" % (tmpUri)) postHeaders = {"Content-type": "text/plain; charset=utf-8", "Accept": "text/plain"} ## ## Number of rows inserted rowCount = 0 ## ## Format the output as a string data = outputFormatter(perfList, outFormat="INFLUX", whitelistDict=whitelistDict) l.verbose("formatted influx data: \n%s", data) ## ## outputFormatter returns a string of the data separated by \n per line postDataDict = data.split("\n") ## ## iterate over the perflist and build the REST API string. ## The "tags" is string of tags separated by NODE_SEPARATOR and the counters will be the fields for postData in postDataDict: l.debug("POST data for write end-point: '%s'" % (postData)) ## ## try: ## ## Get the HTTP Connection httpConn = o.getHttpConnection(urlSchema, urlHost, urlPort) httpConn.request("POST", tmpUri, postData, postHeaders) httpResponse = httpConn.getresponse() responseData = httpResponse.read() httpConn.close() rowCount += 1 except Exception as e2: httpConn.close() errorString = "Failed to write data to influx, '%s'" % (e2.strerror) raise Exception, errorString ## ## indluxDb write returns code 204 if (httpResponse.status != httplib.NO_CONTENT): l.error("Error response data: '%s'" % (responseData)) errorString = "Write to influx db failed with status code: '%d'", httpResponse.status l.error(errorString) httpConn.close() raise Exception, errorString else: l.debug("influx URL ping returned status code: '%d'", httpResponse.status) ## ## Finished - close the connection httpConn.close() l.info("writeToInflux: Number of rows inserted: '%d'" % (rowCount))
def company_profile(cookie,company_id,keyword): # This function requests the companies profile and returns the data if keyword == None: url='https://www.linkedin.com/voyager/api/search/cluster?count=40&guides=List(v->PEOPLE,facetCurrentCompany->%s)&origin=OTHER&q=guided&start=0' % company_id logger.debug('Requesting %s from company_profile()' % url) else: url = "https://www.linkedin.com/voyager/api/search/cluster?count=40&guides=List(v->PEOPLE,facetCurrentCompany->%s)&keywords=%s&origin=OTHER&q=guided&start=0" % (company_id,keyword) logger.debug('Requesting %s from company_profile()' % url) data=http.connect(url,cookie) if data == None: logger.red('Unable to authenticate to LinkedIn') quit() return data.text
def fetch(payload, dbi = None): """抓取 payload['url'] 的檔案 並將最終讀取到的 url 寫入 payload['url_read'], response 寫入 payload['src'] """ import re from lxml.html import fromstring from lib import db, DB, logger from lib.util.text import to_unicode extra = {'classname': 'util.net.fetch()'} try: uo = urllib.urlopen(payload['url']) if (uo.code != 200): raise IOError("HTTP response code=%d from %s" % (uo.code, uo.url)) portal = get_portal(uo.url) if portal: break_portal(portal, payload, uo) else: payload['src'] = uo.read() payload['url_read'] = uo.url except Exception as e: # 抓取出錯,留待記錄 (save_fetch) payload['src'] = 'error ' + unicode(e) payload['category'] = 'error' payload['exception'] = e if 'url_read' not in payload: payload['url_read'] = payload['url'] if dbi is None: _dbi = DB() else: _dbi = dbi try: db.save_fetch(payload['url'], to_unicode(payload['src']), payload['category'], dbi = _dbi) except Exception as e: logger.warning('DB save_fetch failed for url %s' % payload['url'], extra=extra) logger.debug(e) if dbi is None: _dbi.disconnect() if 'error' == payload['category']: # raise the exception to skip the parsing process logger.warning("failed fetching %s" % payload['url'], extra=extra) raise payload['exception'] return payload
def toggle_favorite(self): if self.friend.favorite == False: favorite_icon = QtGui.QIcon('/usr/share/icons/hicolor/32x32/apps' '/favorite.png') self.friend.favorite = True config.add_startup_contacts(self.friend) else: favorite_icon = QtGui.QIcon('/usr/share/icons/hicolor/32x32/apps' '/non-favorite.png') self.friend.favorite = False config.del_startup_contacts(self.friend) logger.debug("Toggle favorite friend: %s to %s" % (self.friend.fullname, self.friend.favorite)) self.setIcon(favorite_icon)
def function_help(self, *args, **kargs): """ Return controller help """ logger.debug("Controller: `help' function called") message = self.tr( """\nHeySms Help\n""" """===========\n\n""" """Show this help\t: help\n""" """Add contact\t: add $CONTACT_ID$. Use `search' command before\n""" """Del contact\t: del $CONTACT_ID$. Use `show' command before\n""" """Search contact\t: search $CONTACT_NAME$\n""" """Show contacts\t: show\n""" """Echo your msg\t: echo $MESSAGE$\n""" ) self.sms_to_bonjour(message)
def function_help(self, *args, **kargs): """ Return controller help """ logger.debug("Controller: `help' function called") message = ( """\nHeySms Help\n""" """===========\n\n""" """Show this help\t: help\n""" """Add contact\t: add $CONTACT_ID$. Use `search' command before\n""" """Del contact\t: del $CONTACT_ID$. Use `show' command before\n""" """Search contact\t: search $CONTACT_NAME$\n""" """Show contacts\t: show\n""" """Echo your msg\t: echo $MESSAGE$\n""" ) self.sms_to_bonjour(message)
def set_language(self, lang=None, starting=False): if lang: self.language = lang self.setValue("language", QtCore.QVariant(self.language)) self.sync() translator = self.parent.translator if translator: translator.load("heysms_" + self.language, "/opt/HeySms/i18n/", "_", ".qm") self.parent.app.installTranslator(translator) if not starting: self.parent.central_widget.retranslate() self.parent.menubar.retranslate() self.parent.main_window.conf_dialog.retranslate() logger.debug("Translate successfully to: %s" % self.language)
def buildDictFromXmlNode(statistics_node): ''' Converts the statistics_node to a dictionary with the attributes in List attrList ''' l.logEntryExit("Entering: statistics_node.tag: '%s'; statistics_node.name: '%s'" % (statistics_node.tag, statistics_node.get("name"))) rtnDict = {} nodeAttrDict = statistics_node.attrib ##### l.debug("Dictionary of node attributes: '%s'", (str(nodeAttrDict))) rtnDict["classificaton"] = statistics_node.tag for attr in nodeAttrDict.keys(): rtnDict[attr] = statistics_node.get(attr) ## ## return the built dictionary l.debug("buildDictFromXmlNode returns '%s'", (str(rtnDict))) return rtnDict
def call(t): global sent_msg if hook.target_msg.is_displayed(): if not sent_msg: logger.debug("AutoHackMsg Sent") if t == 0: hook.target_msg.send_keys('You are hacked by {} {} {}.'.format( gv.APPNAME, gv.VERSION, gv.APPTYPE)) if t == 1: hook.target_msg.send_keys( 'http://github.com/sserve-kr/TypeSense') if t == 2: hook.target_msg_window_close.click() logger.debug("AutoHackMsg clicked") hook.target_msg_btn.click() sent_msg = True return
def __schedule_silent_periods(self): try: periods = self.nodes.get_silent_periods(socket.gethostname()) if not self.last_silent_periods or not compare_list(self.last_silent_periods, periods): schedule.clear() for period in periods: split_period = period.split('-') starting_time = dateutil.parser.parse(split_period[0]) end_time = dateutil.parser.parse(split_period[1]) schedule.every().day.at(starting_time.strftime("%H:%M")).do(self.__suspend_media_processing) schedule.every().day.at(end_time.strftime("%H:%M")).do(self.__resume_media_processing) self.last_silent_periods = periods logger.debug("new silent periods rescheduled {}".format(periods)) schedule.run_pending() except Exception: logger.debug('no silent periods configured')
def main(): """ Main system startup. """ logger.debug("In main...") # Command line args... parseArgs() # Set up... setup() # Init... initialize() # Run... run()
def setup(): """ Sets the application up """ logger.debug("In setup...") # Set up the database db.setup() # First configure the main CP server with default, and optional site local # configs for cfg in configFiles('server', required=True): cherrypy.config.update(cfg) # Add the API app import api # Set it up app = api.setup()
def on_any_event(self, event): if not event.is_directory \ and match_path(event.src_path, included_patterns=self.include_pattern, excluded_patterns=self.exclude_pattern, case_sensitive=self.case_sensitive) \ and event.event_type == EVENT_TYPE_CREATED: try: file_path = event.src_path.decode('utf-8') media_file = self.add_to_processing_queue(file_path) if media_file: logger.info("File [{}] added to processing queue".format( media_file.identifier)) logger.debug(media_file) except Exception: logger.exception( "An error occurred during adding of [{}] to processing queue" .format(file_path))
def findLatestDate( path ): ''' Finds the latest date of modify of any file in a directory structure ''' logger.debug( "finding latest file mtime in %s" % path ) if not str(ENABLECACHING).lower() in [ 'true', '1', 'on', 'enabled' ]: logger.debug( "caching is disabled in the configuration file" ) return -1 if not os.path.exists( path ): logger.error( "failed to determinate last modified date; path \'%s\' does not exist" % path ) return -1 out = subprocess.Popen( shlex.split("find %s -type f -printf \"%%T@\n\"" % path ), stdout = subprocess.PIPE ).communicate()[0] maxd = -1 for i in out.split('\n'): if i.strip() and float(i) > maxd: maxd = float(i) return maxd
def __init__(self): logger.debug('call: providerbase.__init__') logger.debug('register_provider: name=%s, class=%s' % (self._name, self.__class__.__name__)) valid_chars = 'abcdefghijklmnopqrstuvwxyz0123456789_-' if not isinstance(self._name, (str, unicode)): raise ValueError('proto_name should be a string.') proto_name = self._name.lower() for ch in proto_name: if ch not in valid_chars: raise ValueError('Invalid char %s in proto_name' % ch) global providers if proto_name in providers: raise KeyError('provider is already registered by %s' % providers[proto_name].__class__.__name__) providers[proto_name] = self self._name = proto_name
def __init__(self, parent=None): QtCore.QSettings.__init__(self, '/home/' + os.getenv( 'USER' ) + '/.heysms', 0, parent) self.parent = parent self.last_authorized_bonjour_contact = self.value("last_authorized_bonjour_contact", '') if isinstance(self.last_authorized_bonjour_contact, tuple): self.last_authorized_bonjour_contact, _ = self.last_authorized_bonjour_contact # Compatibility mode self.use_smssend = self.value("use_smssend", QtCore.Qt.Unchecked).toInt() ## Useless ... I think ... if isinstance(self.use_smssend, tuple): self.use_smssend, _ = self.use_smssend # toggle_profile self.manage_profile = self.value("manage_profile", QtCore.Qt.Unchecked).toInt() ## Useless ... I think ... if isinstance(self.manage_profile, tuple): self.manage_profile, _ = self.manage_profile # startup_friends raw_friends = self.value("startup_friends", []) self.startup_friends = [str(i.toString()) for i in raw_friends.toList()] # start network usb self.useusb = self.value("use_usb", QtCore.Qt.Unchecked).toInt() ## Useless ... I think ... if isinstance(self.useusb, tuple): self.useusb, _ = self.useusb # start controler self.usecontroler = self.value("use_controller", QtCore.Qt.Unchecked).toInt() ## Useless ... I think ... if isinstance(self.usecontroler, tuple): self.usecontroler, _ = self.usecontroler # language # TODO AUTODETECTION for default default_lang = os.environ['LANG'].split("_")[0] if not default_lang in languages.values(): default_lang = "en" self.language = self.value("language", default_lang).toString() logger.debug("Language: %s" % self.language)
def _perform_auth(self, otp_token=None): if otp_token is None: try: self.user = raw_input('Username: '******'user: '******'Password: '******'password ok.') except KeyboardInterrupt: logger.warn('Ctrl-C detected.') sys.exit(1) user = self.user pwd = self.pwd logger.info('auth: fetch new token') post_json = { 'scopes' : ['gist'], 'note' : 'paste.py @ ' + str(datetime.datetime.now()), 'note_url' : 'https://github.com/jackyyf/paste.py', } post_headers = { 'Content-Type' : 'application/json', } if otp_token is not None: post_headers['X-GitHub-OTP'] = otp_token post_str = json.dumps(post_json) post_url = _api_base + '/authorizations' logger.debug('post_url: ' + post_url) try: resp = self.req.post(post_url, data=post_str, headers=post_headers, auth=(user, pwd)) except exceptions.RequestException as e: raise exception.ServerException(e) logger.info('http ok. response: %d %s' % (resp.status_code, resp.reason)) if resp.status_code == 201: logger.info('auth ok.') token = resp.json()[u'token'] logger.debug(resp.content) self.req.headers['Authorization'] = 'token ' + token return token elif resp.status_code == 401: # Two factor auth? logger.warn('auth failed') if 'X-GitHub-OTP' in resp.headers: logger.warn('auth: two-factor required') try: token = raw_input('Two factor token from ' + resp.headers['X-Github-OTP'].replace('required; ', '') + ':') except KeyboardInterrupt: logger.warn('Ctrl-C detected') sys.exit(1) return self._perform_auth(otp_token=token) else: logger.error('username or password error.') return self._perform_auth() else: raise exception.ServerException('Server responsed with unknown status: %d %s' % (resp.status_code, resp.reason))
def content( userName = '', accessLevel = '', newUrl = '', command = '', queryString = '', postData = '', cookies = '', uploadFile = '' ): ''' login module for user authentication ''' authLevel = NO_ACCESS key = '' cookieCnt = COOKIENAME + ( COOKIESTRING % 'None' ) returnStatus = HTTP_STATUS_STRING % utils.httpStatus( 301 ) if 'username' in postData: if 'password' in postData: users = utils.getUsers() for user in users: if ( user == postData['username'][0] and users[user] == hashlib.sha224(postData['password'][0]).hexdigest()): logger.debug(" found user/pw in user list") key = auth.openSession( user, RW_ACCESS ) authLevel = RW_ACCESS cookieCnt = COOKIENAME + COOKIESTRING % ( user + ":" + key ) break if authLevel == NO_ACCESS: responseHeaders = [ ( 'Location', '/sensee?status=invalid_credentials' ), ( 'Set-Cookie', cookieCnt), ] return responseHeaders, returnStatus, '' else: # save authentication session logger.debug(" cookieCnt: %s" % cookieCnt) responseHeaders = [ ( 'Location', '/sensee/index'+ '?' + urllib.unquote(urllib.urlencode(queryString, True))), ( 'Set-Cookie', cookieCnt), ] return responseHeaders, returnStatus, ''
def get(self, path, default=None): logger.debug('config get: ' + path) try: section, entry = path.rsplit('.', 1) except ValueError: section = 'DEFAULT' entry = path if section.lower() == 'default' : section = 'DEFAULT' if section != 'DEFAULT' and not self.rc.has_section(section): if default is Raise: raise exception.NoSuchOption('No such section: ' + section) return default try: return self.rc.get(section, entry) except ConfigParser.NoOptionError as e: if default is Raise: raise exception.NoSuchOption(e) return default
def add_starting_friends(self): friend_numbers = config.startup_friends for number in friend_numbers: logger.debug("This is a starting friend: %s" % number) fullname = search_contact_by_number(number) # Save it ! while self.parent.bonjour_auth_user == '': logger.debug("Waiting selection of an authorized bonjour contact") sleep(1) bonjour_auth_username = str(self.parent.bonjour_auth_user) auth_user = {bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username]} new_friend = Friend(fullname, number, auth_user) new_friend.favorite = True # Add to friend list in table model self.parent.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to friend list self.friend_list.append(new_friend) # Register it on bonjour new_friend.start()
def remove(self, path, check=False): logger.debug('remove key: ' + path) try: section, entry = path.rsplit('.', 1) except ValueError: section = 'DEFAULT' entry = path if section.lower() == 'default': section = 'DEFAULT' if section != 'DEFAULT' and not self.rc.has_section(section): if check: raise exception.NoSuchOption('No such section: ' + section) return res = self.rc.remove_option(section, entry) if check and not res: raise exception.NoSuchOption('No such config entry: ' + path) return res
def _do_auth(self, token=None): # Authenticate to github, save some login info (user/pass, or oauth token) conf = config.getConfig() auth = conf.getboolean('gist.auth', False) or token is not None if auth: # User/Pass Pair logger.info('auth: oauth token') if token is None: token = conf.require('gist.token') logger.debug('auth: test token usability') # Try authenticate self.req.headers['Authorization'] = 'token ' + token # Get a time in future (1 year) fmt_time = (datetime.datetime.now() + datetime.timedelta(days=365)).strftime('%Y-%m-%dT%H:%M:%SZ') test_url = _api_base + '/gists?since=' + fmt_time logger.debug('test url: ' + test_url) try: resp = self.req.get(test_url) except exceptions.RequestException as e: logger.warn('http error, assume token is good.') logger.info('[%s] %s' % (e.__class__.__name__, e.message)) return logger.debug('http ok, response: %d %s' % (resp.status_code, resp.reason)) if resp.status_code == 401: # Invalid token logger.warn('invalid token') return False elif resp.status_code == 200: logger.info('token ok.') return True else: logger.warn('unknown response status: %d %s' % (resp.status_code, resp.reason)) raise exception.ServerException('Server responsed with unknown status: %d %s' % (resp.status_code, resp.reason)) logger.info('auth: none') return None