Package: watch-path
Watch PathRuns command or callback function when path file modified time changes:arrow_up: Top of Document:building_construction: Requirements:zap: Quick Start:memo: Your Requirements File:floppy_disk: Commit and Push🧰 Usage🗒 Notes:card_index: Attribution:balance_scale: LicensingRequirementsPython version 2 or 3Quick StartInstall this project via Pip version 2 or 3pip3install--user--upgradewatch-pathYour Requirements FileSuggested additions for your requirements.txt file so everyone has a good time with dependencieswatch-pathCommit and Pushgitaddrequirements.txt


gitcommit-F-<<'EOF':heavy_plus_sign: Adds `python-utilities/watch_path#1` as dependency## Anything else worth committingEOFgitpush:tada: Excellent :tada:your project is now ready to begin unitizing code from this repository!UsagePrint available CLI (Command Line Interface) optionswatch_path--helpRun command whentest.txtfile changeswatch_path--filetest.txt--command'cat test.txt'\--sleep0.5\--decodeutf-8Example of inheriting and modifying a class from watch_path...#!/usr/bin/env pythonfromwatch_pathimportWatch_PathclassCustomized_Watch_Path(Watch_Path):"""Customizes `watch_path` class"""def__init__(self,ignore_empty,**kwargs):"""Adds `ignore_empty` to initialization parameters of class"""super(watch_path,self).__init__(**kwargs)self.update(ignore_empty=ignore_empty)defnext(self):"""Adds logic to ignore empty/non-existent paths"""try:new_time_stamp=self.file_modified_time(self['path'])exceptOSErrorase:print(e)ifself['ignore_empty']isnotTrue:self.throw(GeneratorExit)ifnew_time_stamp!=self['time_stamp']:self['time_stamp']=new_time_stampreturnself['callback'](path=self['path'],time_stamp=new_time_stamp,**self['callback_kwargs'])defcustom_callback(**kwargs):print("Detected disturbances in{path}".format(path=kwargs['path']))if__main__=='__name__':"""Code that is run if this file is executed as a script instead of imported"""custom_file_watcher=Customized_Watch_Path(callback=custom_callbackpath='test.txt',ignore_empty=True)try:forcallback_resultsincustom_file_watcher:ifcallback_results:print(callback_results['stdout'].decode('UTF-8'))sleep(1)exceptKeyboardInterrupt:print('Stopping watcher and exiting...')NotesThis repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.AttributionGitHub --github-utilities/make-readmeStackOverflow -- How do I importFileNotFounderrorfrom Python 3?StackOverflow -- How do i watch a file for changes?StackOverflow -- What does thebcharacter do in front of a string literal?LicenseDocumentation for Watch Path
Copyright (C) 2023 S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.For further details review full length version ofAGPL-3.0License.