def test_get_async(self): class TestEventedNDB(koalacore.NDBEventedInterface): _datastore_model = NDBTestModel _resource_object = TestModel test_new = TestModel(example=u'This is a test string') signal_tester = SignalTester() # Create signal refs hook_pre_get = signal(TestEventedNDB.HOOK_PRE_GET) hook_post_get = signal(TestEventedNDB.HOOK_POST_GET) # Subscribe to signals hook_pre_get.connect(signal_tester.hook_subscriber, sender=TestEventedNDB) hook_post_get.connect(signal_tester.hook_subscriber, sender=TestEventedNDB) # Trigger the datastore class to activate signals which have subscribers TestEventedNDB.parse_signal_receivers() insert_future = TestEventedNDB.insert_async(resource_object=test_new) insert_result = TestEventedNDB.get_future_result(future=insert_future) get_future = TestEventedNDB.get_async(resource_uid=insert_result) get_result = TestEventedNDB.get_future_result(future=get_future) self.assertEquals(get_result.example, u'This is a test string', u'Get async property mismatch.') self.assertEquals(len(signal_tester.hook_activations[TestEventedNDB]), 2, u'Get should trigger 2 hooks')
def __init__(self, event, nodeId, weight=1, initialV=Config.defV): ''' Constructor args: event: synchronizing event weight: the node weight initialV: the initial local statistics vector ''' #thread configuration threading.Thread.__init__(self) self.event=event self.runFlag=True #node data initialization self.id=nodeId self.inputGenerator=InputStream().getData() #data generator self.thresh=Config.threshold #monitoring threshold self.weight=weight #node weight self.v=initialV #local statistics vector self.vLast=self.v #last sent local statistics vector self.u=0 #drift vector self.e=0 #estimate vector self.delta=0 #slack vector #signal configuration signal('init').connect(self.init) signal('req').connect(self.req) signal('adj-slk').connect(self.adjSlk) signal('new-est').connect(self.newEst) signal('global-violation').connect(self.globalViolation) #DBG print('node %s created'%self.id)
def __init__(self, connection, scheduler): self.connection = connection signal('on_receive').connect(self.on_receive) self._curse_counter = { } print("Admin module initialized")
def test_delete_async(self): class TestEventedNDB(koalacore.NDBEventedInterface): _datastore_model = NDBTestModel _resource_object = TestModel test_new = TestModel(example=u'This is a test string') signal_tester = SignalTester() # Create signal refs hook_pre_delete = signal(TestEventedNDB.HOOK_PRE_DELETE) hook_post_delete = signal(TestEventedNDB.HOOK_POST_DELETE) # Subscribe to signals hook_pre_delete.connect(signal_tester.hook_subscriber, sender=TestEventedNDB) hook_post_delete.connect(signal_tester.hook_subscriber, sender=TestEventedNDB) # Trigger the datastore class to activate signals which have subscribers TestEventedNDB.parse_signal_receivers() insert_future = TestEventedNDB.insert_async(resource_object=test_new) insert_result = TestEventedNDB.get_future_result(future=insert_future) delete_future = TestEventedNDB.delete_async(resource_uid=insert_result) # doesn't return anything, but we still need to get the result delete_result = TestEventedNDB.get_future_result(future=delete_future) get_future = TestEventedNDB.get_async(resource_uid=insert_result) get_result = TestEventedNDB.get_future_result(future=get_future) self.assertEquals(get_result, None, u'Delete async failed to remove entity.') self.assertEquals(len(signal_tester.hook_activations[TestEventedNDB]), 2, u'Delete should trigger 2 hooks') self.assertEquals(len(signal_tester.filter_activations), 0, u'Delete should trigger 0 filters')
def _emit_deploy_event(self, last_deploy, new_deploy, clean=False, undeployed=None): """Emit events for all timeline entries newer than last deploy. last_deploy: datetime Time stamp of the last successful deployment. new_deploy: datetime Time stamp of the current deployment. clean: bool True when it appears like deploy is being run after a clean. """ event = { 'last_deploy': last_deploy, 'new_deploy': new_deploy, 'clean': clean, 'undeployed': undeployed } if last_deploy.tzinfo is None: last_deploy = last_deploy.replace(tzinfo=gettz('UTC')) deployed = [ entry for entry in self.site.timeline if entry.date > last_deploy and entry not in undeployed ] event['deployed'] = deployed if len(deployed) > 0 or len(undeployed) > 0: signal('deployed').send(event)
def cancel(self): """TODO: Docstring for cancel. :returns: TODO """ self.pack_forget() signal('langmaster.cancel').send()
def compile(self, lang): """Generate the cache/ file with the compiled post.""" dest = self.translated_base_path(lang) if not self.is_translation_available(lang) and not self.config['SHOW_UNTRANSLATED_POSTS']: return # Set the language to the right thing LocaleBorg().set_locale(lang) self.compile_html( self.translated_source_path(lang), dest, self.is_two_file, self, lang) Post.write_depfile(dest, self._depfile[dest], post=self, lang=lang) signal('compiled').send({ 'source': self.translated_source_path(lang), 'dest': dest, 'post': self, 'lang': lang, }) if self.publish_later: LOGGER.notice('{0} is scheduled to be published in the future ({1})'.format( self.source_path, self.date))
def compile(self, lang): """Generate the cache/ file with the compiled post.""" def wrap_encrypt(path, password): """Wrap a post with encryption.""" with io.open(path, "r+", encoding="utf8") as inf: data = inf.read() + "<!--tail-->" data = CRYPT.substitute(data=rc4(password, data)) with io.open(path, "w+", encoding="utf8") as outf: outf.write(data) dest = self.translated_base_path(lang) if not self.is_translation_available(lang) and not self.config["SHOW_UNTRANSLATED_POSTS"]: return # Set the language to the right thing LocaleBorg().set_locale(lang) self.compile_html(self.translated_source_path(lang), dest, self.is_two_file), signal("compiled").send({"source": self.translated_source_path(lang), "dest": dest, "post": self}) if self.meta("password"): # TODO: get rid of this feature one day (v8?; warning added in v7.3.0.) LOGGER.warn("The post {0} is using the `password` attribute, which may stop working in the future.") LOGGER.warn("Please consider switching to a more secure method of encryption.") LOGGER.warn("More details: https://github.com/getnikola/nikola/issues/1547") wrap_encrypt(dest, self.meta("password")) if self.publish_later: LOGGER.notice("{0} is scheduled to be published in the future ({1})".format(self.source_path, self.date))
def add_language(self): """TODO: Docstring for add_language. :returns: TODO """ self.pack_forget() signal('langmaster.new_lang').send(data=self.data)
def __init__(self, master): """TODO: to be defined1. :master: TODO """ tk.Frame.__init__(self, master) self.data = {} self.trainers = {} self.model_select = ComboBox(self, self.data, 'model', on_change=self.check, title='Model', options=[]) self.input_file = FileSelect(self, self.data, 'input_file', on_change=self.check, title='Select file for translation') self.input_file.pack({'side': 'top'}, fill=tk.X) self.output_file = FileSelect(self, self.data, 'output_file', on_change=self.check, save=True, title='Select file for saving translation') self.output_file.pack({'side': 'top'}, fill=tk.X) self.btn_trans = create_btn(self, 'Translate', self.translate) self.btn_back = create_btn(self, 'Back', self.back) self.btn_trans['state'] = tk.DISABLED signal('translator.show').connect(self.on_show)
def back(self): """TODO: Docstring for back. :returns: TODO """ self.pack_forget() signal('translator.back').send()
def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast): self.log.debug("OnRspUserLogin") self.log.debug(pRspUserLogin) self.log.debug(pRspInfo) self.log.debug(nRequestID) self.log.debug(bIsLast) signal("OnRspUserLogin").send(self, pRspUserLogin = pRspUserLogin, pRspInfo = pRspInfo, nRequestID = nRequestID, bIsLast = bIsLast)
def OnRspUserLogout(self, pUserLogout, pRspInfo, nRequestID, bIsLast): self.log.debug("OnRspUserLogout") self.log.debug(pUserLogout) self.log.debug(pRspInfo) self.log.debug(nRequestID) self.log.debug(bIsLast) signal("OnRspUserLogout").send(self, pUserLogout = pUserLogout, pRspInfo = pRspInfo, nRequestID = nRequestID, bIsLast = bIsLast)
def save(self, data): item=data[1] html=data[0] filename = item.get_output_path() new_directory = os.path.dirname(filename) if html == False: return False try: sig = signal('wranglerBeforeSaveItem') sig.send('item', item=item, path=filename) util.ensure_dir(new_directory) file_object = open(filename, "w") file_object.write(html.encode('utf8')) self.reporter.print_stdout(item.get_file_path(), filename, item.get_template()) item.on_save() siggy = signal('wranglerOnSaveItem') siggy.send('item', item=item, path=filename) except: print messages.file_write_error % (filename) traceback.print_exc() self.reporter.log_item_saved(item.get_file_path(), item.get_template(), 0) return False finally: self.reporter.log_item_saved(item.get_file_path(), item.get_template(), 1) return True
def OnRspUnSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID, bIsLast): self.log.debug("OnRspUnSubMarketData") self.log.debug(pSpecificInstrument) self.log.debug(pRspInfo) self.log.debug(nRequestID) self.log.debug(bIsLast) signal("OnRspUnSubMarketData").send(self, pSpecificInstrument = pSpecificInstrument, pRspInfo = pRspInfo, nRequestID = nRequestID, bIsLast = bIsLast)
def _sub(table): for action in ("write", "update", "delete"): def _sub(pk, action=action): msg = "%s_%s %s" % (table, action, pk) pub_socket.send_string(msg) logger.debug("pub msg: %s" % msg) signal("%s_%s" % (table, action)).connect(_sub, weak=False)
def _render_classification_overview(self, classification_name, template, lang, context, kw): # Prepare rendering context["permalink"] = self.site.link("{}_index".format(classification_name), None, lang) if "pagekind" not in context: context["pagekind"] = ["list", "tags_page"] output_name = os.path.join(self.site.config['OUTPUT_FOLDER'], self.site.path('{}_index'.format(classification_name), None, lang)) blinker.signal('generate_classification_overview').send({ 'site': self.site, 'classification_name': classification_name, 'lang': lang, 'context': context, 'kw': kw, 'output_name': output_name, }) task = self.site.generic_post_list_renderer( lang, [], output_name, template, kw['filters'], context, ) task['uptodate'] = task['uptodate'] + [utils.config_changed(kw, 'nikola.plugins.task.taxonomies:page')] task['basename'] = str(self.name) yield task
def open_train_master(self): """TODO: Docstring for open_train_master. :returns: TODO """ self.btn_frame.pack_forget() signal("trainmaster.show").send()
def update(self, *fields): """ Update this document. Optionally a specific list of fields to update can be specified. """ from mongoframes.queries import to_refs assert '_id' in self._document, "Can't update documents without `_id`" # Send update signal signal('update').send(self.__class__, frames=[self]) # Check for selective updates if len(fields) > 0: document = {} for field in fields: document[field] = self._path_to_value(field, self._document) else: document = self._document # Prepare the document to be updated document = to_refs(document) document.pop('_id', None) # Update the document self.get_collection().update_one({'_id': self._id}, {'$set': document}) # Send updated signal signal('updated').send(self.__class__, frames=[self])
def _generate_classification_page(self, taxonomy, classification, post_list, lang): """Render index or post list and associated feeds per classification.""" # Filter list filtered_posts = self._filter_list(post_list, lang) if len(filtered_posts) == 0 and taxonomy.omit_empty_classifications: return # Should we create this list? generate_list = taxonomy.should_generate_classification_page(classification, filtered_posts, lang) generate_rss = taxonomy.should_generate_rss_for_classification_page(classification, filtered_posts, lang) if not generate_list and not generate_rss: return # Get data node = None if taxonomy.has_hierarchy: node = self.site.hierarchy_lookup_per_classification[taxonomy.classification_name][lang][classification] context, kw = taxonomy.provide_context_and_uptodate(classification, lang, node) kw = copy(kw) kw["messages"] = self.site.MESSAGES kw["translations"] = self.site.config['TRANSLATIONS'] kw["filters"] = self.site.config['FILTERS'] kw["site_url"] = self.site.config['SITE_URL'] kw["blog_title"] = self.site.config['BLOG_TITLE'] kw["generate_rss"] = self.site.config['GENERATE_RSS'] kw["feed_teasers"] = self.site.config["FEED_TEASERS"] kw["feed_plain"] = self.site.config["FEED_PLAIN"] kw["feed_links_append_query"] = self.site.config["FEED_LINKS_APPEND_QUERY"] kw["feed_length"] = self.site.config['FEED_LENGTH'] kw["output_folder"] = self.site.config['OUTPUT_FOLDER'] kw["pretty_urls"] = self.site.config['PRETTY_URLS'] kw["strip_indexes"] = self.site.config['STRIP_INDEXES'] kw["index_file"] = self.site.config['INDEX_FILE'] context = copy(context) context["permalink"] = self.site.link(taxonomy.classification_name, classification, lang) blinker.signal('generate_classification_page').send({ 'site': self.site, 'taxonomy': taxonomy, 'classification': classification, 'lang': lang, 'posts': filtered_posts, 'context': context, 'kw': kw, }) # Decide what to do if taxonomy.has_hierarchy and taxonomy.show_list_as_subcategories_list: # Determine whether there are subcategories node = self.site.hierarchy_lookup_per_classification[taxonomy.classification_name][lang][classification] # Are there subclassifications? if len(node.children) > 0: # Yes: create list with subclassifications instead of list of posts if generate_list: yield self._generate_subclassification_page(taxonomy, node, context, kw, lang) return # Generate RSS feed if generate_rss and kw["generate_rss"] and not taxonomy.always_disable_rss: yield self._generate_classification_page_as_rss(taxonomy, classification, filtered_posts, context['title'], context.get("description"), kw, lang) # Render HTML if generate_list and taxonomy.show_list_as_index: yield self._generate_classification_page_as_index(taxonomy, classification, filtered_posts, context, kw, lang) elif generate_list: yield self._generate_classification_page_as_list(taxonomy, classification, filtered_posts, context, kw, lang)
def open_trans(self): """TODO: Docstring for open_trans. :returns: TODO """ self.btn_frame.pack_forget() signal("translator.show").send(trainers=self.conf.get("trainers", {}))
def _session_pub(self, event, objs): if not objs: return for obj in objs: sg_name = '{table}_{event}'.format(table=obj.__tablename__, event=event) signal(sg_name).send(obj)
def initialize(self, **kwargs): """ This initializes an instance of the scommands modification and it will remain loaded in memory until the server owner either unloads it or reloads it which therefore will reset any associated data unless the data had been defined on the class definition itself rather than being initialized in this function. Keyword arguments: * config -- This is the instance of Settings that contains all loaded configuration settings available for this modification, if the file exists. If the file does not exist, then this will simply be None. * interface -- This is the instance of the user interface used internally by ScalyMUCK. Generally, you won't need access to this for any reason and is currently deprecated for later removal. Actions such as binding your Blinker signals should be performed here so that events will be received properly when they occur. Along with initializing the modification, __init__ acts as a gateway for other important data passed in by the modloader under the **kwargs argument. """ self.config = kwargs['config'] self.interface = kwargs['interface'] self.session = kwargs['session'] self.world = kwargs['world'] self.permissions = kwargs['permissions'] self.modloader = kwargs['modloader'] signal('post_client_authenticated').connect(self.callback_client_authenticated) signal('pre_message_sent').connect(self.callback_message_sent)
def load_tasks(self, cmd, opt_values, pos_args): """Load Nikola tasks.""" if self.quiet: DOIT_CONFIG = { 'verbosity': 0, 'reporter': 'zero', } else: DOIT_CONFIG = { 'reporter': ExecutedOnlyReporter, 'outfile': sys.stderr, } DOIT_CONFIG['default_tasks'] = ['render_site', 'post_render'] DOIT_CONFIG.update(self.nikola._doit_config) try: tasks = generate_tasks( 'render_site', self.nikola.gen_tasks('render_site', "Task", 'Group of tasks to render the site.')) latetasks = generate_tasks( 'post_render', self.nikola.gen_tasks('post_render', "LateTask", 'Group of tasks to be executed after site is rendered.')) signal('initialized').send(self.nikola) except Exception: LOGGER.error('Error loading tasks. An unhandled exception occurred.') if self.nikola.debug or self.nikola.show_tracebacks: raise _print_exception() sys.exit(3) return tasks + latetasks, DOIT_CONFIG
def run(self): """ Execute each task in a Task thread. """ # execute each task in sequence for name, func, args, kwargs in self.tasks: task = Task(self, name, func, args, kwargs) self.tasks_by_uid[task.uid] = task result = yield self.runTask(task) # tasks will return an Exception is there was a failure if isinstance(result, BaseException): # wrap it so the runner recognizes this as an expected exception # and doesn't emit generic worker exception signals e = TaskError("Task `{}` failed.".format(name)) e.task = task e.failure = result raise e # otherwise it may optionally return a completion value elif self.all_tasks and not (result or task.has_output): e = TaskError("Task returned empty result.") e.task = task e.failure = e raise e else: signal('task_finish').send(self, task=task, result=result)
def publish_file(self, repo, filename, branch='master'): """ Publish a single file to GitHub. Args: repo (github3.repos.repo.Repository): Repository object for the GitHub repository that contains the state's files. filename (string): Local filename of results file to be published. branch (string): Name of git branch where the files will be published. """ pre_publish = signal('pre_publish') post_publish = signal('post_publish') pre_publish.send(self.__class__, filename=filename) path = self.get_path(filename) with open(filename, 'r') as f: content = f.read() sha = self.get_sha(repo, path, branch) if sha: # Update file msg = "Update file {}".format(path) result = repo.update_file(path, msg, content, sha) else: # Create file msg = "Create file {}".format(path) result = repo.create_file(path, msg, content) post_publish.send(self.__class__, filename=filename)
def __init__(self): """ Data model of a strip of LED's and also handles processes received data packets. :return: """ self.grid_size = Vector2(config.get("GRID_SIZE")) # self.pixel_count = int(self.grid_size.x * self.grid_size.y) self.pixel_count = globals.mapping_data.pixel_count # setup initial pixel data size = self.pixel_count * 4 self.data = bytearray(size) self.clear_data() self.spi_index = 0 # current pixel index of the spi_in function self.updated = None # datetime of last time start frame was received self.packet_length = 0 # count of number of individual bytes received since last start frame was received. self._dirty = True # keep track if data has been changed since last update call # cache blinker signals self._signal_startrecv = blinker.signal("stripdata.startrecv") self._signal_updated = blinker.signal("stripdata.updated") self.header_bytes_found = 0 self.buffer_count = 0 self.buffer = bytearray((0xFF, 0xFF, 0xFF, 0xFF))
def _register(self): if self.password: self.writeln("PASS {}".format(self.password)) self.writeln("USER {0} {1} {0} :{2}".format(self.user, self.mode, self.realname)) self.writeln("NICK {}".format(self.nick)) signal("registration-complete").send(self) self.nickname = self.nick
def __init__(self,name): self.Name = name self.IsDealer = False self.Hand = [] self.__Points = 0 self.OnAddedPoints = signal(SignalNames.OnAddPoints) self.OnPlayerWon = signal(SignalNames.OnPlayerWon)
def __init__(self, event, nodeNum): ''' Constructor args: event: synchronizing event nodes: a node object list ''' #thread configuration-synchronization self.event=event self.lock=threading.Lock() #coordinator data initialization self.nodeNum=nodeNum #network node number self.nodes={} #network node dictionary{key is nodeId:value is weight} self.thresh=Config.threshold #monitoring threshold self.v=0 #global statistics vector self.e=0 #estimate vector self.balancingSet=set() #balancing set (set of tuples) (nodeId,v_value,u_value}) self.balancingNodeIdSet=set() #balancing set containing only nodeIds self.requestedNode=None #requested node flag #helper self.counter=0 #signal configuration signal('init-node').connect(self.init) signal('rep').connect(self.nodeRep) #experimental results self.expCounter=0
import logging import random from blinker import signal loop = asyncio.get_event_loop() connections = {} plugins = [] def plugin_registered_handler(plugin_name): plugins.append(plugin_name) signal("plugin-registered").connect(plugin_registered_handler) class User: """ Represents a user on IRC, with their nickname, username, and hostname. """ def __init__(self, nick, user, host): self.nick = nick self.user = user self.host = host self.hostmask = "{}!{}@{}".format(nick, user, host) self._register_wait = 0 @classmethod
import os import re import time import datetime import web import io import ast import gv from helpers import * from gpio_pins import set_output from sip import template_render from blinker import signal loggedin = signal('loggedin') def report_login(): loggedin.send() value_change = signal('value_change') def report_value_change(): value_change.send() option_change = signal('option_change')
def stderr(self, thread_name, data=None): task = self.tasks_by_uid[thread_name] task.has_output = True signal('worker_stderr').send(self, data=data)
load_settings() raise web.seeother(u"/") # Return user to home page. ### Control valves ### def modify_zone_change(name, **kw): global prior_virt if gv.sd[u'seq']: # if in sequential mode. virtuals = gv.srvals[-8:] virt = next((i for i, x in enumerate(virtuals) if x), None) if (virt is not None and virt != prior_virt): prior_virt = virt set_stations(virt) zones = signal(u"zone_change") zones.connect(modify_zone_change) ### Clear prior_virt after all stations have run ### def clear_prior_virt(name, **kw): global prior_virt if not any(gv.srvals): prior_virt = None complete = signal(u"station_completed") complete.connect(clear_prior_virt) # Run when plugin is loaded load_settings()
# -*- coding: utf-8 -*- from __future__ import print_function, unicode_literals from blinker import signal # Run-level signals: initialized = signal('pelican_initialized') get_generators = signal('get_generators') all_generators_finalized = signal('all_generators_finalized') get_writer = signal('get_writer') finalized = signal('pelican_finalized') # Reader-level signals readers_init = signal('readers_init') # Generator-level signals generator_init = signal('generator_init') article_generator_init = signal('article_generator_init') article_generator_pretaxonomy = signal('article_generator_pretaxonomy') article_generator_finalized = signal('article_generator_finalized') article_generator_write_article = signal('article_generator_write_article') article_writer_finalized = signal('article_writer_finalized') page_generator_init = signal('page_generator_init') page_generator_finalized = signal('page_generator_finalized') page_writer_finalized = signal('page_writer_finalized')
def connection_made(self, transport): self.transport = transport signal("connected").send(self) self.logger.info("Connection success.") self.process_queue()
def connection_lost(self, exc): if not self.work: return self.logger.critical("Connection lost.") signal("connection-lost").send(self.wrapper)
import gzip import os.path import bz2file as bz2 import codecs import logging import six import xml.etree.cElementTree as ET from unicodecsv import DictReader # To add stats collection in inobstrusive way (that can be simply disabled) from blinker import signal sys.stdout = codecs.getwriter('utf-8')(sys.stdout) doubleform_signal = signal('doubleform-found') strip_func = unicode.strip if six.PY2 else str.strip def open_any(filename): """ Helper to open also compressed files """ if filename.endswith(".gz"): return gzip.open if filename.endswith(".bz2"): return bz2.BZ2File return open
def set_site(self, site): self.site = site self.logger = get_logger(self.name, self.site.loghandlers) ready = signal('deployed') ready.connect(self.run_hooks)
print 'error importing GPIO pins into helpers' pass try: import json except ImportError: try: import simplejson as json except ImportError: print _("Error: json module not found") sys.exit() ############################## #### Function Definitions #### station_completed = signal('station_completed') def report_station_completed(station): """ Send blinker signal indicating that a station has completed. Include the station number as data. """ station_completed.send(station) stations_scheduled = signal('stations_scheduled') def report_stations_scheduled(txt=None): """
def _generate_classification_page(self, taxonomy, classification, filtered_posts, generate_list, generate_rss, lang, post_lists_per_lang, classification_set_per_lang=None): """Render index or post list and associated feeds per classification.""" # Should we create this list? if not generate_list and not generate_rss: return # Get data node = None if taxonomy.has_hierarchy: node = self.site.hierarchy_lookup_per_classification[taxonomy.classification_name][lang].get(classification) context, kw = taxonomy.provide_context_and_uptodate(classification, lang, node) kw = copy(kw) kw["messages"] = self.site.MESSAGES kw["translations"] = self.site.config['TRANSLATIONS'] kw["filters"] = self.site.config['FILTERS'] kw["site_url"] = self.site.config['SITE_URL'] kw["blog_title"] = self.site.config['BLOG_TITLE'] kw["generate_rss"] = self.site.config['GENERATE_RSS'] kw["feed_teasers"] = self.site.config["FEED_TEASERS"] kw["feed_plain"] = self.site.config["FEED_PLAIN"] kw["feed_links_append_query"] = self.site.config["FEED_LINKS_APPEND_QUERY"] kw["feed_length"] = self.site.config['FEED_LENGTH'] kw["output_folder"] = self.site.config['OUTPUT_FOLDER'] kw["pretty_urls"] = self.site.config['PRETTY_URLS'] kw["strip_indexes"] = self.site.config['STRIP_INDEXES'] kw["index_file"] = self.site.config['INDEX_FILE'] context = copy(context) context["permalink"] = self.site.link(taxonomy.classification_name, classification, lang) context["kind"] = taxonomy.classification_name # Get links to other language versions of this classification if classification_set_per_lang is not None: other_lang_links = taxonomy.get_other_language_variants(classification, lang, classification_set_per_lang) # Collect by language links_per_lang = defaultdict(list) for other_lang, link in other_lang_links: # Make sure we ignore the current language (in case the # plugin accidentally returns links for it as well) if other_lang != lang: links_per_lang[other_lang].append(link) # Sort first by language, then by classification sorted_links = [] sorted_links_all = [] for other_lang in sorted(list(links_per_lang.keys()) + [lang]): if other_lang == lang: sorted_links_all.append((lang, classification, taxonomy.get_classification_friendly_name(classification, lang))) else: links = hierarchy_utils.sort_classifications(taxonomy, links_per_lang[other_lang], other_lang) links = [(other_lang, other_classification, taxonomy.get_classification_friendly_name(other_classification, other_lang)) for other_classification in links if post_lists_per_lang[other_lang].get(other_classification, ('', False, False))[1]] sorted_links.extend(links) sorted_links_all.extend(links) # Store result in context and kw context['has_other_languages'] = True context['other_languages'] = sorted_links context['all_languages'] = sorted_links_all kw['other_languages'] = sorted_links kw['all_languages'] = sorted_links_all else: context['has_other_languages'] = False # Allow other plugins to modify the result blinker.signal('generate_classification_page').send({ 'site': self.site, 'taxonomy': taxonomy, 'classification': classification, 'lang': lang, 'posts': filtered_posts, 'context': context, 'kw': kw, }) # Decide what to do if taxonomy.has_hierarchy and taxonomy.show_list_as_subcategories_list: # Determine whether there are subcategories node = self.site.hierarchy_lookup_per_classification[taxonomy.classification_name][lang][classification] # Are there subclassifications? if len(node.children) > 0: # Yes: create list with subclassifications instead of list of posts if generate_list: yield self._generate_subclassification_page(taxonomy, node, context, kw, lang) return # Generate RSS feed if generate_rss and kw["generate_rss"] and not taxonomy.always_disable_rss: yield self._generate_classification_page_as_rss(taxonomy, classification, filtered_posts, context['title'], context.get("description"), kw, lang) # Render HTML if generate_list and taxonomy.show_list_as_index: yield self._generate_classification_page_as_index(taxonomy, classification, filtered_posts, context, kw, lang) elif generate_list: yield self._generate_classification_page_as_list(taxonomy, classification, filtered_posts, context, kw, lang)
class Dataset(WithMetrics, BadgeMixin, db.Owned, db.Document): created_at = DateTimeField(verbose_name=_('Creation date'), default=datetime.now, required=True) last_modified = DateTimeField(verbose_name=_('Last modification date'), default=datetime.now, required=True) title = db.StringField(required=True) acronym = db.StringField(max_length=128) # /!\ do not set directly the slug when creating or updating a dataset # this will break the search indexation slug = db.SlugField(max_length=255, required=True, populate_from='title', update=True, follow=True) description = db.StringField(required=True, default='') license = db.ReferenceField('License') tags = db.TagListField() resources = db.ListField(db.EmbeddedDocumentField(Resource)) private = db.BooleanField(default=False) frequency = db.StringField(choices=list(UPDATE_FREQUENCIES.keys())) frequency_date = db.DateTimeField(verbose_name=_('Future date of update')) temporal_coverage = db.EmbeddedDocumentField(db.DateRange) spatial = db.EmbeddedDocumentField(SpatialCoverage) ext = db.MapField(db.GenericEmbeddedDocumentField()) extras = db.ExtrasField() featured = db.BooleanField(required=True, default=False) deleted = db.DateTimeField() archived = db.DateTimeField() def __str__(self): return self.title or '' __badges__ = { PIVOTAL_DATA: _('Pivotal data'), } __search_metrics__ = Object(properties={ 'reuses': Integer(), 'followers': Integer(), 'views': Integer(), }) __metrics_keys__ = [ 'discussions', 'issues', 'reuses', 'followers', 'views', ] meta = { 'indexes': [ '-created_at', 'slug', 'resources.id', 'resources.urlhash', ] + db.Owned.meta['indexes'], 'ordering': ['-created_at'], 'queryset_class': DatasetQuerySet, } before_save = signal('Dataset.before_save') after_save = signal('Dataset.after_save') on_create = signal('Dataset.on_create') on_update = signal('Dataset.on_update') before_delete = signal('Dataset.before_delete') after_delete = signal('Dataset.after_delete') on_delete = signal('Dataset.on_delete') on_archive = signal('Dataset.on_archive') on_resource_added = signal('Dataset.on_resource_added') verbose_name = _('dataset') @classmethod def pre_save(cls, sender, document, **kwargs): cls.before_save.send(document) @classmethod def post_save(cls, sender, document, **kwargs): if 'post_save' in kwargs.get('ignores', []): return cls.after_save.send(document) if kwargs.get('created'): cls.on_create.send(document) else: cls.on_update.send(document) if document.deleted: cls.on_delete.send(document) if document.archived: cls.on_archive.send(document) if kwargs.get('resource_added'): cls.on_resource_added.send(document, resource_id=kwargs['resource_added']) def clean(self): if self.frequency in LEGACY_FREQUENCIES: self.frequency = LEGACY_FREQUENCIES[self.frequency] def url_for(self, *args, **kwargs): return url_for('datasets.show', dataset=self, *args, **kwargs) display_url = property(url_for) @property def is_visible(self): return not self.is_hidden @property def is_hidden(self): return (len(self.resources) == 0 or self.private or self.deleted or self.archived) @property def full_title(self): if not self.acronym: return self.title return '{title} ({acronym})'.format(**self._data) @property def external_url(self): return self.url_for(_external=True) @property def image_url(self): if self.organization: return self.organization.logo.url elif self.owner: return self.owner.avatar.url @property def frequency_label(self): return UPDATE_FREQUENCIES.get(self.frequency or 'unknown', UPDATE_FREQUENCIES['unknown']) def check_availability(self): """Check if resources from that dataset are available. Return a list of (boolean or 'unknown') """ # Only check remote resources. remote_resources = [resource for resource in self.resources if resource.filetype == 'remote'] if not remote_resources: return [] return [resource.check_availability() for resource in remote_resources] @property def last_update(self): if self.resources: return max(resource.published for resource in self.resources) else: return self.last_modified @property def next_update(self): """Compute the next expected update date, given the frequency and last_update. Return None if the frequency is not handled. """ delta = None if self.frequency == 'daily': delta = timedelta(days=1) elif self.frequency == 'weekly': delta = timedelta(weeks=1) elif self.frequency == 'fortnighly': delta = timedelta(weeks=2) elif self.frequency == 'monthly': delta = timedelta(weeks=4) elif self.frequency == 'bimonthly': delta = timedelta(weeks=4 * 2) elif self.frequency == 'quarterly': delta = timedelta(weeks=52 / 4) elif self.frequency == 'biannual': delta = timedelta(weeks=52 / 2) elif self.frequency == 'annual': delta = timedelta(weeks=52) elif self.frequency == 'biennial': delta = timedelta(weeks=52 * 2) elif self.frequency == 'triennial': delta = timedelta(weeks=52 * 3) elif self.frequency == 'quinquennial': delta = timedelta(weeks=52 * 5) if delta is None: return else: return self.last_update + delta @cached_property def quality(self): """Return a dict filled with metrics related to the inner quality of the dataset: * number of tags * description length * and so on """ from udata.models import Discussion # noqa: Prevent circular imports result = {} if not self.id: # Quality is only relevant on saved Datasets return result if self.frequency != 'unknown': result['frequency'] = self.frequency if self.next_update: result['update_in'] = -(self.next_update - datetime.now()).days if self.tags: result['tags_count'] = len(self.tags) if self.description: result['description_length'] = len(self.description) if self.resources: result['has_resources'] = True result['has_only_closed_or_no_formats'] = all( resource.closed_or_no_format for resource in self.resources) result['has_unavailable_resources'] = not all( self.check_availability()) discussions = Discussion.objects(subject=self) if discussions: result['discussions'] = len(discussions) result['has_untreated_discussions'] = not all( discussion.person_involved(self.owner) for discussion in discussions) result['score'] = self.compute_quality_score(result) return result def compute_quality_score(self, quality): """Compute the score related to the quality of that dataset.""" score = 0 UNIT = 2 if 'update_in' in quality: # TODO: should be related to frequency. if quality['update_in'] < 0: score += UNIT else: score -= UNIT if 'tags_count' in quality: if quality['tags_count'] > 3: score += UNIT if 'description_length' in quality: if quality['description_length'] > 100: score += UNIT if 'has_resources' in quality: if quality['has_only_closed_or_no_formats']: score -= UNIT else: score += UNIT if quality['has_unavailable_resources']: score -= UNIT else: score += UNIT if 'discussions' in quality: if quality['has_untreated_discussions']: score -= UNIT else: score += UNIT if score < 0: return 0 return score @classmethod def get(cls, id_or_slug): obj = cls.objects(slug=id_or_slug).first() return obj or cls.objects.get_or_404(id=id_or_slug) def add_resource(self, resource): '''Perform an atomic prepend for a new resource''' resource.validate() self.update(__raw__={ '$push': { 'resources': { '$each': [resource.to_mongo()], '$position': 0 } } }) self.reload() post_save.send(self.__class__, document=self, resource_added=resource.id) def update_resource(self, resource): '''Perform an atomic update for an existing resource''' index = self.resources.index(resource) data = { 'resources__{index}'.format(index=index): resource } self.update(**data) self.reload() post_save.send(self.__class__, document=self) @property def community_resources(self): return self.id and CommunityResource.objects.filter(dataset=self) or [] @cached_property def json_ld(self): result = { '@context': 'http://schema.org', '@type': 'Dataset', '@id': str(self.id), 'alternateName': self.slug, 'dateCreated': self.created_at.isoformat(), 'dateModified': self.last_modified.isoformat(), 'url': url_for('datasets.show', dataset=self, _external=True), 'name': self.title, 'keywords': ','.join(self.tags), 'distribution': [resource.json_ld for resource in self.resources], # Theses values are not standard 'contributedDistribution': [ resource.json_ld for resource in self.community_resources ], 'extras': [get_json_ld_extra(*item) for item in self.extras.items()], } if self.description: result['description'] = mdstrip(self.description) if self.license and self.license.url: result['license'] = self.license.url if self.organization: author = self.organization.json_ld elif self.owner: author = self.owner.json_ld else: author = None if author: result['author'] = author return result @property def views_count(self): return self.metrics.get('views', 0) def count_discussions(self): from udata.models import Discussion self.metrics['discussions'] = Discussion.objects(subject=self, closed=None).count() self.save() def count_issues(self): from udata.models import Issue self.metrics['issues'] = Issue.objects(subject=self, closed=None).count() self.save() def count_reuses(self): from udata.models import Reuse self.metrics['reuses'] = Reuse.objects(datasets=self).visible().count() self.save() def count_followers(self): from udata.models import Follow self.metrics['followers'] = Follow.objects(until=None).followers(self).count() self.save()
import signal import time import logging from concurrent import futures import grpc import blinker started = blinker.signal('server_started') stopped = blinker.signal('server_stopped') class Server: """sea server implements :param app: application instance """ def __init__(self, app): self.app = app self.setup_logger() self.workers = self.app.config.get('GRPC_WORKERS') self.host = self.app.config.get('GRPC_HOST') self.port = self.app.config.get('GRPC_PORT') self.server = grpc.server( futures.ThreadPoolExecutor( max_workers=self.workers)) self.server.add_insecure_port( '{}:{}'.format(self.host, self.port)) self._stopped = False
import os import sys import blinker from six.moves import configparser from tinydb import TinyDB, Query from tinydb_smartcache import SmartCacheTable # Main settings SETTINGS = {} # Database DB = None CONTACT = Query() # Signals SIGNAL_TG = blinker.signal('TO_TG') SIGNAL_WA = blinker.signal('TO_WA') def get_logger(name): """ Get a logger with the given name. """ # Base logger logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) # Handler to stdout handler = logging.StreamHandler() handler.setLevel(logging.DEBUG) # Formatting formatter = logging.Formatter(
class BasePlugin(object): """ This is the base class for all plugins. If you want to know, how to implement your own plugin, you should also take a look at the :mod:`plugins.hellodolly` plugin. """ #: Integer with the init priority of the plugin. #: A higher value results in a later initialisation. INIT_PRIORITY = 0 #: Integer with the finish priority of the plugin. #: A higher value results in a later call of the finish method. FINISH_PRIORITY = 0 #: The last version number of the EMSM version that worked correctly #: with that plugin. VERSION = "0.0.0" #: The plugin package can be downloaded from this url. #: #: .. seealso:: #: #: * :mod:`emsm.plugins.plugins` package manager DOWNLOAD_URL = str() #: This string is displayed when the ``--long-help`` argument is used. DESCRIPTION = str() #: If ``True``, the plugin has no :meth:`argparser` and can therefore #: not be invoked from the command line. HIDDEN = False #: Signal, that is emitted, when a plugin has been uninstalled. plugin_uninstalled = blinker.signal("plugin_uninstalled") def __init__(self, app, name): """ Initialises the configuration and the storage of the plugin. **Override:** * Extend, but do not override. """ log.info("initialising '{}' ...".format(name)) self.__app = app self.__name = name # Get the argparser for this plugin and set it up. if type(self).HIDDEN: self.__argparser = None else: self.__argparser = app.argparser().plugin_parser(name) self.__argparser.add_argument("--long-help", action=argparse_.LongHelpAction, description=type(self).DESCRIPTION) return None def app(self): """ Returns the parent EMSM :class:`~emsm.application.Application` that owns this plugin. """ return self.__app def name(self): """ Returns the name of the plugin. """ return self.__name def conf(self): """ Returns a dictionary like object that contains the configuration of the plugin. .. deprecated:: 4.0.16-beta This method has been replaced by :meth:`global_conf` to clarify the difference to :meth:`world_conf`. """ msg = "The BasePlugin.conf() method has been marked as deprecated. "\ "Please use BasePlugin.global_conf() instead." warnings.warn(msg, DeprecationWarning) return self.global_conf() def global_conf(self): """ Returns a dictionary like object, that contains the *global* configuration of the plugin (:file:`plugins.conf`). :seealso: :meth:`world_conf` """ # Make sure the configuration section exists. main_conf = self.__app.conf().main() if not self.__name in main_conf: log.info("creating configuration section for '%s' in '%s'.", self.__name, main_conf.path()) main_conf.add_section(self.__name) log.info("created configuration section for '%s' in '%s'.", self.__name, main_conf.path()) return main_conf[self.__name] def world_conf(self, world): """ Returns a dictionary like object, that contains the *world* specific configuration of the plugin (:file:`foo.world.conf`). :seealso: :meth:`global_conf` :arg world: The :class:`WorldWrapper` of the world or the world's name (str). """ # Get the world's name. world_name = world.name() if isinstance(world, WorldWrapper) else world # Make sure, the configuration section exists. conf = self.__app.conf().world(world_name) section_name = "plugin:{}".format(self.__name) if not section_name in conf: log.info("creating configuration section for '%s' in '%s'.", self.__name, conf.path()) conf.add_section(section_name) log.info("created configuration section for '%s' in '%s'.", self.__name, conf.path()) return conf[section_name] def data_dir(self, create=True): """ Returns the directory that contains all data created by the plugin to manage its EMSM job. :param bool create: If the directory does not exist, it will be created. .. seealso:: * :meth:`emsm.core.paths.Pathsystem.plugin_data_dir` """ data_dir = self.__app.paths().plugin_data(self.__name) # Make sure the directory exists. if not os.path.exists(data_dir) and create: log.info("creating data directory for '{}'.".format(self.__name)) os.makedirs(data_dir) log.info("created data directory for '{}'.".format(self.__name)) return data_dir def argparser(self): """ Returns the :class:`argparse.ArgumentParser` that is used by this plugin. If :attr:`HIDDEN` is ``True``, *None* is returned, since the plugin has no argument parser. .. seealso:: * :meth:`emsm.core.argparse_.ArgumentParser.plugin_parser` """ return self.__argparser def _uninstall(self): """ This method is called by *uninstall()* and should remove all data or configuration generated by the plugin. **Subclass:** * You may completly override this method. """ return None def uninstall(self): """ Called when the plugin should be uninstalled. This method is interactive and requires the user to confirm if and which data should be removed. The BasePlugin removes: * the plugin module (the *.py* file in *plugins*) * the plugin data directory * the plugin configuration **Subclass:** Subclasses should override the :meth:`_uninstall` method. **Signals:** * :attr:`plugin_uninstalled` .. seealso:: * :meth:`data_dir` * :meth:`conf` * :meth:`_uninstall` """ log.info("uninstalling '{}' ...".format(self.__name)) # Make sure the user really wants to uninstall the plugin. if not userinput.ask("Do you really want to remove '{}'?"\ .format(self.__name) ): # I did not want to implement a new exception type for this case. # I think KeyboardInterrupt is good enough. log.info("cancelled uninstallation of '{}'.".format(self.__name)) return None # Remove the python module that contains the plugin. plugin_module = self.__app.plugins().get_module(self.__name) if plugin_module: os.remove(plugin_module.__file__) log.info("removed '{}' module at '{}'."\ .format(self.__name, plugin_module.__file__) ) # Remove the plugin data directory. if userinput.ask("Do you want to remove the data directory?"): shutil.rmtree(self.data_dir(), True) log.info("removed '{}' plugin data directory at '{}'."\ .format(self.__name, self.data_dir(create=False)) ) # Remove the configuration. if userinput.ask("Do you want to remove the configuration?"): self.__app.conf().main().remove_section(self.__name) log.info("removed '{}' configuration section in '{}'."\ .format(self.__name, self.__app.conf().main().path()) ) # Remove the configuration section in every *.world.conf file. for world_conf in self.__app.conf().worlds(): world_conf.remove_section("plugin:" + self.name()) # Remove the subclass stuff. self._uninstall() # Emit the signal. BasePlugin.plugin_uninstalled.send(self) return None def run(self, args): """ The *main* method of the plugin. This method is called if the plugin has been invoked by the command line arguments. :params argparse.Namespace args: is an argparse.Namespace instance that contains the values of the parsed command line arguments. Subclass: * You may override this method. .. seealso:: * :meth:`argparser` * :meth:`emsm.core.argparse_.ArgumentParser.args` * :meth:`emsm.core.plugins.PluginManager.run` """ return None def finish(self): """ Called when the EMSM application is about to finish. This method can be used for background jobs or clean up stuff. Subclass: * You may override this method. .. seealso:: * :meth:`emsm.core.plugins.PluginManager.finish` """ return None
def __init__(self, context, filepath=None, metadata=None, content=None, basename=None): self.context = context if filepath is not None: # Get filenames, paths etc. dirname = os.path.dirname(filepath) basepath, filename = os.path.split(filepath) basename, extension = os.path.splitext(filename) relpath = os.path.relpath( os.path.join(dirname, basename) + '.html', context.SOURCE_FOLDER) # Parse the file for content and metadata with codecs.open(filepath, 'r', encoding='utf8') as md_file: raw_metadata, raw_content = md_parse_meta(md_file.read()) elif metadata is not None and content is not None and basename is not None: raw_content = content raw_metadata = metadata else: raise Exception( 'Article object not supplied with either filepath or content and metadata.' ) self.content = context.MD(raw_content) self.metadata = {} for key in raw_metadata: self.metadata[key.lower()] = raw_metadata[key].strip( ) if isinstance(raw_metadata[key], str) else raw_metadata[key] # Set article variables from metadata self.date = datetime.datetime.strptime(self.metadata['date'].strip( ), '%Y-%m-%d') if 'date' in self.metadata else datetime.datetime.now() self.type = self.metadata['type'].strip().lower( ) if 'type' in self.metadata else '' self.title = self.metadata[ 'title'] if 'title' in self.metadata else basename self.summary = context.MD( self.metadata['summary']) if 'summary' in self.metadata else '' self.location = self.metadata['location'].strip().lower( ) if 'location' in self.metadata else None status = self.metadata['status'].strip().lower( ) if 'status' in self.metadata else None if status == 'unlisted' or self.type == 'unlisted': self.status = ArticleStatus.UNLISTED elif status == 'draft': self.status = ArticleStatus.DRAFT else: self.status = ArticleStatus.ACTIVE # Work out other variables self.template = context.JINJA_ENV.get_template('article.html') self.source_filepath = filepath if self.date and self.location: output_filename = '{}-{}.html'.format( self.location.lower(), self.date.strftime('%Y-%m-%d')) else: output_filename = '{}.html'.format(basename) self.output_filepath = os.path.join(context.OUTPUT_FOLDER, 'articles', output_filename) self.url = 'articles/{}'.format(output_filename) signal_sender = signal(Signals.AFTER_ARTICLE_READ) signal_sender.send((context, self))
def on_mouse_wheel(event): signal('on_mouse_global_wheel').send(root, mouse_event=event)
from blinker import signal from celery import Celery from flask import Blueprint, request from settings import FACEBOOK_VERIFY_TOKEN, LOCAL_BROKER from .extensions import csrf from .models import Account bp = Blueprint('facebookhandler', __name__) app = Celery('tasks', broker=LOCAL_BROKER) fb_message = signal('facebook-message') fb_postback = signal('facebook-postback') @bp.route('/facebook', methods=['GET']) def verify(): if request.args.get('hub.mode') == 'subscribe' and request.args.get( 'hub.challenge'): if not request.args.get('hub.verify_token') == FACEBOOK_VERIFY_TOKEN: return 'Verification token mismatch', 403 return request.args['hub.challenge'], 200 return 'Hello world', 200 @bp.route('/facebook', methods=['POST']) @csrf.exempt def webhook():
from blinker import signal initialized = signal('pelican_initialized') finalized = signal('pelican_finalized') article_generate_context = signal('article_generate_context') article_generator_init = signal('article_generator_init') get_generators = signal('get_generators') pages_generate_context = signal('pages_generate_context') pages_generator_init = signal('pages_generator_init') content_object_init = signal('content_object_init')
def __init__(self, master): Frame.__init__(self, master) self.master = master self.place(relwidth=1, relheight=1) self.model = Model() # Top level menu self.menu_bar = Menu(master) master.config(menu=self.menu_bar) self.menu_file = Menu(self.menu_bar, tearoff=0) self.menu_file.add_command(label="Save As XML...", command = self.save_xml) self.menu_bar.add_cascade(label="File", menu=self.menu_file) # Left frame, which contains WeightPanel, part_number_filter and PartWeighingsPanel self.left_frame = Frame(self) self.left_frame.grid(row=0, column=0, sticky='ns') # Weight Panel (Inside left frame) self.weight_panel = WeightPanel(self.left_frame, self.model) self.weight_panel.grid(row=0, column=0, sticky='n', padx=5, pady=5) # Part number filer (Inside left frame) self.part_number_filter_txt = StringVar(self) self.part_number_filter_txt.trace('w', self.on_part_number_filter_txt_change) self.part_number_filter = Entry(self.left_frame, textvariable=self.part_number_filter_txt) self.part_number_filter.grid(row=1, column=0, sticky='we', padx=5) # Weighing clusters (Inside left frame too) self.weighings_panel = PartWeighingsPanel(self.left_frame) self.weighings_panel.grid(row=2, column=0, sticky='nwe', padx=5, pady=5) # Options Panel self.options_panel = OptionsPanel(self, self.model) self.options_panel.grid(row=3, column=0, sticky='s', padx=5, pady=10) # Center Frame self.part_images_grid = PartImagesGrid(self) self.part_images_grid.grid(row=0, rowspan=3, column=1, sticky='nswe', pady=10) self.part_info = PartInfoFrame(self) self.part_info.grid(row=3, column=1, sticky='we', padx=5, pady=10) self.grid_columnconfigure(1, weight=1) self.grid_columnconfigure(2, minsize=360) self.grid_rowconfigure(0, weight=1) # Part inventory list (Right Frame) self.right_frame = PartInventoryList(self, self.model.part_entry_list) self.right_frame.grid(row=0, column=2, rowspan=2, sticky='nsew', padx=5, pady=10) # Events signal('on_mouse_click_part').connect(self.on_mouse_click_part) signal('on_mouse_click_url').connect(self.on_mouse_click_url) signal('on_color_picker_closed').connect(self.on_color_picker_closed) signal('on_test_01').connect(self.on_test_01) self.check_new_weight_timer = self.after(30, self.check_new_weight)
self.zeroX = 0 self.zeroY = 0 [self.zeroX,self.zeroY] = self.measure(500) self.fromLevel.send(["raz",self.zeroX,self.zeroY]) if __name__ == '__main__': ## -------------------------------------------------------------- ## Description : echo data ## NOTE : ## - ## Author : jouke hylkema ## date : 30-03-2020 17:03:27 ## -------------------------------------------------------------- def gotData(data): print("=== LEVEL Data ===") for i in data: print("| %s: %s"%(i,data[i])) Level = myLevel(0,0) Level.start() signal('fromLevel').connect(gotData) Level.toLevel.send("start") cmd = input("Press key to quit") Level.Doit=False
from blinker import signal # This file houses plugin endpoints for aleph. These are called at various # times during the lifecycle of the server and can be used to hook in # extension functionality. # Register additional API endpoints. register_blueprints = signal('register_blueprints') # Handle OAuth return values. handle_oauth_session = signal('handle_oauth_session')
def stop_listening(cls, event, func): """Remove a callback for a signal against the class""" signal(event).disconnect(func, sender=cls)
from blinker import signal started = signal('test-started') def each(round): print('Round {}!'.format(round)) def round_two(round): print('Only {}'.format(round)) started.connect(each) started.connect(round_two, sender=2) for round in range(1, 4): started.send(round)
def set_site(self, site): """Set Nikola site object.""" super(StaticComments, self).set_site(site) site._GLOBAL_CONTEXT['site_has_static_comments'] = True blinker.signal("scanned").connect(self._process_posts_and_pages)
def _execute(self, options, args): """Create a new post or page.""" global LOGGER compiler_names = [ p.name for p in self.site.plugin_manager.getPluginsOfCategory( "PageCompiler") ] if len(args) > 1: print(self.help()) return False elif args: path = args[0] else: path = None # Even though stuff was split into `new_page`, it’s easier to do it # here not to duplicate the code. is_page = options.get('is_page', False) is_post = not is_page content_type = 'page' if is_page else 'post' title = options['title'] or None author = options['author'] or '' tags = options['tags'] onefile = options['onefile'] twofile = options['twofile'] import_file = options['import'] wants_available = options['available-formats'] if wants_available: self.print_compilers() return if is_page: LOGGER = PAGELOGGER else: LOGGER = POSTLOGGER if twofile: onefile = False if not onefile and not twofile: onefile = self.site.config.get('ONE_FILE_POSTS', True) content_format = options['content_format'] content_subformat = None if "@" in content_format: content_format, content_subformat = content_format.split("@") if not content_format: # Issue #400 content_format = get_default_compiler( is_post, self.site.config['COMPILERS'], self.site.config['post_pages']) if content_format not in compiler_names: LOGGER.error( "Unknown {0} format {1}, maybe you need to install a plugin?". format(content_type, content_format)) self.print_compilers() return compiler_plugin = self.site.plugin_manager.getPluginByName( content_format, "PageCompiler").plugin_object # Guess where we should put this entry = self.filter_post_pages(content_format, is_post) if entry is False: return 1 if import_file: print("Importing Existing {xx}".format(xx=content_type.title())) print("-----------------------\n") else: print("Creating New {xx}".format(xx=content_type.title())) print("-----------------\n") if title is not None: print("Title:", title) else: while not title: title = utils.ask('Title') if isinstance(title, utils.bytes_str): try: title = title.decode(sys.stdin.encoding) except (AttributeError, TypeError): # for tests title = title.decode('utf-8') title = title.strip() if not path: slug = utils.slugify(title) else: if isinstance(path, utils.bytes_str): try: path = path.decode(sys.stdin.encoding) except (AttributeError, TypeError): # for tests path = path.decode('utf-8') slug = utils.slugify(os.path.splitext(os.path.basename(path))[0]) if isinstance(author, utils.bytes_str): try: author = author.decode(sys.stdin.encoding) except (AttributeError, TypeError): # for tests author = author.decode('utf-8') # Calculate the date to use for the content schedule = options['schedule'] or self.site.config['SCHEDULE_ALL'] rule = self.site.config['SCHEDULE_RULE'] self.site.scan_posts() timeline = self.site.timeline last_date = None if not timeline else timeline[0].date date = get_date(schedule, rule, last_date, self.site.tzinfo, self.site.config['FORCE_ISO8601']) data = { 'title': title, 'slug': slug, 'date': date, 'tags': tags, 'link': '', 'description': '', 'type': 'text', } output_path = os.path.dirname(entry[0]) meta_path = os.path.join(output_path, slug + ".meta") pattern = os.path.basename(entry[0]) suffix = pattern[1:] if not path: txt_path = os.path.join(output_path, slug + suffix) else: txt_path = os.path.join(self.site.original_cwd, path) if (not onefile and os.path.isfile(meta_path)) or \ os.path.isfile(txt_path): # Emit an event when a post exists event = dict(path=txt_path) if not onefile: # write metadata file event['meta_path'] = meta_path signal('existing_' + content_type).send(self, **event) LOGGER.error("The title already exists!") return 8 d_name = os.path.dirname(txt_path) utils.makedirs(d_name) metadata = {} if author: metadata['author'] = author metadata.update(self.site.config['ADDITIONAL_METADATA']) data.update(metadata) # ipynb plugin needs the ipython kernel info. We get the kernel name # from the content_subformat and pass it to the compiler in the metadata if content_format == "ipynb" and content_subformat is not None: metadata["ipython_kernel"] = content_subformat # Override onefile if not really supported. if not compiler_plugin.supports_onefile and onefile: onefile = False LOGGER.warn('This compiler does not support one-file posts.') if import_file: with io.open(import_file, 'r', encoding='utf-8') as fh: content = fh.read() else: if is_page: content = self.site.MESSAGES[ self.site.default_lang]["Write your page here."] else: content = self.site.MESSAGES[ self.site.default_lang]["Write your post here."] compiler_plugin.create_post(txt_path, content=content, onefile=onefile, title=title, slug=slug, date=date, tags=tags, is_page=is_page, **metadata) event = dict(path=txt_path) if not onefile: # write metadata file with io.open(meta_path, "w+", encoding="utf8") as fd: fd.write(utils.write_metadata(data)) LOGGER.info("Your {0}'s metadata is at: {1}".format( content_type, meta_path)) event['meta_path'] = meta_path LOGGER.info("Your {0}'s text is at: {1}".format( content_type, txt_path)) signal('new_' + content_type).send(self, **event) if options['edit']: editor = os.getenv('EDITOR', '').split() to_run = editor + [txt_path] if not onefile: to_run.append(meta_path) if editor: subprocess.call(to_run) else: LOGGER.error( '$EDITOR not set, cannot edit the post. Please do it manually.' )
from collections import Counter, OrderedDict import glfw import OpenGL.GL as gl import operator import imgui import collections import blinker windowClosed = blinker.signal("windowClosed") def render_all(iterable, *args): """Quickly calls the _render method on an iterable of renderables. """ ret = map(operator.methodcaller('_render', args), iterable) # print(collections.deque(ret)) retLists = list(ret) # print(retLists) result = collections.defaultdict(list) # convert to dict for i in range(len(retLists)): for name, value in retLists[i].items(): result[name].append(value) return dict(result) class Desktop:
def listen(cls, event, func): """Add a callback for a signal against the class""" signal(event).connect(func, sender=cls)
from blinker import signal from app.feed.services import FeedService from app.feed.tasks import update_followers_feeds feed_post_added = signal('feed-post-added') @feed_post_added.connect def update_feeds(service: FeedService, **kwargs): post = kwargs.get('post') update_followers_feeds.delay(post.user_id, post.id)
def min_duration(name, **kw): """ Prevent program from running if run time is less than user defined minimum. """ # min = int(lwa_options[u"min_duration"]) min = (int(lwa_options[u"mrtm"]) * 60) + int(lwa_options[u"mrts"]) run_schedule = gv.rs for index, item in enumerate(run_schedule): if (any(item) and item[2] != 0 and item[2] < min): gv.rs[index][0] = gv.rs[index][1] gv.rs[index][2] = 0 gv.ps[index] = [0, 0] gv.sd[u"bsy"] = 0 scheduled = signal(u"stations_scheduled") scheduled.connect(min_duration) ################################################################################ # Info queries: # ################################################################################ def history_info(obj, curr_conditions, options): time_now = datetime.datetime.now() day_delta = datetime.timedelta(days=float(options[u"days_history"])) history = dict(curr_conditions) path = u"./data/weather_level_history"