https://github.com/alice1017/mdfmonitor
** mdfmonitor ** is a Python module that uses file timestamps and URL Data headers to monitor file and URL updates.
mdfmonitor contains:
FileModificationMonitor
FileModificationMonitor (hereafter referred to as "monitor") monitors ** files ** for updates.
Monitor has a repository with ** timestamp data ** of the file and ** data of the contents of the file **. First of all, insert the original time stamp data and the data of the contents of the file. Next, get the new time stamp data and the contents data of the file, ** compare ** these old data and new data, and if they are different, consider it as ** update ** and make it an object yield. To do.
It's simple to use.
FileModificationMonitor
#!/usr/bin/python
import os
from mdfmonitor import FileModificationMonitor
files = os.listdir(".") # >>> ['sample.txt', 'sample.py']
# create Watcher instnce
monitor = FileModificationMonitor()
# append file to mdfmonitor instance
monitor.add_file("sample.txt")
# or
# append files to mdfmonitor instance
monitor.add_files(os.listdir("."))
for mdf in monitor.monitor():
print mdf.file.center(30, "=")
print "Catch the Modification!!"
print "Old timestamp: %s" % mdf.old_mtime
print "New timestamp: %s" % mdf.new_mtime
print "manager: %s" % str(mdf.manager.o_repository)
print "Diff".center(30,"=")
print mdf.diff
URLModificationMonitor
URLModificationMonitor (also called "monitor") can monitor URL content updates.
The structure of Monitor is almost the same as FileModificationMonitor
.
The difference is that it uses the ** Date ** header that comes with the Response
header of the URL to find updates, not the timestamp data.
This is about the same.
#!/usr/bin/python
import os
from mdfmonitor import URLModificationMonitor
files = os.listdir(".") # >>> ['sample.txt', 'sample.py']
# create Watcher instnce
monitor = URLModificationMonitor()
# append file to mdfmonitor instance
monitor.add_url("http://sampe.com/path/")
for mdf in monitor.monitor():
print mdf.url.center(30, "=")
print "Catch the Modification!!"
print "Old timestamp: %s" % mdf.old_dtime
print "New timestamp: %s" % mdf.new_dtime
print "manager: %s" % str(mdf.manager.o_repository)
print "Diff".center(30,"=")
print mdf.diff
① Difference
Both ** FileModificationMonitor ** and ** URLModificationMonitor ** yield an object called ** ModificationObject **, but this object has new Body data and old data, and based on that, it's called ** diff **. Generates a diff string. (I'm using a module called difflib
in Python)
② ModificationObjectManager History is an integral part of updates, isn't it? ** ModificationObjectManager ** is a class that saves its history. The update object is inserted in the array called o_repository of Manager, and that array becomes the update history as it is.
Since it is a Python module, you can use pip
and ʻeasy_install`.
``shell $ sudo easy_install mdfmonitor
Or`git`Please use
```shell
$ git clone https://github.com/alice1017/mdfmonitor.git
$ cd mdfmonitor
$ sudo pyton setup.py build install
MIT license
##so
That's why I introduced mdfmonitor. When I searched for it on PYPI, there weren't many modules like this, so I made it again. The terrible English in the README and docstring is by design.
If you say "it is better to design like this" or "there is a bug", please pull or comment on github.
##What you can do with mdfmonitor
Since mdfmonitor is a script that monitors file updates, gitFor those who manage the version with, it is automaticaddAnd automaticcommitCan be implemented.
Recommended Posts