GithubHelp home page GithubHelp logo

teddbug-s / watchdog_plus_old Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 41 KB

A python package written on top of WatchDog to monitor multiple directories in background and on system start-up.

Python 100.00%
python watchdog filesystem-monitoring background-process

watchdog_plus_old's Introduction

Watchdog Plus

A python package to built on top of watchdog for extra functionality such as monitoring multiple directory paths using processes or threads programmatically, easily create and schedule an observer, schedule observer services known as WatchDogService to monitor paths in the background also providing you with APIs to manage the background process.

Usage

the Observer Manager

Create and schedule an observer.

from watchdog_plus.managers import ObserverManager

# path to monitor
path = "/home/teddbug/Desktop"

manager = ObserverManager()
# create an observer, this automatically schedules the observer with the default handler
desktop_watchdog = manager.create_observer(path, name="desktop_watchdog") # you can specify any name
# this way you start the observer natively 
desktop_watchdog.start()

# but you could also do for more functionality like specifying
# duration for the observer
manager.start_observer("desktop_observer", duration=20)

Create and schedule observers

from watchdog_plus.managers import ObserverManager, StartMethods

paths = [
    "home/teddbug/Desktop",
    "home/teddbug/Downloads",
    "home/teddbug/Videos"
]

manager = ObserverManager() # initiate the manager
# you can optionally provide names for each of the observers but
# names are also auto generated using the last directory name lower cased
manager.create_observers(paths)
# starting the observers
manager.start_observers(
    names=[name.split('/')[-1].lower() for name in paths],
    start_method=StartMethods.THREAD # use threading 
)
# you can simply just supply the names of only the observers you want to start

WatchdogService

create a watchdog service to monitor files in background

from watchdog_plus.services import WatchdogService

# path to monitor
path = "/home/teddbug/Desktop"

service = WatchdogService(
    path=path,
    name=None, # not supplying a name to the service
    run_on_startup=False # could be enabled to allow service to run on system startup
)
# schedule with output file for logging and a handler could also be provided
service.schedule()
# start service
service.start()

watchdog_plus_old's People

Contributors

kwieeciol avatar teddbug-s avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

kwieeciol

watchdog_plus_old's Issues

SyntaxError: invalid syntax

from watchdog_plus.managers import ObserverManager, StartMethods

paths = [
    "/hddisk/ttt/monitor/1",
    "/hddisk/ttt/monitor/2"
]

manager = ObserverManager() # initiate the manager
# you can optionally provide names for each of the observers but
# names are also auto generated using the last directory name lower cased
manager.create_observers(paths)
# starting the observers
manager.start_observers(
    names=[name.split('/')[-1].lower() for name in paths],
    start_method=StartMethods.THREAD # use threading
)
# you can simply just supply the names of only the observers you want to start

I got error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from watchdog_plus.managers import ObserverManager, StartMethods
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/managers/__init__.py", line 1, in <module>
    from .observer_manager import ObserverManager, StartMethods
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/managers/observer_manager.py", line 31, in <module>
    from ..handlers import EventHandler
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/__init__.py", line 1, in <module>
    from .event_handler import EventHandler
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/event_handler.py", line 35, in <module>
    from .logger import EventLogger
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/logger/__init__.py", line 1, in <module>
    from .event_logger import EventLogger
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/logger/event_logger.py", line 57
    if changes := key.get(name, []):
                        ^
SyntaxError: invalid syntax

Thanks

SyntaxError: invalid syntax

from watchdog_plus.managers import ObserverManager, StartMethods

paths = [
    "/hddisk/ttt/monitor/1",
    "/hddisk/ttt/monitor/2"
]

manager = ObserverManager() # initiate the manager
# you can optionally provide names for each of the observers but
# names are also auto generated using the last directory name lower cased
manager.create_observers(paths)
# starting the observers
manager.start_observers(
    names=[name.split('/')[-1].lower() for name in paths],
    start_method=StartMethods.THREAD # use threading
)
# you can simply just supply the names of only the observers you want to start

I got error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from watchdog_plus.managers import ObserverManager, StartMethods
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/managers/__init__.py", line 1, in <module>
    from .observer_manager import ObserverManager, StartMethods
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/managers/observer_manager.py", line 31, in <module>
    from ..handlers import EventHandler
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/__init__.py", line 1, in <module>
    from .event_handler import EventHandler
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/event_handler.py", line 35, in <module>
    from .logger import EventLogger
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/logger/__init__.py", line 1, in <module>
    from .event_logger import EventLogger
  File "/hddisk/ttt/monitor/watchdog_plus/watchdog_plus/handlers/logger/event_logger.py", line 57
    if changes := key.get(name, []):
                        ^
SyntaxError: invalid syntax

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.