def test_terminal(self): print('Testing utils.run_command') from watchme.utils import run_command from watchme.utils import which result = run_command('echo Las Papas Fritas') self.assertEqual(result['message'], 'Las Papas Fritas\n') self.assertEqual(result['return_code'], 0) print('Testing utils.which') result = which('echo') self.assertEqual(result, '/bin/echo')
def test_terminal(self): print("Testing utils.run_command") from watchme.utils import run_command from watchme.utils import which result = run_command("echo Las Papas Fritas") self.assertEqual(result["message"], "Las Papas Fritas\n") self.assertEqual(result["return_code"], 0) print("Testing utils.which") result = which("echo") self.assertEqual(result, "/bin/echo")
def schedule(self, minute=12, hour=0, month='*', day='*', weekday='*', job=None, force=False): '''schedule the watcher to run at some frequency to update record of pages. By default, the task will run at 12 minutes passed midnight, daily. You can change the variables to change the frequency. See https://crontab.guru/ to get a setting that works for you. Hourly: 0 * * * * Daily: 0 0 * * * (midnight) default weekly 0 0 * * 0 monthly 0 0 1 * * yearly 0 0 1 1 * Parameters ========== minute: must be within 1 and 60, or set to "*" for every minute hour: must be within 0 through 23 or set to * month: must be within 1 and 12, or * day: must be between 1 and 31, or * weekday: must be between 0 and 6 or * job: if provided, assumes we are updated an existing entry. ''' cron = self.get_crontab() # Cut out early if the job already exists, and force is false if self.has_schedule() and not force: bot.exit('%s already has a schedule. Use --force to update.' % self.name) # Remove any previous schedules cron = self.remove_schedule(quiet=True) # minute must be between * or 0 through 59, or * if minute not in ['*'] + list(range(60)): bot.exit('minute must be in [0..59] or equal to *') # Hour must be between 0 through 23, or * if hour not in ['*'] + list(range(24)): bot.exit('hour must be in [0..23] or equal to *') # Day must be in range 1 through 31, or * if day not in ['*'] + list(range(1, 32)): bot.exit('day must be in [1..31] or equal to *') # Day must be in range 1 through 31, or * if month not in ['*'] + list(range(1, 13)): bot.exit('month must be in [1..12] or equal to *') # Day must be in range 1 through 31, or * if weekday not in ['*'] + list(range(7)): bot.exit('weekday must be in [0..6] or equal to *') # The command will run the watcher, watcher.cfg controls what happens whereis = which('watchme') command = '%s run %s' % (whereis, self.name) comment = 'watchme-%s' % self.name if job == None: job = cron.new(command=command, comment=comment) # Set the time, and then write the job to file job.setall(minute, hour, day, month, weekday) job.enable() cron.write_to_user(user=True) bot.info(job) return job