Пример #1
0
    def test_add_cmds(self):
        """When files are added, either at init or via add_cmds
        watcher.cmds length should reflect that. Non-files or duplicates
        shouldn't be reflected."""
       
        w = Watcher()
        self.assertEqual(0, len(w.cmds))
        w.add_cmds("python %s" % self.fixture('sample.py'), self.fixture('sample.py'))
        self.assertEqual(2, len(w.cmds))
       

        w = Watcher(cmds=["python %s" % self.fixture('sample.py')])
        self.assertEqual(1, len(w.cmds))
Пример #2
0
    def test_add_files(self):
        """When files are added, either at init or via add_files
        watcher.files length should reflect that. Non-files or duplicates
        shouldn't be reflected."""
        
        self.assertEqual(0, len(self.watcher.files))
        self.watcher.add_files(self.fixture("a.txt"), self.fixture("b.txt"))
        self.assertEqual(2, len(self.watcher.files))
       
        self.watcher.add_files(self.fixture("c.txt"))
        self.assertEqual(3, len(self.watcher.files))

        w = Watcher(files=[self.fixture("a.txt"), self.fixture("b.txt"), self.fixture("c.txt")])
        self.assertEqual(3, len(w.files))
Пример #3
0
def main(args=None):
    """
    Used by the pywatch script to handle command-line
    args.
    """

    if not args:
        args = sys.argv[1:]

    usage = 'usage: %prog [options] "command" file1 file2 ...'
    parser = OptionParser(usage=usage)
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="Output timestamp when commands are run.")
    parser.add_option("--version",
                      action="store_true",
                      dest="version",
                      default=False,
                      help="Output verion number and exit.")
    parser.add_option("--no-clear",
                      action="store_true",
                      default=True,
                      help="Don't clear the terminal when files change.")
    options, args = parser.parse_args(args)

    if options.version:
        print "pywatch %s" % VERSION
        sys.exit(0)

    if len(args) < 2:
        print parser.error(
            "You must provide a shell command and at least one file.")

    cmds = [
        args[0],
    ]
    files = args[1:]

    w = Watcher(cmds=cmds,
                files=files,
                verbose=options.verbose,
                clear=options.no_clear)
    w.run_monitor()
    sys.exit(0)
Пример #4
0
 def setUp(self):
     base_path = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
     self.fixtures_path = os.path.join(base_path, 'fixtures')
     self.watcher = Watcher()