Esempio n. 1
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

            print("FPS: %d" % cap.get(cv2.CAP_PROP_FPS), end='\r')
Esempio n. 2
0
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)
Esempio n. 3
0
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:
        file_monitor.join()
        notifications.join()
        logging.shutdown()
        exit()
Esempio n. 4
0
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)