def __init__(self): options, args = self.parse_args() log_format = "%(asctime)s - %(message)s" date_format = "%b %d, %H:%M:%S" logging.basicConfig(format=log_format, datefmt=date_format, level=options.log_level) # Add notifications notify_handler.register(logging.getLogger(), "Pushy") dir = os.path.abspath(options.source) if options.source else './' self.monitor = FileMonitor(dir) if options.ignored_dirs: self.ignored_dirs = re.compile(options.ignored_dirs, re.I) if options.ignored_files: self.ignored_files = re.compile(options.ignored_files, re.I) self.monitor.delay = options.delay if options.delay else 1 self.monitor.file_changed += self.handle_change self.monitor.dir_changed += self.handle_change if options.target: target = os.path.abspath(options.target) if options.username and options.hostname: self.pusher = SshPusher(dir, target, options.hostname, options.username) else: self.pusher = Pusher(dir, target) else: print "You might want to specify a target directory. This script isn't very useful otherwise." self.pusher = None logging.info("Pushy started.") try: self.monitor.start() except (KeyboardInterrupt, SystemExit): logging.info("Pushy stopped.") sys.exit() except: raise
def emulation_btn_slot(self): if not self.emulation_pulse: self.clr = [10, 255, 150] self.clr_step = 15 self.emulation_btn.clearFocus() self.read_flash_btn_slot() _file = self._get_filename_form_text_box() self.file_monitor = FileMonitor(_file, self.print_to_console) if self.file_monitor.file_content: self.emu.emulator.keep_emulator_awaken() self.emulation_pulse = PeriodicThread(period=0.05) self.emulation_pulse.periodic_signal.connect( self.emulation_btn_pulse) self.emulation_pulse.start() self.emulation = EmulationThread( self.emu.emulator.emulate, (self.file_monitor, self.rw_ind_signal.emit)) self.emulation.start() else: self.emulation_disable()
print("\n[{0}] End Camera..!".format(sys.argv[0])) # start-up if __name__ == "__main__": exeName = main.__file__ # camera obj cap = cv2.VideoCapture(camDevID) if not (cap.isOpened()): print("[{0}] Camera Open Fail..!".format(sys.argv[0])) sys.exit(0) # file monitor fm = FileMonitor() fm.add_file("./Algorithm.py", Algorithm) fm.start() try: print("[{0}] ==== Camera Activated ====".format(sys.argv[0])) while True: ret, frame = cap.read() algo = Algorithm.Algorithm() nFrame = algo.do_func(frame) cv2.imshow('CCD LIVE', nFrame) # update frame if cv2.waitKey(1) & 0xFF == ord('q'): break
from pymongo import MongoClient from watchdog.observers.polling import PollingObserver from file_monitor import FileMonitor from web_server import WebServer from config import config from utils import init_database from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop if __name__ == "__main__": client = MongoClient() database = client.get_database(config["database_name"]) client.close() init_database(database) server = WebServer(database).web_server observer = PollingObserver() file_monitor = FileMonitor(database, config["content_path"]) observer.schedule(file_monitor, path=config["content_path"], recursive=True) print config["content_path"] observer.start() if (config["dev_mode"]): server.run(config["server_ip"], config["server_port"], debug=True) else: server = HTTPServer(WSGIContainer(server)) server.listen(config["server_port"], config["server_ip"]) IOLoop.instance().start()
#coding:utf8 import threading import time import random from file_monitor import FileMonitor import long_op # Can't do 'from long_op import LongOp' here, because reload only works on module level fm = FileMonitor() fm.add_file("long_op.py", long_op) fm.start() resource = threading.BoundedSemaphore(2) threads = [] lock = threading.Lock() EXITTHREADS = False def start_thread(): while True: resource.acquire() print("Start new thread") t = long_op.LongOp(random.randint(0, 9)) with lock: threads.append(t) t.start() if EXITTHREADS: break def clear_threads():
import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), "../")) import time from pymongo import MongoClient from watchdog.observers import Observer from file_monitor import FileMonitor from utils import clear_database if __name__ == "__main__": client = MongoClient() database = client.get_database("test") client.close() observer = Observer() file_monitor = FileMonitor(database, "./pages", True) observer.schedule(file_monitor, path="./pages", recursive=True) observer.start() try: while True: time.sleep(1) except: observer.stop() clear_database(database)
import queue from config import Config from file_event import FileEvent from file_monitor import FileMonitor from logger import Logger from notifications.notification_event import NotificationEvent from notifications.notifications import Notifications if __name__ == "__main__": config = Config('config.json') logger = Logger(config) file_event_queue = queue.Queue() file_monitor = FileMonitor(config, file_event_queue) notifications = Notifications(config, file_event_queue) try: file_monitor.start() notifications.start() while True: try: event = file_event_queue.get(timeout=5) if isinstance(event, FileEvent): logger.log_file_event(event) elif isinstance(event, NotificationEvent): logger.log_notification_event(event) except queue.Empty: pass except KeyboardInterrupt:
class Main(object): def __init__(self): options, args = self.parse_args() log_format = "%(asctime)s - %(message)s" date_format = "%b %d, %H:%M:%S" logging.basicConfig(format=log_format, datefmt=date_format, level=options.log_level) # Add notifications notify_handler.register(logging.getLogger(), "Pushy") dir = os.path.abspath(options.source) if options.source else './' self.monitor = FileMonitor(dir) if options.ignored_dirs: self.ignored_dirs = re.compile(options.ignored_dirs, re.I) if options.ignored_files: self.ignored_files = re.compile(options.ignored_files, re.I) self.monitor.delay = options.delay if options.delay else 1 self.monitor.file_changed += self.handle_change self.monitor.dir_changed += self.handle_change if options.target: target = os.path.abspath(options.target) if options.username and options.hostname: self.pusher = SshPusher(dir, target, options.hostname, options.username) else: self.pusher = Pusher(dir, target) else: print "You might want to specify a target directory. This script isn't very useful otherwise." self.pusher = None logging.info("Pushy started.") try: self.monitor.start() except (KeyboardInterrupt, SystemExit): logging.info("Pushy stopped.") sys.exit() except: raise def parse_args(self): parser = OptionParser(description="Pushes filesystem changes to a target directory") parser.add_option("-t", "--target", help="The target directory.", type="string" ) parser.add_option("-s", "--source", help="The source directory. Default is current directory.", type="string", default="./" ) parser.add_option("-u", "--username", help="A username. If supplied, files will be pushed via ssh.", type="string" ) parser.add_option("-r", "--remote-host", dest="hostname", help="The name of the host that will receive files. Used for ssh pushes.", type="string" ) parser.add_option("-l", "--log-level", dest="log_level", help="The logger level to use.", type="int", default=logging.INFO ) parser.add_option("-d", "--delay", help="The number of seconds to pause between filesystem scans.", type="int", default=1 ) parser.add_option("--ignored-files", dest="ignored_files", help="If a file matches this regex, it is ignored.", type="string" ) parser.add_option("--ignored-dirs", dest="ignored_dirs", help="If a directory matches this regex, it is ignored.", type="string" ) return parser.parse_args() def handle_change(self, path, action): logging.debug("Handling change event '%s' for path '%s'" % (action, path)) if self.pusher is None: return if action == "deleted": self.pusher.remove(path) elif action == "added": self.pusher.add(path) elif action == "updated": self.pusher.update(path)
class Main(object): def __init__(self): options, args = self.parse_args() log_format = "%(asctime)s - %(message)s" date_format = "%b %d, %H:%M:%S" logging.basicConfig(format=log_format, datefmt=date_format, level=options.log_level) # Add notifications notify_handler.register(logging.getLogger(), "Pushy") dir = os.path.abspath(options.source) if options.source else './' self.monitor = FileMonitor(dir) if options.ignored_dirs: self.ignored_dirs = re.compile(options.ignored_dirs, re.I) if options.ignored_files: self.ignored_files = re.compile(options.ignored_files, re.I) self.monitor.delay = options.delay if options.delay else 1 self.monitor.file_changed += self.handle_change self.monitor.dir_changed += self.handle_change if options.target: target = os.path.abspath(options.target) if options.username and options.hostname: self.pusher = SshPusher(dir, target, options.hostname, options.username) else: self.pusher = Pusher(dir, target) else: print "You might want to specify a target directory. This script isn't very useful otherwise." self.pusher = None logging.info("Pushy started.") try: self.monitor.start() except (KeyboardInterrupt, SystemExit): logging.info("Pushy stopped.") sys.exit() except: raise def parse_args(self): parser = OptionParser( description="Pushes filesystem changes to a target directory") parser.add_option("-t", "--target", help="The target directory.", type="string") parser.add_option( "-s", "--source", help="The source directory. Default is current directory.", type="string", default="./") parser.add_option( "-u", "--username", help="A username. If supplied, files will be pushed via ssh.", type="string") parser.add_option( "-r", "--remote-host", dest="hostname", help= "The name of the host that will receive files. Used for ssh pushes.", type="string") parser.add_option("-l", "--log-level", dest="log_level", help="The logger level to use.", type="int", default=logging.INFO) parser.add_option( "-d", "--delay", help="The number of seconds to pause between filesystem scans.", type="int", default=1) parser.add_option("--ignored-files", dest="ignored_files", help="If a file matches this regex, it is ignored.", type="string") parser.add_option( "--ignored-dirs", dest="ignored_dirs", help="If a directory matches this regex, it is ignored.", type="string") return parser.parse_args() def handle_change(self, path, action): logging.debug("Handling change event '%s' for path '%s'" % (action, path)) if self.pusher is None: return if action == "deleted": self.pusher.remove(path) elif action == "added": self.pusher.add(path) elif action == "updated": self.pusher.update(path)
from dbus_services import (DeepinMovieServie, check_multiple_instances, DeepinMovieInterface, session_bus, DBUS_PATH) result = check_multiple_instances() if result: dbus_service = DeepinMovieServie(app) session_bus.registerObject(DBUS_PATH, dbus_service) else: if not config.playerMultipleProgramsAllowed: dbus_interface = DeepinMovieInterface() dbus_interface.play(json.dumps(sys.argv[1:])) os._exit(0) windowView = Window(result or len(sys.argv) > 1) menu_controller = MenuController(windowView) file_monitor = FileMonitor() findVideoThreadManager = FindVideoThreadManager() app._extra_window = weakref.ref(windowView) qml_context = windowView.rootContext() qml_context.setContextProperty("config", config) qml_context.setContextProperty("_utils", utils) qml_context.setContextProperty("_findVideoThreadManager", findVideoThreadManager) qml_context.setContextProperty("_file_monitor", file_monitor) qml_context.setContextProperty("database", database) qml_context.setContextProperty("windowView", windowView) qml_context.setContextProperty("movieInfo", movie_info) qml_context.setContextProperty("_menu_controller", menu_controller)