Coder Social home page Coder Social logo

borntyping / spotter Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 11.0 31 KB

A command line tool for watching files and running shell commands when they change

Home Page: https://pypi.python.org/pypi/spotter

License: MIT License

Python 100.00%
python spotter watch

spotter's Introduction

spotter

Latest PyPI version

Spotter is a simple command line tool for watching files and running shell commands when they change. Directives are read from a text file, and spotter will look for a file named .spotter in the current directory if no filenames are given.

Usage

spotter [-h] [-v] [-q] [-c] [filename [filename ...]]
Positional arguments:
  • filename: A list of files containing directives to load, defaulting to [".spotter"].
Optional arguments:
  • -h, --help: Explain the command line options.
  • -v, --version: Show the current version number.
  • -q, --quiet: The output of commands is not printed unless they fail.
  • -c, --continue: Failed commands will not stop spotter from continuing.

Spotter can also be run as a python module:

python -m spotter ...

Directives

All directives are in the following form:

<directive>: <argument> [-> <second argument>]

Not all directives take a second argument, but all of them take a first argument.

Watch

watch: <pattern> -> <command>

The Watch directive takes two arguments: <pattern> is a unix-style filename pattern, and <command> is a shell command to run when a file matching the pattern is created or changed. More information on the pattern matching used can be found in the fnmatch library documentation.

watch: *.txt -> echo "Text file changed"

Multiple watch directives can be given, and spotter will continue to run matching watch directives until one fails (i.e. returns an exit code above 0) or until it runs a matching watch-final directive.

watch: * -> return 1
watch: * -> echo "This command will not run"

The --continue command line argument can be used to disable this behaviour, forcing spotter to continue processing watches even if one fails.

Watch-Final

watch-final: <pattern> -> <command>

Watch-final has exactly the same syntax and behaviour as the Watch directive. Unlike the Watch directive, if the pattern matches and the command is run, no further watches will be processed.

watch-final: *.txt -> echo "No commands will run after this"

Start / Stop

start: <command>
stop: <command>

The start and stop directives can be used to run commands when spotter starts running and when spotter stops running.

start: echo "Started watching files"
stop: echo "Stopped watching files"

Define

define: <name> -> <value>

The Define directive allows values to be stored and then included in other directives when they are run. filename is always available in watch commands, and contains the path of the file that matched the pattern. Definitions are included in the commands using python format specifications, and are inserted when the command is run, not when the command is loaded.

define: python_command -> python2.6

watch: *.py -> {python_command} "{filename}"

spotter's People

Contributors

borntyping avatar grue avatar kragniz avatar movermeyer avatar natefox avatar thijstriemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

spotter's Issues

Config files fail to parse if the command includes a ':' character

WatchFile.read_line needs patching so that split() is limited to a single split.

Traceback (most recent call last):
  File "/usr/local/bin/spotter", line 9, in <module>
    load_entry_point('spotter==1.5', 'console_scripts', 'spotter')()
  File "/usr/local/lib/python2.7/dist-packages/spotter/__init__.py", line 32, in main
    Spotter(parser.parse_args(), start=True)
  File "/usr/local/lib/python2.7/dist-packages/spotter/spotter.py", line 21, in __init__
    self.read_files(self.options.filenames)
  File "/usr/local/lib/python2.7/dist-packages/spotter/spotter.py", line 28, in read_files
    self.watchlists.append(WatchFile(filename))
  File "/usr/local/lib/python2.7/dist-packages/spotter/watches.py", line 61, in __init__
    self.read_file(filename)
  File "/usr/local/lib/python2.7/dist-packages/spotter/watches.py", line 70, in read_file
    self.read_line(line)
  File "/usr/local/lib/python2.7/dist-packages/spotter/watches.py", line 74, in read_line
    directive, arguments = line.split(':')
ValueError: too many values to unpack

IOError .spotter

Instead of crashing out when .spotter does not exist, catch IOError and return a nice message to the user about creating .spotter or supplying args at runtime.

keepass kdbx files change not detected

Debian 9.3
Spotter 0.2
pyinotify-0.9.6
python --version 2.7.13
python3 --version 3.5.3

I'm using spotter to monitor modification on my keepass deb, but strangly enough modifications on this file are not raised by spotter, here is how I repro the issue.
The step below done with a .txt file does work ok

  1. create your .kdbx file
  2. create your .spotter to monitor your file with this directive,
    watch: *.kdbx -> echo "ok ca marche"
  3. Start spotter (spotter &)
  4. Make any change using any keepass app
  5. The command is never triggered…

Also the only way I manage to the command trigger was doing this

  1. create your .kdbx file
  2. create your .spotter to monitor your file with this directive,
    watch: *.kdbx -> echo "ok ca marche"
  3. Start spotter (spotter &)
  4. cp my.kdbx temp.kdbx
  5. The echo command is properly trigger
  6. echo toto > temp.kdbx
  7. The echo command is properly trigger

Any though why this is happening ?

Thanks for any input.
Matth

Crashes with non-ascii filenames

I'm getting this error

Traceback (most recent call last):
  File "/usr/local/bin/spotter", line 9, in <module>
    load_entry_point('spotter==1.3', 'console_scripts', 'spotter')()
  File "/usr/local/lib/python2.7/dist-packages/spotter-1.3-py2.7.egg/spotter/__init__.py", line 32, in main
    Spotter(parser.parse_args(), start=True)
  File "/usr/local/lib/python2.7/dist-packages/spotter-1.3-py2.7.egg/spotter/spotter.py", line 23, in __init__
    self.loop()
  File "/usr/local/lib/python2.7/dist-packages/spotter-1.3-py2.7.egg/spotter/spotter.py", line 33, in loop
    self.inotify_loop()
  File "/usr/local/lib/python2.7/dist-packages/spotter-1.3-py2.7.egg/spotter/spotter.py", line 38, in inotify_loop
    watch_manager.add_watch('.', Spotter.INOTIFY_EVENT_MASK, rec=True)
  File "/usr/local/lib/python2.7/dist-packages/pyinotify.py", line 1898, in add_watch
    for rpath in self.__walk_rec(apath, rec):
  File "/usr/local/lib/python2.7/dist-packages/pyinotify.py", line 2082, in __walk_rec
    for root, dirs, files in os.walk(top):
  File "/usr/lib/python2.7/os.py", line 294, in walk
    for x in walk(new_path, topdown, onerror, followlinks):
  File "/usr/lib/python2.7/os.py", line 284, in walk
    if isdir(join(top, name)):
  File "/usr/lib/python2.7/posixpath.py", line 80, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2: ordinal not in range(128)

It can be created by running this somewhere in the watched directories

touch mÉ.txt

My spotter directive file is simply:

watch: * -> echo "Backing up {filename}"

Even if I start spotter with --quiet I get this error, so I dont think its a console setting. I tried http://stackoverflow.com/a/7892892/2019263 without success.

Changes in files causes an attribute error for python 3.5

I might have been screwing this one up, but, when I try to run the sample > spotter command in the spotter repo and a file changes, I get the following attribute error:
AttributeError: 'str' object has no attribute 'decode'
Would you happen to have any ideas on what to do? I've built spotter with the python3.5 distribution.

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.