示例#1
0
	def __init__(self):
		
		self.tasktypes = TaskCollection()
		for tasktype in self.tasktypes_iter():
			self.tasktypes[tasktype.ID] = tasktype

		events.publish(
			'TaskHiveCoordinator.TaskTypes.Changed'
			, self.tasktypes
		)

		self.taskhives = {}
		self.taskhives_lock = threading.Lock()
		for taskhive_data in storage.query(r'^TaskHive\..+'):
			taskhive_id = taskhive_data['id']
			self.taskhives[taskhive_id] = TaskHive( self.tasktypes, taskhive_data )

		# making listing of tasktypes available through pubsub system.
		events.subscribe('TaskHiveCoordinator.GetTaskTypes', self.get_tasktypes_metadata)

		events.publish(
			'Storage.On'
			, 'set'
			, r'^TaskHive\.'
			, self._hive_set_handler
		)
示例#2
0
	def __init__(self):
		self.storagebackend = StorageBackend_File()
		self.subscribers = {'change':{}, 'set':{}}

		self._change_lock = weakref.WeakValueDictionary()

		events.subscribe(
			'Storage.Set'
			, self.set
		)

		events.subscribe(
			'Storage.Get'
			, self.get
		)

		events.subscribe(
			'Storage.Query'
			, self.query
		)

		events.subscribe(
			'Storage.Change'
			, self.change
		)

		events.subscribe(
			'Storage.On'
			, self._data_events_subscribe
		)
示例#3
0
文件: main.py 项目: Duke-chua/pfkaplr
	def init(self):
		self.clients = weakref.WeakKeyDictionary()
		self.clients_lock = threading.Lock()

		# Task.AllowBrowsersToListenForChange has identical listener
		# but there it is responsible for connecting new connections
		# to interested TaskHives. Here we just log the connections
		# cause when TaskHive calls us, we need to have a handle to
		# the connection.
		events.subscribe(
			'LiveRealoadServer.NewConnection'
			, self._new_client_connected
		)
示例#4
0
	def run(self, callback):
		'''
		@param {Function} callback to be called by runner when done (or passed to async delegate)
		'''
		self.run_requests += 1
		if not self.server.is_running:
			self.server.start()

			events.subscribe(
				'Application.Configuration.Show'
				, self._process_request_for_config
			)

		callback()
示例#5
0
	def init(self):
		self.tasktypelogo = {}

		from .configurationserver import server, config_application

		events.subscribe(
			'TaskHiveCoordinator.TaskTypes.Changed'
			, bind( 
				self._tasktypes_changed_handler
				, os.path.join(config_application.CWD, config_application.STATIC_FOLDER)
			)
		)

		self.server = server
		self.run_requests = 0
def test():
	import tempfile
	import shutil
	import pubsub

	watched_path = tempfile.mkdtemp()
	print "Temp folder: " + watched_path

	events = pubsub.PubSub()
	w = WatchCoordinator(events)

	def display_changes(watch_path, changed_path, change_action):
		print "Watched path '%s'\nChanged path '%s'\nChange action '%s'" % (watch_path, changed_path, change_action)

	token = events.subscribe(
		'TaskHive.1.PathWatcher.1'
		, display_changes
	)

	try:
		th = w.watch(watched_path, token['topic'])
		l = threading.Event()
		l.clear()
		l.wait(2)
		open(watched_path+'/testfile.txt','w').write('')
		l.wait(50)
	except Exception, e:
		raise
示例#7
0
def test():
    import tempfile
    import shutil
    import pubsub

    watched_path = tempfile.mkdtemp()
    print "Temp folder: " + watched_path

    events = pubsub.PubSub()
    w = WatchCoordinator(events)

    def display_changes(watch_path, changed_path, change_action):
        print "Watched path '%s'\nChanged path '%s'\nChange action '%s'" % (
            watch_path, changed_path, change_action)

    token = events.subscribe('TaskHive.1.PathWatcher.1', display_changes)

    try:
        th = w.watch(watched_path, token['topic'])
        l = threading.Event()
        l.clear()
        l.wait(2)
        open(watched_path + '/testfile.txt', 'w').write('')
        l.wait(50)
    except Exception, e:
        raise
示例#8
0
文件: main.py 项目: Duke-chua/pfkaplr
    def init(self):
        # this starts the LiveReload server in general. It means all browsers CAN connect to it,
        # but they don't have a connection to any given TaskHive, and will be prompted to choose one
        # or disconnect.

        logging.debug("Initing LiveReloadServer")

        from .livereloadserver import live_reload_application

        self.server = live_reload_application
        self.run_requests = 0

        self.clients = weakref.WeakKeyDictionary()
        self.clients_lock = threading.Lock()

        events.subscribe('LiveRealoadServer.NewConnection',
                         self._new_client_connected)
示例#9
0
	def init(self):
		# this starts the LiveReload server in general. It means all browsers CAN connect to it,
		# but they don't have a connection to any given TaskHive, and will be prompted to choose one
		# or disconnect.

		logging.debug("Initing LiveReloadServer")

		from .livereloadserver import live_reload_application

		self.server = live_reload_application
		self.run_requests = 0

		self.clients = weakref.WeakKeyDictionary()
		self.clients_lock = threading.Lock()

		events.subscribe(
			'LiveRealoadServer.NewConnection'
			, self._new_client_connected
		)
示例#10
0
def main():
    import threading
    ev = threading.Event()
    ev.clear()

    events.subscribe('Application.Exit', bind(exit_the_main_loop, ev))

    a = Application()

    print(
        "\n# Press 'abort' key combination (usually CTRL+C) to stop the %s server #\n"
        % APP_NAME)
    try:
        while not ev.is_set():
            logging.debug("Main Loop...")
            ev.wait(30)
    except KeyboardInterrupt:
        pass

    print "Good bye"
示例#11
0
    def __init__(self):

        self.tasktypes = TaskCollection()
        for tasktype in self.tasktypes_iter():
            self.tasktypes[tasktype.ID] = tasktype

        events.publish('TaskHiveCoordinator.TaskTypes.Changed', self.tasktypes)

        self.taskhives = {}
        self.taskhives_lock = threading.Lock()
        for taskhive_data in storage.query(r'^TaskHive\..+'):
            taskhive_id = taskhive_data['id']
            self.taskhives[taskhive_id] = TaskHive(self.tasktypes,
                                                   taskhive_data)

        # making listing of tasktypes available through pubsub system.
        events.subscribe('TaskHiveCoordinator.GetTaskTypes',
                         self.get_tasktypes_metadata)

        events.publish('Storage.On', 'set', r'^TaskHive\.',
                       self._hive_set_handler)
示例#12
0
文件: app.py 项目: dvdotsenko/pfkaplr
def main():
    import threading
    ev = threading.Event()
    ev.clear()

    events.subscribe(
        'Application.Exit'
        , bind(exit_the_main_loop, ev)
    )

    a = Application()
    
    print("\n# Press 'abort' key combination (usually CTRL+C) to stop the %s server #\n" % APP_NAME)
    try:
        while not ev.is_set():
            logging.debug("Main Loop...")
            ev.wait(30)
    except KeyboardInterrupt:
        pass

    print "Good bye"
示例#13
0
    def __init__(self):

        # 'path':callback
        self.paths = {}
        self.paths_lock = threading.Lock()

        # some OS-specific file system watchers
        # have echoes for same change
        # On windows we are fast enough to
        # fire several times between start and end of
        # write for same file. The format is:
        # {path:{changetype:time}}
        self.recently_fired = {}
        self.recently_fired_lock = threading.Lock()

        # callback:filter_regex
        # because self.paths is the only place where we store hard refs to callbacks
        # removing it there, should autocleanup self.filters
        self.filters = weakref.WeakKeyDictionary()
        self.filters_lock = threading.Lock()

        # internal API
        events.subscribe('PathWatchCoordinator.StartPathWatchRunner',
                         self._watch_runner)

        # public API
        events.subscribe('PathWatchCoordinator.Watch', self.watch)

        events.subscribe('PathWatchCoordinator.Stop', self.stop)
示例#14
0
	def __init__(self):

		# 'path':callback
		self.paths = {}
		self.paths_lock = threading.Lock()

		# some OS-specific file system watchers
		# have echoes for same change
		# On windows we are fast enough to
		# fire several times between start and end of
		# write for same file. The format is:
		# {path:{changetype:time}}
		self.recently_fired = {} 
		self.recently_fired_lock = threading.Lock()

		# callback:filter_regex
		# because self.paths is the only place where we store hard refs to callbacks
		# removing it there, should autocleanup self.filters
		self.filters = weakref.WeakKeyDictionary()
		self.filters_lock = threading.Lock()
		
		# internal API
		events.subscribe(
			'PathWatchCoordinator.StartPathWatchRunner'
			, self._watch_runner
		)

		# public API
		events.subscribe(
			'PathWatchCoordinator.Watch'
			, self.watch
		)

		events.subscribe(
			'PathWatchCoordinator.Stop'
			, self.stop
		)